AddOMathStructs.vb
'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.DrawingImports GrapeCity.Documents.Word
Public Class AddOMathStructs Function CreateDocx() As GcWordDocument Dim doc = New GcWordDocument() doc.Body.AddParagraph("OMath content created in DsWord", doc.Styles(BuiltInStyleId.Title))
Dim styleOmath = doc.Styles.Add("omath", doc.Styles(BuiltInStyleId.Title)) styleOmath.ParagraphFormat.Indentation.LeftIndent = 36 Dim styleText = doc.Styles.Add("text", StyleType.Character) styleText.Font.Size = 14 Dim styleCap1 = doc.Styles.Add("styleCap1", doc.Styles(BuiltInStyleId.Heading1)) styleCap1.ParagraphFormat.Spacing.SpaceBeforeAuto = False styleCap1.ParagraphFormat.Spacing.SpaceBefore = 18 Dim capA = vbLf & "Example 1: " Dim capB = vbLf & "Example 2: "
Dim addA As Func(Of String, OMath) = Function(caption As String) doc.Body.AddParagraph(caption, styleCap1) Dim p = doc.Body.AddParagraph(styleOmath) p.AddRun(capA, styleText) Return p.AddOMath() End Function Dim addB As Func(Of OMath) = Function() Dim p = doc.Body.AddParagraph(styleOmath) p.AddRun(capB, styleText) Return p.AddOMath() End Function
'' OMathAccent Dim om = addA("OMathAccent") om.AddAccent("a", ChrW(&H20D7)) om = addB() Dim accent = om.AddAccent("", ChrW(&H308)) accent.Base.AddFraction("2", "5", Nothing)
'' OMathBar om = addA("OMathBar") om.AddBar("2x+1=3") om = addB() Dim bar = om.AddBar() bar.Base.AddFunction("cos", "2x") bar.Position = OMathVerticalJustification.Top
'' OMathBorderBox om = addA("OMathBorderBox") om.AddBorderBox("xyz") om = addB() Dim bbox = om.AddBorderBox("2+2*") bbox.Base.AddFraction("3", "3", Nothing) bbox.Base.AddRun(" = 5") bbox.HideLeft = True bbox.HideTop = True bbox.HideRight = True bbox.HideBottom = True bbox.StrikeBottomLeftToTopRight = True bbox.StrikeTopLeftToBottomRight = True
'' OMathBox om = addA("OMathBox") om.AddRun("a") Dim box = om.AddBox("==") om.AddRun("b") box.IsOperatorEmulator = True om = addB() Dim nary = om.AddNary("x", "0", "1", "∭") box = nary.Base.AddBox("dx") box.IsDifferential = True
'' OMathDelimiter om = addA("OMathDelimiter") om.AddDelimiter(New String() {"a", "b", "c"}) om = addB() Dim delimiter = om.AddDelimiter(New String() {"5", "7"}, "[", "]", "\") delimiter.Items.Add().AddRadical("n", "7") Dim styleNorm = doc.Styles.Add("Norm", StyleType.Character) styleNorm.Font.Italic = False styleNorm.Font.Color.RGB = Color.Red styleNorm.Font.Size = 20
'' OMathEquationArray om = addA("OMathEquationArray") om.AddEquationArray(New String() {"a", "b", "c"}) om = addB() Dim ea = om.AddEquationArray() ea.Items.Add().AddDelimiter(New String() {"x", "y", "z"}) ea.Items.Add().AddFraction("π", "2", OMathFractionType.Skewed)
'' OMathFraction om = addA("OMathFraction") om.AddFraction("π", "4", Nothing) om = addB() Dim fr = om.AddFraction() Dim func = fr.Numerator.AddFunction("sin", "") func.Argument.AddFraction("π", "3", Nothing) fr.Denominator.AddRadical("e", "3")
'' OMathFunction om = addA("OMathFunction") om.AddFunction("ln", "2e") om = addB() Dim f = om.AddFunction("cos", "") f.Argument.AddFraction("π", "2", Nothing)
'' OMathGroupCharacter om = addA("OMathGroupCharacter") om.AddGroupCharacter("mgh", "^") om = addB() Dim lu = om.AddLimitUpper("", "x") Dim gc = lu.Base.AddGroupCharacter("xyz", ChrW(&H23DE)) gc.Position = OMathVerticalJustification.Top gc.VerticalJustification = OMathVerticalJustification.Bottom
'' OMathLimitLower om = addA("OMathLimitLower") om.AddLimitLower("abc", "z") om = addB() Dim ll = om.AddLimitLower() ll.Base.AddBorderBox("2x+3") ll.Limit.AddFraction("2", "5", Nothing)
'' OMathLimitUpper om = addA("OMathLimitUpper") om.AddLimitUpper("abc", "y") om = addB() lu = om.AddLimitUpper() lu.Base.AddRadical("e", "3") lu.Limit.AddFunction("cos", "2x")
'' OMathMatrix om = addA("OMathMatrix") om.AddMatrix(New Integer?(,) {{1, 2}, {3, 4}}) om = addB() delimiter = om.AddDelimiter() Dim item = delimiter.Items.Add() Dim matrix = item.AddMatrix(3, 1) matrix.Rows(0).Cells(0).AddRun("U") matrix.Rows(0).Cells(0).AddDelimiter(New String() {"t"}) matrix.Rows(1).Cells(0).AddRun("V") matrix.Rows(1).Cells(0).AddDelimiter(New String() {"t"}) matrix.Rows(2).Cells(0).AddRun("W") matrix.Rows(2).Cells(0).AddDelimiter(New String() {"t"})
'' OMathNary om = addA("OMathNary") om.AddNary("xⅆx", "0", "∞", "∭") om = addB() nary = om.AddNary("", "", "", "∏") nary.Subscript.AddFraction("π", "3", Nothing) nary.Superscript.AddFraction("2π", "3", Nothing) nary.Base.AddFunction("cos", "x")
'' OMathPhantom om = addA("OMathPhantom") Dim del = om.AddDelimiter(Nothing, "<", ">", "") Dim ph = del.Items.Add().AddPhantom("argument", False) ph.Show = False om = addB() Dim radical = om.AddRadical() radical.HideDegree = True ph = radical.Radicand.AddPhantom() ph.Show = True ph.Argument.AddFraction("x", "y", Nothing) ph.Smash = True
'' OMathPreSubSuperscript om = addA("OMathPreSubSuperscript") om.AddPreSubSuperscript("Y", "1", "n") om = addB() Dim pss = om.AddPreSubSuperscript("", "-x", "2x") Dim pssRadical = pss.Base.AddRadical("n", "") pssRadical.HideDegree = True
'' OMathRadical om = addA("OMathRadical") om.AddRadical("x", "3") om = addB() radical = om.AddRadical() radical.Degree.AddFraction("2", "3", OMathFractionType.Skewed) radical.Radicand.AddFunction("cos", "2x")
'' OMathSubscript om = addA("OMathSubscript") om.AddSubscript("x", "linear") om = addB() func = om.AddFunction("", "2x+1") func.Name.AddSubscript("log", "3")
'' OMathSubSuperscript om = addA("OMathSubSuperscript") om.AddSubSuperscript("Y", "1", "n") om = addB() Dim subs = om.AddSubSuperscript("", "-x", "2x") Dim subsRadical = subs.Base.AddRadical("n", "") subsRadical.HideDegree = True
'' OMathSuperscript om = addA("OMathSuperscript") om.AddSuperscript("x", "2") om = addB() func = om.AddFunction() func.Name.AddSuperscript("cos", "2") Dim frac = func.Argument.AddFraction() frac.Numerator.AddRun("7x") frac.Denominator.AddRun("2π")
Return doc End FunctionEnd Class