Mathematical expressions

With Snow Flower Text’s lightweight markup, mathematical expressions can be easily represented in either of the two textual notations, LatexMath or AsciiMath. The formula layout is publication-quality based on Donald Knuth’s TeX, which is the standard for typesetting academic papers.

Examples of beautiful mathematical expressions
\[x = \frac{-b \pm \sqrt{ b^2-4ac }}{2a}\]

The mathematical expression of Snow Flower Text has the following features.

HiDPI Support

Mathematical representations are handled in vector format. It renders vividly no matter what size you zoom in or out. This feature is inherited not only in the preview, but also in the exported PDF, HTML and EPUB.

Free choice of AsciiDoc and MarkDown lightweight markup

Snow Flower Text is designed to minimize the differences in lightweight markup as much as possible, and uses the same math processor as AsciiDoc and MarkDown. AsciiDoc and MarkDown use a common math processor, so you can choose a lightweight markup format without worrying about the differences in LatexMath support of math processors.

1. How to use

1.1. How to use LatexMath

The way LatexMath displays formulas can be divided into two main modes: inline and display. In inline mode, formulas are embedded as inline elements and treated as part of the text. In display mode, the equation is centered as a block element with line breaks before and after the equation.

1.1.1. Inline elements mode

How to write in AsciiDoc

Use the latexmath:[] inline macro.

This is an inline equation: latexmath:[e=mc^2].
How to write in Markdown

Enclose in \\( …​ \\).

This is an inline equation: \\( e=mc^2 \\)

The above code will be rendered as follows

This is an inline equation: \(e=mc^2\).

1.1.2. Block elements mode

How to write in AsciiDoc

Use the [latexmath] block macro.

[latexmath]
++++
x = \frac{-b \pm \sqrt{ b^2-4ac }}{2a}
++++
How to write in Markdown

Enclose in $$ …​ $$.

$$ x = \frac{-b \pm \sqrt{ b^2-4ac }}{2a} $$

The above code will be rendered as follows

\[x = \frac{-b \pm \sqrt{ b^2-4ac }}{2a}\]

1.2. How to use AsciiMath

Most AsciiMath symbols are textual mimics of their appearance. Compared to LatexMath, they are less expressive, but more simple.

1.2.1. Inline elements mode

How to write in AsciiDoc

Use the asciimath:[] inline macro.

asciimath:[x=(-b +- sqrt(b^2 – 4ac))/(2a)]
How to write in Markdown

Enclose in \\$ …​ \\$.

\\$ x=(-b +- sqrt(b^2 – 4ac))/(2a) \\$

The above code will be rendered as follows

\$x=(-b +- sqrt(b^2 – 4ac))/(2a)\$

1.2.2. Block elements mode

How to write in AsciiDoc

Use the [asciimath] block macro.

[asciimath]
++++
x=(-b +- sqrt(b^2 – 4ac))/(2a)
++++

The above code will be rendered as follows

\$x=(-b +- sqrt(b^2 – 4ac))/(2a)\$

2. LatexMath

2.1. Symbols

Table 1. Operation symbols
CodeDisplay

+

\(+\)

-

\(-\)

\pm

\(\pm\)

\times

\(\times \)

\div

\(\div \)

\setminus

\(\setminus \)

\ast

\(\ast \)

\star

\(\star \)

\cap

\(\cap \)

\bigcap

\(\bigcap \)

\cup

\(\cup \)

\bigcup

\(\bigcup \)

\sum

\(\sum \)

\prod

\(\prod \)

\coprod

\(\coprod \)

\int

\(\int \)

\iint

\(\iint \)

\iiint

\(\iiint \)

\oint

\(\oint \)

\intop

\(\intop \)

\smallint

\(\smallint \)

\wedge

\(\wedge \)

\bigwedge

\(\bigwedge \)

\vee

\(\vee \)

\bigvee

\(\bigvee \)

\sqcup

\(\sqcup \)

\bigsqcup

\(\bigsqcup \)

\otimes

\(\otimes\)

\bigotimes

\(\bigotimes\)

\oplus

\(\oplus \)

\bigoplus

\(\bigoplus \)

\odot

\(\odot \)

\bigodot

\(\bigodot \)

\uplus

\(\uplus \)

\biguplus

\(\biguplus \)

Table 2. Miscellaneous symbols
CodeDisplay

vfrac{2}{3}

\(\frac{2}{3}\)

2^3

\(2^3\)

\sqrt x

\(\sqrt x\)

