# Syntax Reference

Here are lists of syntax that are available for TEXDraw by default.

## Introduction

TEXDraw syntax is based on the LaTeX syntax. Here we cover possible syntaxes that’s officially supported by this plugin. Altough you can also learn $\LaTeX$ syntax in other resources, like the TeX Bible, TexBook, the Wikibooks LaTeX directory or even the TeX Stack-Exchange to complement the missing contents or for more gentler introduction in the concept of $\LaTeX$ itself.

## Basic Guides

This section covers the basic principles of how LaTeX works.

### Special Characters

$\LaTeX$ provides a lot of features it becames the de-facto of writing scientific papers even to this day. It may have unfamiliar syntax like what we used to be with HTML, Markdown, etc. But trust me you’ll get used with it fairly quickly.

Anyway, these 8 characters has special meaning in $\LaTeX$: { } \ % &  ^ _ • { } (curly brackets) is to group and separate commands from its surroundings. They must appear in pairs. • \ (backslash) is to start commands, which extend until the first non-alphanumerical character. • % (percent) is to ignore the rest of text in the line. It’s a symbol to start a comment code. • & (ampersand) is to make horizontal tabs alignments •  (dollar) is to toggle (start or finish) math mode
• ^ (hat) is to create a superscript in math mode
• _ (underscore) is to create a subscript in math mode

Along these characters, you may mostly use backslash \ by a lot, because it’s the way we give commands to LaTeX. A command is a special syntax that $\LaTeX$ understands and processed by former definitions. So with that, does $TEXDraw$ fully follows $\LaTeX$ rule? That’s not necessarily true. $\LaTeX$ itself is build based upon $\TeX$ and they’re different each other. $TEXDraw$ does not strictly follow $\LaTeX$, however you may find many similarities on both syntax, because we strive to be fully compatible such that if you find a formula written in $\LaTeX$ somewhere out in the internet, it will just work on $TEXDraw$.

### Spacing

In a nutshell, $\LaTeX$ spacing is similar to Markdown, consecutive spaces is always be assumed as one, while a blank line will produce a new paragraph for the next line.

Can you override this? Yes.

• You can use \par to explicitly start a new paragraph.
• You can also use \linebreak or \\ to insert a soft break.

You can also use varieties of space commands like:

• \w or \  (backslash before a space) for a single whitespace.
• \,,\:, \; for thin, medium, thick space respectively.
• \kern{<unit>} for custom horizontal space specified by unit
• \\ <unit> or \vskip{<unit>} for custom vertical space specified by <unit>

You might not need to use them all, they’re mostly for decoration.

Note that in $\LaTeX$ any continous whitespace is always skipped after a command by the parser, so it’s also common to use double slash like \LaTeX\ for spaces to work as usual in $\LaTeX$.

### Units

$\LaTeX$ has many measurements unit option to deal with, and they usually given in real world unit like pt because \LaTeX was originally build for printing in paper. Unfornatunely screens doesn’t really work with these unit, so $TEXDraw$ comes up their own definition of points which is configurable using pixelsPerInch and nativeSize described on the configuration section.

The complete list is of units is px (Pixel), em (Em), pt (Point), pc (Pica), in (Inch), bp (BigPoint), cm (Centimeter), mm (Millimeter), dd (DidotPoint), cc (Cicero), sp ScaledPoint. The good rule of thumb is use either pt for space-related units or em for size-related units and px for special case where you want to match the sizes in UI canvas (px has a special case they don’t affected with TEXDraw’s size attribute).

Some examples of usage of units are:

• Custom font size with \fontsize
• Custom spacing with \kern or \vskip
• Custom line metrics with \setlength, etc.

### Environments

In $\LaTeX$ curly brackets ({ and }) are used for scoping any side-effects within them (from e.g. text style or color change). Sometimes we can also give them special properties (that’s why we call them “environment”). To use an environment, we start it with \begin{<environment>} and finish it with \end{<environment>}. The complete list for <environment> are:

• math: Math mode block
• verbatim: Verbatim (raw) block
• enumerate, itemize: Bullets and numbering
• flushleft, flushright, center: Block-based alignments
• comment: Block based comment (% comment equivalent)
• tabular, array: Table (block and inline table respectively)
• matrix, smallmatrix: Math Matrix
• pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix: Delimited matrix
• minipage: Nested paragraph block
• align: For aligning equations

