Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Syntax Reference

This article explain syntaxes that TEXDraw supports.

Introduction

TEXDraw syntax is based on LaTeX. 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.

Table of Contents

Basic Guides

This section covers the basic principles of how LaTeX works.

Special Characters

$\LaTeX$ provides a lot of features it became 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.

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.

Among these characters, you might use backslash \ mostly because it’s the way we give commands to LaTeX. A command is a special syntax that $\LaTeX$ understands and processed differently.

Does TEXDraw fully follows $\LaTeX$ rule? No, TEXDraw does not strictly follow $\LaTeX$ as it would be very difficult to implement. However, you may find many similarities on both syntax, because TEXDraw strives 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

$\LaTeX$ spacing behavior 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.

Alternatively:

  • Use \par to explicitly start a new paragraph.
  • Use \linebreak or \\ to insert a soft break.

Also, use varieties of space commands to insert custom spacing:

  • \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>

Note: in $\LaTeX$, any continous whitespace is always ignored after a command, so it’s common to use double slash (e.g. \LaTeX\) for spaces to work as usual in text mode of $\LaTeX$.

Units

$\LaTeX$ has many measurement units to use, and it specified in real world units (e.g. pt) because \LaTeX was originally designed for printers. Unfornatunely, screens doesn’t work with these unit. TEXDraw comes up with its 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 ({...}) are used for scoping any side-effects within them (e.g. from text style or color changes). Sometimes, we can also give them additional properties which in $\LaTeX$ is called as environments. To use a $\LaTeX$ 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
  • \righttoleft or \lefttoright. Enable or disable right-to-left paragraph direction

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 a 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.

Font Sizes

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 is a combination of \mdseries, \rmfamily, and \upshape. To change one of them you simply need to call the command and everything else will be combined correctly.

There also single switch command which will not combine existing selected series, family, or shape. These are: \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, it need to be typed fully (e.g. \bfseries\itshape to use both italic and bold).

Note: these commands above are all replaces font style in current stack. $\LaTeX$ also provides non-overriding font style commands in \text* commands (e.g. \textit{<italic text>}).

Math mode in $\LaTeX$ uses different font set. You can use \math* commands (e.g. mathrm, mathbf) to get back to default font set in math mode.

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).

There’s also a set of predefined commands listed: red, cyan, blue, darkblue, lightblue, purple, yellow, lime, fuchsia, white, silver, grey, black, orange, brown, maroon, green, olive, navy, teal, aqua, magenta.

Note: TEXDraw’s color property set in the Unity object is only set the initial font color, it’s not sampling the overall 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.

Ligatures are not used in math mode.

Ligatures preview

Hyphens

It’s common to write a long sentence and then split them in between paragraph line. TEXDraw solves this problem by adding optional breaking hyphen by using \-. Write \- 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 TEXDraw automate this? No, because it’s computationally intensive to do so.

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, type the accent symbol followed by an alphabet (e.g. \`A becomes À).

accents example

Accents also handles special case where the alphabets are lower i and j, it 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 possible. 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.

Text Extras

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

Headings

Headings are available using \section, \subsection, \subsubsection commands. It will be numbered automatically.

\section{Section}
\subsection{Subsection}
\subsubsection{Subsubsection}

There’s also \title, \author, \date commands to set document title, author, and date.

To customize the style, edit in Block Macros of the configuration.

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|...|). If you want to use | in inline verbatim then you may use other non-special symbols as the delimiter such as \verb!...!.

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

Overlapping lines

This function creates a straight line over (\overline), under (\underline) or though (\midline) over a text.

overlines examples

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

image-20220103015120142

\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 the default text mode by these points:

  • In text 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.

Entering Math Mode

A math mode is started and ended by $...$ or \(...\) for inline mode and $$...$$ or \[...\] for 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 the legacy $\TeX$ $$ and $$$$ because of better clarity and avoid possible 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

Inline math will activate text mode while block math will activate display mode. Display mode has larger expression than text mode — it’s affecting how fractions, roots, scripts, large operators and limits displayed.

Aligning Math Expressions

By default, math mode is centered. There are more ways to customize this than simply aligning to the left or to the right.

You can leverage primitive boxes as they’re 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 is 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 opinion in other TeX platforms.

Fractions

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

\[\frac{\text{Nominator}}{\text{Denominator}}\]
$$ \frac{\text{Nominator}}{\text{Denominator}} $$
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

Integrals

Integrals is a part of Large Operators, hence it has the same rules as Large Operators. However, there’s special varieties of integrals that can be used for specific purposes.

\[\iint^2_0x\]
$$ \iint^2_0x $$

The integral varieties are: int, iint, iiint, idotsint, oint, varint, variint, variiint, varoint, varoiint.

Delimiters

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]\]
$$ z = \left[2\left(x + y^2\right) -{2x\over3}\right] $$

syntax delimiters

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

Matrices

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, binom and choose for enclosing the matrix with delimiters.

\[\begin{pmatrix}2&4x\\ 3&1\end{pmatrix}\times\begin{pmatrix}2y&8\\ 1&3\end{pmatrix}\]
$$
  \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>\]
$$ \not= \not< \not> $$
\[\not2x\over\not8_4\]
$$ \not2x\over\not8_4 $$

Over and Under Delimiters

Math delimiters can be rotated and placed on top or bottom of the expression. For example, \overbrace and \underbrace can be used to create a brace over or under the expression to show grouping. Use scripts to write expression above or below it.

\[\overbrace{E=mc^2}^{\text{Mass energy equivalence}}\]
$$ \overbrace{E=mc^2}^{\text{Mass energy equivalence}} $$

The complete list of over and under delimiters are: underset and overset, underbrace and overbrace, underbracket and overbracket, underparen and overparen, underangle and overangle, underleftarrow and overleftarrow, underrightarrow and overrightarrow, underleftrightarrow and overleftrightarrow.

Extra Functions

These commands used for aiding in advanced usage of geometry, layout and scripting.

Primitive Boxes

These are primitive commands from $\TeX$ can be 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 (also can be used for advanced math aligment too).

Transformation Boxes

These are commands that can be used to transform the content inside it.

  • \scalebox{<scale>}{<content>} Scale <content> by <scale>.
  • \rotatebox{<angle>}{<content>} Rotate <content> by <angle>.
  • \reflectbox{<content>} Reflect <content> horizontally.
  • \raisebox{<unit>}{<content>} Raise <content> by <unit>.

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.

Count Registers

Count registers is integer variable manipulation internally used by TEXDraw for dynamic numbering. Supported commands are:

  • \count Load a count register
  • \advance Increment a count register
  • \cmultiply Multiply a count register
  • \cdivide Divide a count register
  • \the, \number Print a count register
  • \roman Print a count register in roman numeral

This is internally used for list enumeration and headings. You can use it for your own purpose too, just be aware that TEXDraw only supports subset of $\TeX$ count register functions as listed above.

Importing .tex Files

Importing a $\TeX$ file can be used by using \input{<filename>}. The <filename> is a relative path to the file from Unity’s Resources folder. For example, if you put a file named mytex.tex in Assets/Resources folder, you can import it by using \input{mytex}.

There’s also \inlineinput so you can import a file and put it inline with the current text. For example, \inlineinput{mytex}.

Concrete list of commands

This article might be a little bit too long if you just want to see the list of commands.

The complete list of commands in code is programmed on TexModuleInitiator.cs. You might be interested to see (or modify!) the code there.