\sqrt[3] x

\(\sqrt[3] x\)

Table 3. Relation symbols
CodeDisplay

=

\(= \)

\ne or \neq

\(\ne \)

<

\(< \)

>

\(> \)

\le or \leq

\(\le \)

\ge or \geq

\(\ge \)

\prec

\(\prec \)

\preceq

\(\preceq \)

\succ

\(\succ \)

\succeq

\(\succeq \)

\ll

\(\ll \)

\gg

\(\gg \)

\leqslant

\(\leqslant \)

\geqslant

\(\geqslant \)

\leqq

\(\leqq \)

\geqq

\(\geqq \)

\in

\(\in \)

\notin

\(\notin \)

\subset

\(\subset \)

\supset

\(\supset \)

\subseteq

\(\subseteq \)

\supseteq

\(\supseteq \)

\equiv

\(\equiv \)

\cong

\(\cong \)

\approx

\(\approx \)

\propto

\(\propto \)

Table 4. Logical symbols
CodeDisplay

\neg

\(\neg \)

\implies

\(\implies \)

\iff

\(\iff \)

\forall

\(\forall \)

\exists

\(\exists \)

\bot

\(\bot \)

\top

\(\top \)

\vdash

\(\vdash \)

\models

\(\models \)

Table 5. Grouping brackets
CodeDisplay

(

\(( \)

)

\() \)

[

\([ \)

]

\(] \)

{

\(\{ \)

}

\(\} \)

\langle

\(\langle \)

\rangle

\(\rangle \)

|x|

\(|x| \)

Table 6. Arrows
CodeDisplay

\Downarrow

\(\Downarrow \)

\Downarrow

\(\Downarrow \)

\downarrow

\(\downarrow \)

\get

\(\gets \)

\hookleftarrow

\(\hookleftarrow \)

\hookrightarrow

\(\hookrightarrow \)

\leadsto

\(\leadsto \)

\Leftarrow

\(\Leftarrow \)

\leftarrow

\(\leftarrow \)

\leftharpoondown

\(\leftharpoondown\)

\leftharpoonup

\(\leftharpoonup \)

\Leftrightarrow

\(\Leftrightarrow \)

\leftrightarrow

\(\leftrightarrow \)

\Longleftarrow

\(\Longleftarrow \)

\longleftarrow

\(\longleftarrow \)

\Longleftrightarrow

\(\Longleftrightarrow \)

\longleftrightarrow

\(\longleftrightarrow \)

\longmapsto

\(\longmapsto \)

\Longrightarrow

\(\Longrightarrow \)

\longrightarrow

\(\longrightarrow \)

\mapsto

\(\mapsto \)

\nearrow

\(\nearrow \)

\nwarrow

\(\nwarrow \)

\Rightarrow

\(\Rightarrow \)

\rightarrow

\(\rightarrow \)

\rightharpoondown

\(\rightharpoondown \)

\rightharpoonup

\(\rightharpoonup \)

\rightleftharpoons

\(\rightleftharpoons\)

\searrow

\(\searrow \)

\swarrow

\(\swarrow \)

\to

\(\to \)

\Uparrow

\(\Uparrow \)

\uparrow

\(\uparrow \)

\Updownarrow

\(\Updownarrow \)

\updownarrow

\(\updownarrow \)

Table 7. Accents
CodeDisplay

a'

\(a’\)

a''

\(a”\)

a^{\prime}

\(a^{\prime}\)

\acute{a}

\(\acute{a}\)

\bar{y}

\(\bar{y}\)

\breve{a}

\(\breve{a}\)

\check{a}

\(\check{a}\)

\dot{a}

\(\dot{a}\)

\ddot{a}

\(\ddot{a}\)

\grave{a}

\(\grave{a}\)

\hat{\theta}

\(\hat{\theta}\)

\widehat{ac}

\(\widehat{ac}\)

\tilde{a}

\(\tilde{a}\)

\widetilde{ac}

\(\widetilde{ac}\)

\vec{F}

\(\vec{F}\)

\overline{AB}

\(\overline{AB}\)

\underline{AB}

\(\underline{AB}\)

\overleftarrow{AB}

\(\overleftarrow{AB}\)

\underleftarrow{AB}

\(\underleftarrow{AB}\)

\overleftrightarrow{AB}

\(\overleftrightarrow{AB}\)

\underleftrightarrow{AB}

\(\underleftrightarrow{AB}\)

\overrightarrow{AB}

\(\overrightarrow{AB}\)

