Math syntax
===========

[[Parent]]: remark_syntax.txt

Mathematics can be written in Remark using either the [AsciiMath syntax][AsciiMath], or the [Latex syntax][MathJaxLatex]. Here we provide a brief tutorial to both syntaxes; complete list of commands for the syntaxes can be found from the above links. 

Inline mathematics in AsciiMath and Latex are enclosed in `''` and `$`, respectively. Display mathematics in Latex is enclosed in `$$`. 

_Note_: MathJax 2.5 --- which renders the mathematics --- [contains a bug][MathJaxBug] which makes the equation number to overlap a long equation. Since Remark refers to MathJax via CDN, this problem will be automatically fixed with the next version of MathJax.

[MathJaxBug]: https://github.com/mathjax/MathJax/issues/1189

[MathJax]: http://www.mathjax.org
[MathJaxLatex]: http://docs.mathjax.org/en/latest/tex.html#supported-latex-commands
[AsciiMath]: http://asciimath.org
[MathJaxConfig]: [[Ref]]: mathjax-config.js
 
Realistic constructs
--------------------

### Quadratic equation

[[Example]]:
	The solution to the quadratic equation is ''x = (-b +- sqrt(b^2 - 4ac)) / (2a)''.

[[Example]]:
	The solution to the quadratic equation is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.

### Equation labels

[[Example]]:
	The quadratic equation is given by 
	$$a x^2 + b x + c = 0 \label{Quadratic}.$$ 
	The solution to Equation $\ref{Quadratic}$ is given by 
	$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.$$

### Equation tags

[[Example]]:
	The quadratic equation is given by 
	$$a x^2 + b x + c = 0 \label{Quadratic2} \tag{quadratic equation}.$$ 
	The solution to the $\ref{Quadratic2}$ is given by 
	$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}. \notag$$

### Reflexivity

[[Example]]:
	''R " is reflexive" <=> forall x: x R x''

[[Example]]:
	$R \textrm{ is reflexive} \iff \forall x: x R x$

### Transitivity

[[Example]]:	
	''R " is transitive" <=> forall x, y, z: (xRy ^^ yRz) => xRz''

[[Example]]:	
	$R \textrm{ is transitive} \iff \forall x, y, z: (xRy \land yRz) \implies xRz$

### Continuity

[[Example]]:
	A function $f : \mathbb{R}^n \to \mathbb{R}^m$ is _continuous_ at $p \in \mathbb{R}^n$, if
	$$\forall \varepsilon \in \mathbb{R}^{> 0}: \exists \delta \in \mathbb{R}^{> 0}: \forall x \in \mathbb{R}^n : \left\lVert x - p \right\rVert < \delta \implies \left\lVert f(x) - f(p) \right\rVert < \varepsilon.$$

[[Example]]:
	A function ''f : RR^n -> RR^m'' is _continuous_ at ''p in RR^n'', if

	''forall epsilon in RR^{> 0}: exists delta in RR^{> 0}: forall x in RR^n: ||x - p|| < delta => ||f(x) - f(p)|| < epsilon''

### Differentiability

[[Example]]:
	A function $f : \mathbb{R}^n \to \mathbb{R}^m$ is _differentiable_ at $p \in \mathbb{R}^n$, if
	$$\frac{\left\lVert f(p + h) - \left[ f(p) + (D_p f)(h) \right] \right\rVert}{\left\lVert h \right\rVert} \xrightarrow{h \to 0} 0.$$

### Limit

[[Example]]:
	''1 / n stackrel(n -> infty)(->) 0''

[[Example]]:
	$\frac{1}{n} \xrightarrow{n \to \infty} 0$

Basic constructs
----------------

### Basic constructs

#### Fraction

[[Example]]:
	''(x+1)/(x-1)''

	$\frac{x + 1}{x - 1}$

#### Superscript

[[Example]]:
	''x^(i+j)'' 

	$x^{i + j}$ 

#### Subscript

[[Example]]:
	''x_(ij)''

	$x_{ij}$

#### Square-root
	
[[Example]]:
	''sqrt(x)'' 

	$\sqrt{x}$ 

#### Root

[[Example]]:
	''root(n)(x)'' 

	$\sqrt[n]{x}$ 

#### Stacking symbols

[[Example]]:
	''stackrel(n -> infty)(->)''

	$\overset{n \to \infty}{\to}$

	$\xrightarrow{n \to \infty}$

#### Text

[[Example]]:
	 ''text(is reflexive)''

	 ''"is reflexive"''

	 $\textrm{is reflexive}$

### Operation symbols

[[Example]]:
	''+ - * // \\ xx -: @ o+ ox sum prod ^^ ^^^ vv vvv nn nnn uu uuu''

	$+ - * / \setminus \times \div \circ \oplus \otimes \sum \prod \land \bigwedge \lor \bigvee \cap \bigcap \cup \bigcup$