Examples of individual environments are explained below. Keep scrolling!

## Text Mode Features

By default, TEXDraw starts with text mode. A text mode is used to write usual text with $\LaTeX$. There are some built-in features useful to understand.

### Paragraphs

A paragraph has many set of builtin and customizable features. Some commands to customize them include:

• \raggedleft, \centering, \raggedright. Set current and next paragraph alignment
• \justifying. To turn on justify back (after alignment has been set)
• \indent or \noindent. Enable or disable current and next paragraph indentation

You can also override some of paragraph units using \setlength{<param>}{<unit>}. These <params> include:

• \parskip. Length of paragraph spacing
• \baselineskip. Length of line spacing
• \parindent. Length of paragraph indentation
• \leftmargin. Length of paragraph padding left side
• \rightmargin. Length of paragraph padding right side

For bonus tip, If you want to scope alignment between text or block, you can use Environments instead:

• \begin{flushleft}...\end{flushleft}
• \begin{flushright}...\end{flushright}
• \begin{center}...\end{center}

### Font Size

Font size can be adjusted by variety of commands from \tiny to \HUGE. You can also specify custom font size using \fontsize{<unit>}. Every step is 1.2 times larger than previous one.

There’s also \scriptsize and \scriptscriptsize to adjust font size that’s better suited for math usage.

### Font Style

A font style consists of multiple attributes consist of selected family, series, and shape. The default font style always have selected \mdseries, \rmfamily, and \upshape. To change one of them you simply need to call the command and everything else will be combined correctly.

Note that there also single switch command which isn’t trying to combine existing selected series, family, or shape. Those single switch command is: \rm (normal), \sl (slanted), \it (italic), \bf (boldface), \tt (typewriter), \sf (sans serif) and \sc (super case). Note that you can’t combine styles with these switch commands, you need them to be typed fully (e.g. \bfseries\itshape for activating both italic and bold).

Remember that those commads replaces font style in current stack. $\LaTeX$ also provides non-overriding font style commands in \text* commands (e.g. \textit{<italic text>}).

If you already know math mode in $\LaTeX$, math mode does use different font. You can use \math* commands (e.g. mathrm, mathbf) in math mode to get back to regular text font.

To use different set of font family, you can just call the font name. Built-in $TEXDraw$ does have a custom font just for demonstration with Open Sans, simply call them by it’s file name \opens and Open Sans font will be used.

At last, you should be aware that not all font style combination might available. You can see this table for default font available in TEXDraw.

\rmfamily \sffamily \ttfamily \bf\rmfamily \bf\sffamily \bf\ttfamily
\upshape ✅ (cmr) ✅ (cmss) ✅ (cmtt) ✅ (cmb) ✅ (cmssbx) ✅ (cmtex)
\itshape ✅ (cmti) ✅(cmssi) ✅ (cmitt) ✅ (cmbxti)
\slshape ✅ (cmsl) ✅ (cmsltt) ✅ (cmbxsl)
\scshape ✅ (cmcsc) ✅ (cmtcsc)

### Font Color