\underrightarrow{AB}

\(\underrightarrow{AB}\)

\overbrace{AB}

\(\overbrace{AB}\)

\underbrace{AB}

\(\underbrace{AB}\)

Table 8. Greek letters
CodeDisplay

\alpha

\(\alpha\)

\beta

\(\beta\)

\gamma

\(\gamma\)

\Gamma

\(\Gamma\)

\delta

\(\delta\)

\Delta

\(\Delta\)

\epsilon

\(\epsilon\)

\varepsilon

\(\varepsilon\)

\zeta

\(\zeta\)

\eta

\(\eta\)

\theta

\(\theta\)

\vartheta

\(\vartheta\)

\Theta

\(\Theta\)

\iota

\(\iota\)

\kappa

\(\kappa\)

\lambda

\(\lambda\)

\Lambda

\(\Lambda\)

\mu

\(\mu\)

\nu

\(\nu\)

\xi

\(\xi\)

\Xi

\(\Xi\)

\omicron

\(\omicron\)

\pi

\(\pi\)

\Pi

\(\Pi\)

\rho

\(\rho\)

\sigma

\(\sigma\)

\Sigma

\(\Sigma\)

\tau

\(\tau\)

\upsilon

\(\upsilon\)

\phi

\(\phi\)

\Phi

\(\Phi\)

\varphi

\(\varphi\)

\chi

\(\chi\)

\psi

\(\psi\)

\omega

\(\omega\)

\Omega

\(\Omega\)

2.2. Font

2.2.1. Font family

LatexMath uses italics by default. For example, if you are writing element symbols or units, it is better to change the font with the \mathrm command.

[latexmath]
++++
\mathrm{H_2+\frac{1}{2}O_2 = H_2O(l)+268kJ}
++++
When using the default font
\[H_2+\frac{1}{2}O_2 = H_2O(l)+268kJ\]
When changing the font with the \mathrm command
\[\mathrm{H_2+\frac{1}{2}O_2 = H_2O(l)+268kJ}\]
Table 9. Font codes
CodeDisplayDescription

\mathrm

\(\mathrm{ABCDEF\ abcdef\ 123456}\)

Serif

\mathbf

\(\mathbf{ABCDEF\ abcdef\ 123456}\)

Bold font

\mathit

\(\mathit{ABCDEF\ abcdef\ 123456}\)

Italic font

\mathsf

\(\mathsf{ABCDEF\ abcdef\ 123456}\)

Sans-serif

\mathtt

\(\mathtt{ABCDEF\ abcdef\ 123456}\)

Monospace

\textrm

\(\textrm{ABCDEF abcdef 123456}\)

\textbf

\(\textbf{ABCDEF abcdef 123456}\)

\textit

\(\textit{ABCDEF abcdef 123456}\)

\textsf

\(\textsf{ABCDEF abcdef 123456}\)

\texttt

\(\texttt{ABCDEF abcdef 123456}\)

\rm

\(\rm{ABCDEF}\)

\bf

\(\bf{ABCDEF}\)

\it

\(\it{ABCDEF}\)

\sf

\(\sf{ABCDEF}\)

\tt

\(\tt{ABCDEF\ abcdef\ 123456}\)

\Bbb

\(\Bbb{ABCDEF}\)

\mathcal

\(\mathcal{ABCDEF}\)

Calligraphy

\frak

\(\frak{ABCDEF\ abcdef\ 123456}\)

Fraktur

\boldsymbol

\(\boldsymbol{ABCDEF}\)

\mathbb

\(\mathbb{ABCDEF}\)

Blackboard bold

\mathscr

\(\mathscr{ABCDEF}\)

Script

\mathfrak

\(\mathfrak{ABCDEF\ abcdef\ 123456}\)

Fraktur

2.2.2. Font size

[latexmath]
++++
\Huge Lorem Ipsum
++++

The above code will be rendered as follows

\[\Huge Lorem\ Ipsum\]
CodeDisplay

\Huge

\(\Huge{Lorem\ Ipsum}\)

\huge

\(\huge{Lorem\ Ipsum}\)

\LARGE

\(\LARGE{Lorem\ Ipsum}\)

\Large

\(\Large{Lorem\ Ipsum}\)

\Large

\(\Large{Lorem\ Ipsum}\)

\normalsize

\(\normalsize{Lorem\ Ipsum}\)

\small

\(\small{Lorem\ Ipsum}\)

\scriptsize

\(\scriptsize{Lorem\ Ipsum}\)

