# Office Math

DsWord is a Document Solutions product that offers a high performance library to create, load, modify, and save Word documents programmatically.

## Content

Office Math in a Word document is a combination of mathematical symbols or text. For example, A=πr^2 can be converted and written in a Word document as:
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/area-of-circle.png)
DsWord allows you to read, add, edit, and display Office Math content in a Word document using [OMathParagraph](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathParagraph.html) and [OMath](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.html) classes. OMathParagraph represents a paragraph that contains Office Math content, while OMath represents an inline Office Math zone and can be included in an OMathParagraph or a regular paragraph. Also, you can add OMathParagraph and OMath to a **SimpleField**, **Hyperlink**, **BidirectionalOverride**, and **ControlContent** in an inline content control.
DsWord provides specialized classes such as [OMathBar](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathBar.html), [OMathBorderBox](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathBorderBox.html), [OMathBox](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathBox.html), [OMathDelimiter](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathDelimiter.html), [OMathEquationArray](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathEquationArray.html), [OMathFraction](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathFraction.html), [OMathFunction](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathFunction.html), etc. to represent the various math structures inside an OMath zone. These classes are derived from the common abstract [OMathStruct](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathStruct.html) base class. Each class implementation has its own strong structure of **OMathElement**s. [OMathElement](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathElement.html) represents an element inside the OMathStruct class instance. You can add OMathElement only to OMathDelimiter and OMathEquationArray class instances manually; in other OMathStruct implementations, their position is predefined.
Besides Office Math content, OMath and OMathElement classes can contain the following objects: SimpleField, Hyperlink, and ContentControl. Also, these classes and OMathParagraph class can contain [ContentMark](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.ContentMark.html) and [Run](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Run.html) objects. When Run object is inside the Office Math zone (in OMath or OMathElement), its new property [IsOMathRun](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Run.IsOMathRun.html) sets to true. In this case, the new property [OMathFormat](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Run.OMathFormat.html) became available for additional mathematical formatting through the [OMathFormat](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathFormat.html) class. The default appearance and behavior of Office Math content are available with the new [OMathOptions](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Settings.OMathOptions.html) property in [Settings](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.Settings.html) class through [OMathOptions](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathOptions.html) class.
You can access the Office Math content using [OMathParagraphs](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.OMathParagraphs.html), [OMaths](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.OMaths.html), [OMathStructs](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.OMathStructs.html), [OMathElements](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.OMathElements.html) and [OMathMatrixRows](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.OMathMatrixRows.html) properties of [RangeBase](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.RangeBase.html) class.

## Working with OMathElements

**OMathElements** allow you to create various complex equations with different structures using accent, bar, border-box, box, delimiter, and so on. The following sections demonstrate the usage of such OMathElements.

### Accent

An accent is a single Unicode symbol present over a base element. You can add an accent symbol to an equation using [AddAccent](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddAccent.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/accent-diagram.png)
Refer to the following example code to add an accent over a fraction:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();
            
// Add accent to the equation.
var accent = om.AddAccent("", "\u0308");
accent.Base.AddFraction("2", "5", OMathFractionType.Bar);