### Relation symbols

[[Example]]:
	''= != < <= > >= -< >- in !in sub sup sube supe -= ~= ~~ prop''

	$= \neq < \leq > \geq \prec \succ \in \not\in \subset \supset \subseteq \supseteq \equiv \approxeq \approx \propto$

### Logical symbols

[[Example]]:
	''and or not => iff forall exists TT |--''

	$\land \lor \lnot \implies \iff \forall \exists \top \bot \vdash \vDash$

### Miscellaneous symbols

[[Example]]:
	''int oint del grad +- O/ oo aleph ... cdots \ quad qquad diamond square |~ ~|''

	$\int \oint \partial \nabla \pm \emptyset \infty \aleph \dots \cdots \quad \qquad \diamond \square \lceil \rceil \lfloor \rfloor$

### Standard functions

[[Example]]:
	''sin cos tan csc sec cot sinh cosh tanh log ln det dim lim mod gcd lcm''

	$\sin \cos \tan \csc \sec \cot \sinh \cosh \tanh \log \ln \det \dim \lim \mod \gcd$

### Grouping brackets

[[Example]]:
	''(x) [x] {x} (:x:)''

	$(x) [x] \{x\} \langle x \rangle$

### Arrows

[[Example]]:
	''uarr darr -> larr harr => lArr <=>''

	$\uparrow \downarrow \to \leftarrow \leftrightarrow \Uparrow \Downarrow \Rightarrow \Leftarrow \Leftrightarrow$

### Accents

#### Hat

[[Example]]:
	''hat(2 + 3 * 4)''

	$\hat{x}$

	$\widehat{2 + 3 * 4}$

#### Dot

[[Example]]:
	''dot(x)''

	$\dot{x}$

#### Two dots

[[Example]]:
	''ddot(x)''

	$\ddot{x}$

#### Overline

[[Example]]:
	''bar(2 + 3 * 4)''

	$\overline{2 + 3 * 4}$

#### Underline

[[Example]]:
	''ul(2 + 3 * 4)''

	$\underline{2 + 3 * 4}$

#### Vector arrow

[[Example]]:
	''vec(2 + 3 * 4)''

	$\vec{x}$

	$\overrightarrow{2 + 3 * 4}$

### Font commands

#### Normal

[[Example]]:
	''text(abcdefghijklmnopqrstuvwxyz)''
	
	''text(ABCDEFGHIJKLMNOPQRSTUVWXYZ)''

	$\mathrm{abcdefghijklmnopqrstuvwxyz}$
	
	$\mathrm{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Bold

[[Example]]:
	''bb("abcdefghijklmnopqrstuvwxyz")''

	''bb("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathbf{abcdefghijklmnopqrstuvwxyz}$

	$\mathbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Blackboard-bold
	
[[Example]]:
	''bbb("abcdefghijklmnopqrstuvwxyz")''

	''bbb("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathbb{abcdefghijklmnopqrstuvwxyz}$

	$\mathbb{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Script
	
[[Example]]:
	''cc("abcdefghijklmnopqrstuvwxyz")''

	''cc("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathscr{abcdefghijklmnopqrstuvwxyz}$

	$\mathscr{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Calligraphic
	
[[Example]]:
	$\mathcal{abcdefghijklmnopqrstuvwxyz}$

	$\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Monospace

[[Example]]:
	''tt("abcdefghijklmnopqrstuvwxyz")''

	''tt("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathtt{abcdefghijklmnopqrstuvwxyz}$

	$\mathtt{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

#### Fraktur
	
[[Example]]:
	''fr("abcdefghijklmnopqrstuvwxyz")''

	''fr("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathfrak{abcdefghijklmnopqrstuvwxyz}$

	$\mathfrak{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$
	
#### Sans-serif

[[Example]]:
	''sf("abcdefghijklmnopqrstuvwxyz")''

	''sf("ABCDEFGHIJKLMNOPQRSTUVWXYZ")''

	$\mathsf{abcdefghijklmnopqrstuvwxyz}$

	$\mathsf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}$

### Matrices

[[Example]]:
	''[[a,b],[c,d]] ((1,0),(0,1))''

	$\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}$

### Greek letters

[[Example]]:
	''alpha beta gamma delta epsi zeta eta theta iota kappa lambda mu nu xi o pi rho sigma tau upsilon phi chi psi omega''

	''A B Gamma Delta E Z H theta I K Lambda N N Xi O Pi P Sigma T Y Phi X Psi Omega''

	$\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta \theta \iota \kappa \lambda \mu \nu \xi o \pi \rho \sigma \tau \upsilon \phi \chi \psi \omega$

	$A B \Gamma \Delta E Z H \theta I K \Lambda N N \Xi O \Pi P \Sigma T Y \Phi X \Psi \Omega$