Font color can be easily be changed by calling \color{<colorunit>} where <colorunit> is the “color keyword” that Unity can understand (e.g. #AAA, #AAAA, #AAAAAA, #AAAAAAAA, red, lime).

Remember that $TEXDraw$ color property only set initial font color, they’re not sampling the rendered font colors.

### Ligatures

Ligature is a built-in feature in text mode. It detects, joins and subtitute ff, fi, ffi, fl, ffl, --, ---, , '' character to single equivalent character glyph for better typography.

### Hyphens

It’s common to write a long sentence and then split them in between paragraph line. To accomodate this, we can use optional breaking hyphen by using \-. Simply put them in between text that you want to split (e.g. crypto\-graphy) and the hyphen will only appear if it necessary to break that word in the end of a line.

Can we automate this? Not yet. Currently, we don’t support auto hyphenations because it’s computationally intensive to do.

### Accents

$\LaTeX$ has a special set of characters to be used as an accent. These characters set are \ (grave) \' (acute) \^ (circumflex) \" (umlaut) \~ (tilde) \= (macron) \. (dotaccent) \u (breve) \v (caron) \H (hungarumlaut) \t (tie) \c (cedilla). To use it simply type the accent symbol followed by an alphabets (e.g. \A becomes À).

Accents also handles special case where the alphabets are lower i and j, they simply be replaced with \dotlessi and \dotlessj (non dotted alphabet letter equivalent).

### Unicode

While $\LaTeX$ doesn’t recognize any characters beyond ASCII, $TEXDraw$ will attempt to translate any non-ASCII unicode character to $\TeX$ equivalent if available. Meaning you can simply type instead of \leq or ã instead of \~a.

This conversion only happens within built-in font type. If you use user-provided fonts, the unicode conversion will not happen in prefer to the unicode characters provided by that custom font.

### Importing $\TeX$ file

You can put a .tex file in Unity’s Resources folder so it can imported right to your scene with \input. For example \input{texdraw/manual} will display TEXDraw manual text.

## Text Extras

These extra text features might be useful as part of $\LaTeX$ features.

### Bullets and Numbering

Bullets and numbering are available using itemize and enumerate environment. They also can wrap and indent properly.

\begin{itemize}
\item First level, itemize, first item
\begin{itemize}
\item Second level, itemize, first item
\item Second level, itemize, second item
\begin{enumerate}
\item Third level, enumerate, first item
\item Third level, enumerate, second item
\end{enumerate}
\end{itemize}
\item First level, itemize, second item
\end{itemize}


### Verbatim Mode

The verbatim environment allows you to write code on a block level and creates a hint so that TEXDraw won’t parse any of its content until the first occurence of \end{verbatim}.

\begin{verbatim}...\end{verbatim}


The \verb command also does similar but in inline level (e.g. \verb|\verb|). You can surround inline code with \verb| at beginning and | at the end. If you want to use | in inline verbatim then you can use other non-special symbols such as \verb!...!.

Note that verbatim mode doesn’t support auto-wrap. You need to handle wrapping yourself.

### Primitive Boxes

These are primitive commands from $\TeX$ that can be still used to do low-level layouting in an interesting way.

• \hbox by <unit>{<content>} Wrap <content> in an horizontal box (at minimum) by <unit>
• \hbox spread <unit>{<content>} Wrap <content> in an horizontal box with margin by <unit>
• \vbox{<content>}, \vcenter{<content>}, \vtop{<content>} Wrap <content> in vertical mode at bottom, center, or top baseline.
• \raisebox{<unit>}{<content>} Raise <content> by <unit>.
• \begin{minipage}[<alignment>]{<unit>}<content>\end{minipage} Create nested paragraph <content> with given vertical <alignment> (m middle, t top or b bottom) and given horizontal <unit> width.
• These variaties of space commands can also be useful here…
• \hss, \vss, \hfill, \vfill automatically fill available space for layouting (also can be used for advanced math aligment too).

### Overlines

This function creates a straight line over (\overline), under (\underline) or though (\midline) a selected <content> after.

The \link[keyname]{<content>} command is not useful on their own, but can be a powerful yet simple tool to leverage $TEXDraw$ in some two-way interactions. All it does is capture the rectangle bound resulted from box calculations and use the data for futher input processing.

• TEXLink uses \link to receive click events on them and display color tweens (like web links) as feedback
• TEXInput uses \link so it can receive mouse or touch input and manipulate text accordingly
• TEXEmbed uses \link so it can hook other RectTransform to follow empty placeholder \link.

The [keyname] is used for identifying the link. It can be any string you want, if it omitted then it will be equal with the content.

### Tabular

$TEXDraw$ can generate tables for you, either it’s on display (tabular environment) or inlined (array environment).

Both environment requires {column-definitions} to tell how much columns it needed and their each setup (alignment, border, etc).

\begin{tabular}{column-definitions}...\end{tabular}


The tabular mode arranges expression in inside the environment as a table. You use alignment control & and paragraph control \\ to control text to next column and row. The flow is always row-by-row.

This environment requires you to write {column-definitions} followed right after \begin{tabular}. This definitions is better be explained by examples:

• {ccc} means 3 columns aligned on center on each cell.
• {lccr} means the first cell (l) is aligned to left while the last one (r) is aligned to the right.
• {|c|c|c|} means each cell will have a single line border left right and inside.
• {||ccc||} means leftmost and rightmost border of table will be double lined.
• {lx} means the second column (x) will expand to the rest of available space.
• {lp{50pt}} means the second column (p{50pt}) will have 50pt width and each cell is vertically top aligned (m or b can be used instead for middle or bottom alignment).
• {>{\columncolor[gray]{0.2}\color{white}}l} means this column will have grey-dim background with white color.

To show row lines, add \hline before the first row and after the last row and after any new row created (by \\). Double \hline\hline also can be used to draw double line in row. Here are complex tabular mode in action

\begin{center}
\begin{tabular}{|>{\columncolor[green]\color{white}}l | l | l | x |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\ \hline
\end{tabular}
\end{center}


## Math Mode

A math mode is a mode for specifically writing a math expression. It’s the powerful side of $\TeX$ typesetting. Math mode is different than usual paragraph mode by the following points:

• In paragraph mode multiple spaces is cascaded into one space. Math mode completely discard it.

• A special spacing between characters is put based on adjacent character types, this is known as the Glue padding system.

• In math block mode, texts are centered by default trather than justified.

### Entering Math Mode

A math mode is started and finished by ($$) or ($$$$) for math inline mode and ($$$$) or ($$) for math block mode. A math inline mode writes math expressions inside a paragraph, like $\frac{2}{3}$ for $2\over3$ while in math block mode the expression will be moved to exclusive line. Like:

$2x+y$

for $$2x+y$$.

It’s advised to use the new $\LaTeX$ notation $$$$ and $$ rather than old $\TeX$ $$ and $$$$ because of better clarity and avoid possible bugs or confusion.

### Math Style Modes

There are more subtle differences than just inline $$$$ vs. block math $$. In fact, there are 4 major math mode in $\LaTeX$ :

• Display Mode
• Text Mode
• Script Mode
• ScriptScript Mode

### Alignment in Math Mode

By default math mode is centered, but there are several ways to customize this, and it’s not just aligning to left and right.

First, you can take leverage of primitive boxes, they’re super useful here. For example, \hfil, as a flexible space, can be used for aligning rest of the math to left or right, or even both.

You’ll also find align environment useful here, for example to align an equal sign in multiple rows.

\begin{align}
x + 8 &= 2y + z \\
2x &= 4y + 2z - 16
\end{align}

\begin{align*} x + 8 &= 2y + z \\ 2x &= 4y + 2z - 16 \end{align*}

### Text Inside Math

To write text inside math, you can use \text{<text here>}. This will restores back the font style including the space behaviour.

Tex Code
$$Alpha \over eq C$$ $$Alpha \over eq C$$
$$\text{Alpha} \over \text{eq C}$$ $$\text{Alpha} \over \text{eq C}$$

### Symbols

TEXDraw have over 600+ sets of symbols available for use.

Tex Code
$$\alpha=\beta+\gamma$$ $$\alpha=\beta+\gamma$$
$$\theta\approx\angle 90^\circ$$ $$\theta\approx\angle 90^\circ$$

Symbols are much better to be written in math mode because of additional glue system which properly adds spacing between characters. We explain more below.

### Symbol Types and Glue

There’s about 8 types of symbols in $\TeX$: Ordinary, Large Operator, Binary Operator, Relation, Open Delimiter, Close Delimiter, Punctuation, Inner Types.

In math mode, regular spaces don’t work. However, there’s a “glue” space in between each symbol which is differ based on the symbol types between them, that is either a no space, thin, medium, or thick space.

The configuration for these glue space is defined in the Glue Matrix configuration. But anyway, you still can use the manual spacing above if you want to, just don’t overuse it.

### Minus Sign

In $\TeX$ a sign operator (-) can become three different symbols depending on the context.

For instance, if it’s not in math mode, it will be a dash. Else it will be a negative sign or a minus operator depending how you place it in math mode.

In math mode, a negative sign created if it’s on the beginning of math mode. So if you want to make it in the middle you need to nest it on nested math mode, see how this goes:

Tex Code
$x- {}-{}5$ $$x- -5$$
$x- -5$ $$x- \(-5$$\)

This is probably only work in TEXDraw though. There’s wildly different consensus for this in other TeX platforms.

### Fractions

$\frac{\text{Nominator}}{\text{Denominator}}$

Fractions can be written with \frac{<num>}{<denom>} or <num>\over<denom>. The first one is preferred for clarity.

Tex Code
$$\frac12$$ \frac12
$$\frac{2x}{5-2}$$ \frac{2x}{5-2}
$$2\over3$$ 2\over3
$$10{6\over9}$$ 10{6\over9}

If you wanted to write a fraction that doesn’t draw a line, you can use \nfrac. For a fraction that doesn’t make font size get smaller (which is useful for continous fraction), use \cfrac. There’s also a common extension \binom for binomial fraction.

Tex Code
$$\left\{\begin{array}{c}1\\2\end{array}\right.$$ \left\{\nfrac12\right.
$$\cfrac1{a_1+\cfrac1{a_2+\cdots}}$$ \cfrac1{a_1+\cfrac1{a_2+\cdots}}
$$\binom{n}{k} = \frac{n!}{k!(n-k)!}$$ \binom{n}{k} = \frac{n!}{k!(n-k)!}

### Roots

$\sqrt[\text{Degree}]{\text{Base}}$

Mathematical root expressions can be written either in these formats:

Tex Code
$$\sqrt 2$$ \sqrt 2
$$\sqrt[3]{x\pi}$$ \sqrt[3]{x\pi}

### Scripts

$\text{Base}^\text{Super}_\text{Sub}$

Script expressions can be written with ^ for superscript or _ for subscript.

Tex Code
$$2^3_4$$ 2^3_4
$$2^{3^4}$$ 2^{3^4}
$${}^{2}x$$ {}^{2}x

Warning: any nested script must using parentheses by curly bracket.

### Large Operators

$\sum^\infty_{i=0} \neq \int^a_b$

Large operators are just like scripts but it’s placed below or on top of it. Some operators applying this are defined in large operator list in section Symbols.

If large operators are in put on inline or cramped mode it will behave like a regular script. For example $\sum^\infty_{i=0} \neq \int^a_b$

Remember that some large operators have a superscript and subscript, others be placed on top or bottom of it. This can be overrided with \limits or \nolimits to be placed right after the large operator symbol, for instance:

Tex Code
$$\int^2_0x$$ \int^2_0x
$$\int\limits^2_0x$$ \int\limits^2_0x
$$\prod\nolimits^2_{x=1}x$$ \prod\nolimits^2_{x=1}x

### Delimiters

$z = \left[2\left(x + y^2\right) -{2x\over3}\right]$

Delimiters are pair of brackets that can expands based on contents. You can use \left and \right for defining which pair bracket are marked for auto height expansion. For example, \left(...\right). You can also use other bracket pairs as defined in delimiter symbols. To omit one of the delimiter from display, use dot . as the delimiter.

$$z = \left[2\left(x + y^2\right) -{2x\over3}\right]$$


Note that \left and \right must be in pair. There also an alternative commands for manual height expansion that is \big, \Big, \bigg and \Bigg.

### Matrices

$\begin{pmatrix}2&4x\\ 3&1\end{pmatrix}\times\begin{pmatrix}2y&8\\ 1&3\end{pmatrix}$

Matrix has the same concept as table, however they don’t need column definition, they just be centered at all times. To create matrix, wrap your expression with \begin{matrix}...\end{matrix} for bare matrix. There’s also builtin pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix for enclosing the matrix with delimiters.

$$\begin{pmatrix}2&4x\\3&1\end{pmatrix}\times \begin{pmatrix}2y&8\\1&3\end{pmatrix}$$


### Negated Expressions

There’s couple ways to do negated expression, first, for one character negation there’s \not to put any character in front of a slash, for instance \not= for $\not=$ (this also has the shorthand \neq). It’s best used for character relations.

$\not= \not< \not>$
$$\not2x\over\not8_4$$


For multiple characters, there are \sout (strike-out), \cancel, \bcancel and \xcancel.

$\sout{\text{sout}}\ \ \cancel{\text{cancel}}\ \ \bcancel{\text{bcancel}}\ \ \xcancel{\text{xcancel}}$