\tiny

\(\tiny{Lorem\ Ipsum}\)

2.3. Layout

2.3.1. Align the height of the parentheses

The \left and \right commands can be used to automatically adjust the height of the parentheses if you want the parentheses to be automatically enlarged and adjusted to fit the mathematical expression in the parentheses.

For example, if the expression in parentheses is a fraction, the height of the parentheses will be insufficient.

\begin{align}
[\frac{3}{5} ] \\
(\frac{3}{5} ) \\
\{\frac{x+1}{y^2}\}
\end{align}
\[\begin{align} [\frac{3}{5} ] \\ (\frac{3}{5} ) \\ \{\frac{x+1}{y^2}\} \end{align}\]

The \left and \right commands are used to adjust the height.

\begin{align}
\left[ \frac{3}{5} \right] \\
\left( \frac{3}{5} \right) \\
\left\{\frac{x+1}{y^2}\right\}
\end{align}
\[\begin{align} \left[ \frac{3}{5} \right] \\ \left( \frac{3}{5} \right) \\ \left\{\frac{x+1}{y^2}\right\} \end{align}\]

2.3.2. Aligning the height of modifiers

The \mathstrut command will align the height of the modifier symbols.

In the following example, the height of the root symbol varies depending on the height of the character.

\sqrt{a} + \sqrt{b} + \sqrt{c} + \sqrt{d}
\[\sqrt{a} + \sqrt{b} + \sqrt{c} + \sqrt{d}\]

By using the \mathstrut command, the height of the parentheses will be aligned as follows

\sqrt{\mathstrut a} + \sqrt{\mathstrut b} + \sqrt{\mathstrut c} + \sqrt{\mathstrut d}
\[\sqrt{\mathstrut a} + \sqrt{\mathstrut b} + \sqrt{\mathstrut c} + \sqrt{\mathstrut d}\]

2.3.3. Align the text start position

f(n) = \left\{
\begin{array}{l l}
n/2 \quad \text{if $n$ is even}\\
-(n+1)/2 \quad \text{if $n$ is odd}\\
\end{array}
\right.
\[f(n) = \left\{ \begin{array}{l l} n/2 \quad \text{if $n$ is even}\\ -(n+1)/2 \quad \text{if $n$ is odd}\\ \end{array} \right.\]
f(n) = \left\{
\begin{array}{l l}
n/2 & \quad \text{if $n$ is even}\\
-(n+1)/2 & \quad \text{if $n$ is odd}\\
\end{array}
\right.
\[f(n) = \left\{ \begin{array}{l l} n/2 & \quad \text{if $n$ is even}\\ -(n+1)/2 & \quad \text{if $n$ is odd}\\ \end{array} \right.\]

This will align the text start position.

2.3.4. Change to block mode while in inline mode

\sum_{k=1}^{n}k^2

\(\sum_{k=1}^{n}k^2\)

\displaystyle \sum_{k=1}^{n}k^2

\(\displaystyle \sum_{k=1}^{n}k^2\)

2.3.5. Label equation with a symbols

Use \tag{label} to add an equation number to the equation, where label can be any character.

\frac{3}{5} \tag{5}
\[\displaystyle \frac{3}{5} \tag{5}\]

Use \tag*{label} if parentheses are not needed.

\frac{3}{5} \tag*{5}
\[\displaystyle \frac{3}{5} \tag*{5}\]

3. LatexMath Sample

The Lorenz Equations
\begin{align}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{align}
\[\begin{align} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x – y – xz \\ \dot{z} & = -\beta z + xy \end{align}\]
The Cauchy-Schwarz Inequality
\left( \sum_{k=1}^n a_k b_k \right)^{\!\!2} \leq
\left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)
\[\left( \sum_{k=1}^n a_k b_k \right)^{\!\!2} \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)\]
A Cross Product Formula
\mathbf{V}_1 \times \mathbf{V}_2 =
\begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \\
\end{vmatrix}
\[\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \\ \end{vmatrix}\]
A Rogers-Ramanujan Identity
1 +  \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =
\prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},
\quad\quad \text{for $|q|<1$}.
\[1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots = \prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})}, \quad\quad \text{for $|q|<1$}.\]
An Identity of Ramanujan
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }
\[\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }\]

4. AsciiMath Sample

x=(-b +- sqrt(b^2 – 4ac))/(2a)
\$x=(-b +- sqrt(b^2 – 4ac))/(2a)\$

6. Reference

Download on the Mac App Store