// Save the Word document.
sampleDoc.Save("Accent.docx");
```

**![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/accent.png)**

### Bar

A bar is a horizontal line present over or below a base element. You can add a bar to an equation using [AddBar](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddBar.html) method of OMath class. By default, the bar is added below the base element.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/bar-diagram.png)
Refer to the following example code to add a bar over a function:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add bar to the equation.
var bar = om.AddBar();
bar.Base.AddFunction("cos", "2x");
bar.Position = OMathVerticalJustification.Top;

// Save the Word document.
sampleDoc.Save("Bar.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/bar.png)

### Border Box

A border box is a border present around a base element with four sides. You can add a border box to an equation using [AddBorderBox](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddBorderBox.html) method of OMath class. By default, a box is drawn around the base element, but you can also add strikethrough in horizontal, vertical, and diagonal directions.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/border-box-diagram.png)
Refer to the following example code to add a border box around an equation:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add borderbox to the equation.
var box = om.AddBorderBox("2+2*");
box.Base.AddFraction("3", "3", OMathFractionType.Bar);
box.Base.AddRun(" = 5");

// Save the Word document.
sampleDoc.Save("BorderBox.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/border-box.png)

### Box

A box represents a box that groups components of an equation or other instance of mathematical text. You can add a box to an equation using [AddBox](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddBox.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/box-diagram.png)
Refer to the following example code to add two runs with a box element between them:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add box to the equation.
om.AddRun("a");
var box = om.AddBox("==");
om.AddRun("b");
box.IsOperatorEmulator = true;

// Save the Word document.
sampleDoc.Save("Box.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/box.png)

### Delimiter

A delimiter is a mark or symbol that represents the beginning or end of separate elements of an equation with a designated separator between each element. You can add a delimiter to an equation using [AddDelimiter](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddDelimiter.html) method of OMath class. By default, the beginning and end characters will be parentheses, and the separator will be a pipe symbol.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/delimiter-diagram.png)
Refer to the following example code to add delimiters to an equation:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add delimiter to the equation.
var delimiter = om.AddDelimiter(new string[] { "5", "7" }, "[", "]", "\\");
delimiter.Items.Add().AddRadical("n", "7");

// Save the Word document.
sampleDoc.Save("Delimiter.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/delimiter.png)

### Equation Array

An equation array is a one-dimensional vertical array consisting of one or more equations or expression elements. You can add an equation array using [AddEquationArray](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddEquationArray.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/equation-array-diagram.png)
Refer to the following example code to add an equation array:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add equation array.
var ea = om.AddEquationArray();
ea.Items.Add().AddDelimiter(new string[] { "x", "y", "z" });
ea.Items.Add().AddFraction("π", "2", OMathFractionType.Skewed);

// Save the Word document.
sampleDoc.Save("EquationArray.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/equation-array.png)

### Fraction

A fraction consists of a numerator element and a denominator element separated by a fraction bar. You can add a fraction using [AddFraction](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddFraction.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/fraction-diagram.png)
Refer to the following example code to add a fraction:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add fraction.
var fr = om.AddFraction();
var func = fr.Numerator.AddFunction("sin", "");
func.Argument.AddFraction("π", "3", OMathFractionType.Bar);
fr.Denominator.AddRadical("e", "3");

// Save the Word document.
sampleDoc.Save("Fraction.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/fraction.png)

### Function

A function consists of a function name element and an argument element. You can add a function using [AddFunction](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddFunction.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/function-diagram.png)
Refer to the following example code to add a function:

```CS
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add function.
var f = om.AddFunction("cos", "");
f.Argument.AddFraction("π", "2", OMathFractionType.Bar);

// Save the Word document.
sampleDoc.Save("Function.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/function.png)

### Group Character

A group character is a Unicode symbol present above or below the base element. You can add a group character using [AddGroupCharacter](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddGroupCharacter.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/group-character-diagram.png)
Refer to the following example code to add a group character to the function:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add group character.
var gc = om.AddGroupCharacter("xyz", "\u23DE");
gc.Position = OMathVerticalJustification.Top;
gc.VerticalJustification = OMathVerticalJustification.Bottom;

// Save the Word document.
sampleDoc.Save("GroupCharacter.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/group-character.png)

### Lower Limit

A lower limit is the lowest value of any value or expression. You can add a lower limit using [AddLimitLower](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddLimitLower.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/lower-limit-diagram.png)
Refer to the following example code to add a lower limit to the function:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add lower limit.
om.AddLimitLower("abc", "z");

// Save the Word document.
sampleDoc.Save("LowerLimit.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/lower-limit.png)

### Upper Limit

An upper limit is the highest value of any value or expression. You can add an upper limit using [AddLimitUpper](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddLimitUpper.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/upper-limit-diagram.png)
Refer to the following example code to add an upper limit to the function:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add upper limit.
om.AddLimitUpper("abc", "y");

// Save the Word document.
sampleDoc.Save("UpperLimit.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/upper-limit.png)

### Matrix

A matrix is a rectangular array of elements in one or more rows and columns. DsWord provides [OMathMatrix](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathMatrix.html) class, which is a special type of OMathStruct. OMathMatrix represents a math matrix where you can add or remove rows and columns represented by [OMathMatrixRow](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathMatrixRow.html) and [OMathMatrixColumn](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathMatrixColumn.html), respectively. Each cell in OMathMatrix is OMathElement instance. You can add a matrix using [AddMatrix](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddMatrix.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/matrix-diagram.png)
Refer to the following example code to add a matrix:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add matrix.
om.AddMatrix(new int?[2, 2] { { 1, 2 }, { 3, 4 } });

// Save the Word document.
sampleDoc.Save("Matrix.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/matrix.png)

### N-Array

An N-Array consists of an n-ary operator character, a base element (or operand), and optional upper and lower limit elements. You can add an N-Array using [AddNary](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddNary.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/nary-diagram.png)
Refer to the following example code to add an N-Array:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add N-Array.
om.AddNary("xⅆx", "0", "∞", "∭");

// Save the Word document.
sampleDoc.Save("Nary.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/nary.png)

### Phantom

A phantom structure adds the spacing of the phantom base element without displaying that base and suppresses part of the glyph for spacing considerations. You can add a phantom structure using [AddPhantom](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddPhantom.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/phantom-diagram.png)
Refer to the following example code to add a phantom structure:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add phantom structure.
var del = om.AddDelimiter(null, "<", ">", "");
var ph = del.Items.Add().AddPhantom("argument", false);
ph.Show = false;

// Save the Word document.
sampleDoc.Save("Phantom.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/phantom.png)

### Radical

A radical symbol denotes the square root or nth root, and it creates a radical expression comprising a radicand and a degree element. You can add a radical using [AddRadical](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddRadical.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/radical-diagram.png)
Refer to the following example code to add a radical expression:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add radical expression.
var radical = om.AddRadical();
radical.Degree.AddFraction("2", "3", OMathFractionType.Skewed);
radical.Radicand.AddFunction("cos", "2x");

// Save the Word document.
sampleDoc.Save("Radical.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/radical.png)

### Subscript

A subscript is a character, such as a number or letter, placed slightly below the normal line. You can add a subscript using [AddSubscript](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddSubscript.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/subscript-diagram.png)
Refer to the following example code to add a subscript:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add subscript.
var func = om.AddFunction("", "2x+1");
func.Name.AddSubscript("log", "3");

// Save the Word document.
sampleDoc.Save("Subscript.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/subscript.png)

### Superscript

A superscript is a character, such as a number or letter, placed slightly above the normal line. You can add a superscript using [AddSuperscript](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddSuperscript.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/superscript-diagram.png)
Refer to the following example code to add a superscript:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add superscript.
var func = om.AddFunction();
func.Name.AddSuperscript("cos", "2");
var frac = func.Argument.AddFraction();
frac.Numerator.AddRun("7x");
frac.Denominator.AddRun("2π");

// Save the Word document.
sampleDoc.Save("Superscript.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/superscript.png)

### PreSubSuperscript

A pre-sub-superscript structure consists of a base element, a reduced-size script element placed below and to the left, and a reduced-size script element placed above and to the left. You can add a pre-sub-superscript structure using [AddPreSubSuperscript](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddPreSubSuperscript.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/presubsuperscript-diagram.png)
Refer to the following example code to add a pre-sub-superscript structure:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add pre-sub-superscript structure.
var pss = om.AddPreSubSuperscript("", "-x", "2x");
pss.Base.AddRadical("n", "").HideDegree = true;

// Save the Word document.
sampleDoc.Save("PreSubSuperscript.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/pre-sub-superscript-structure.png)

### SubSuperscript

A SubSuperscript consists of a base element, a reduced-size script element placed below and to the right, and a reduced-size script element placed above and to the right. You can add a SubSuperscript using [AddSubSuperscript](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMath.AddSubSuperscript.html) method of OMath class.
![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/subsuperscript-diagram.png)
Refer to the following example code to add a SubSuperscript:

```csharp
// Initialize GcWordDocument.
var sampleDoc = new GcWordDocument();
var om = sampleDoc.Body.AddParagraph().AddOMathParagraph().AddOMath();

// Add SubSuperscript.
var subs = om.AddSubSuperscript("", "-x", "2x");
subs.Base.AddRadical("n", "").HideDegree = true;

// Save the Word document.
sampleDoc.Save("SubSuperscript.docx");
```

![](https://cdn.mescius.io/document-site-files/images/d623c730-bceb-4e85-a6b2-a3dbe84720b2/images/subsuperscript.png)

## BuiltIn Equations

You can add built-in equations supported by MS Word using Add method of RangeBase, OMathParagraph, OMath, and OMathElement classes that accept [OMathBuiltInEquation](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathBuiltInEquation.html) enumeration value identifying the desired equation.

### Add BuiltIn Equation

1. Access Office Math paragraph collection using **OMathParagraphs** property of RangeBase class.
2. Add a builtIn equation using [Add](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathParagraphCollection.Add.html) method of [OMathParagraphCollection](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.OMathParagraphCollection.html) class and pass the builtin equation as a parameter by choosing the appropriate value from OMathBuiltInEquation enumeration .

```csharp
// Initialize GcWordDocument.
GcWordDocument doc = new GcWordDocument();

// Add an Office Math paragraph with a built-in area of a circle equation.
doc.Body.Paragraphs.Add().GetRange().OMathParagraphs.Add(OMathBuiltInEquation.AreaOfCircle);

// Save the Word document.
doc.Save("AreaofCircleBuiltin.docx");
```

## MathML Converter

You can convert Office Math content to MathML and vice versa using **MathMLConverter** class. Also, it allows you to insert MathML directly into a RangeBase and converts the MathML to Office Math automatically.

1. Access the Office Math paragraph collection using **OMathParagraphs** property of **RangeBase** class and add Office Math paragraph using **Add** method of **OMathParagraphCollection** class.
2. Implement a text reader to read from a string using **StringReader** class.
3. Create an XML reader to read MathML from the string using **Create** method of **XmlReader** class.
4. Create a MathML converter and add the content to OMathParagraph using [FromMathML](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.MathMLConverter.FromMathML.html) method of [MathMLConverter](/document-solutions/dot-net-word-api/api/online/DS.Documents.Word/GrapeCity.Documents.Word.MathMLConverter.html) class.

```csharp
// Initialize GcWordDocument.
GcWordDocument doc = new GcWordDocument();

// Add an Office Math paragraph.
OMathParagraph oMathParagraph = doc.Body.Paragraphs.Add().GetRange().OMathParagraphs.Add();

// Create an XML reader from the MathML area of the circle string.
StringReader stringReader = new StringReader("<mml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"" +
    " xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\"><mml:mi>A</mml:mi><mml:mo>=</mml:mo>" +
    "<mml:mi>π</mml:mi><mml:msup><mml:mrow><mml:mi>r</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup></mml:math>");
XmlReader xmlReader = XmlReader.Create(stringReader);

// Create a MathML converter.
MathMLConverter converter = new MathMLConverter();

// Add the MathML area of the circle.
converter.AddMathML(xmlReader, oMathParagraph);

// Save the Word document.
doc.Save("AreaofCircleMathml.docx");
```

**Limitation**
Export of Office Math content to PDF or images is not yet supported.