Mathematics representation Rtest

  1. Rtest uses MathJax which turns LaTeX commands into mathematic symbols.
  2. The following table introduces some of the frequently used LaTeX commands.
  3. Try to read through those info before create any formula in test editor.
  4. However, the command that you have entered in test editor will not be rendered immediately. You need to view it in preview mode.
  5. The published tests will render the formula as you have seen in the preview mode.
  6. For more information:
  7. Sometimes, when you are editing a paragraph, and you just need a fraction or symbol, then probably it would be better to use text rather than LaTeX command (for better uniformity).


Table: LaTeX code for Math

#DescriptionLaTex codeOutput
1 Enclose formula with \( ... \) (inline mode) or $$ ... $$ (display mode)
* Rtest prefers to use inline-mode for most case
* Since this enclosement is required for all commands, then it will not be shown in subsequent commands for readability.
E.g.: inline-mode
\( \frac{1}{2}\int x^3 dx \)
\( \frac{1}{2}\int x^3 dx \)
E.g: display-mode
$$ \frac{1}{2}\int x^3 dx $$
$$ \frac{1}{2}\int x^3 dx $$
2 Superscript
Use ^
x^3\( x^3 \)
3 Subscripts
Use _
y_i\( y_i \)
4Grouping
Use { ... } to group any literals, terms, etc.
* Notice the differences with/without proper grouping
12^34, \frac pqrs\( 12^34 \), \( \frac pqrs \)
12^{34}, \frac {pq}{rs}\( 12^{34} \), \( \frac {pq}{rs} \)
5Parentheses
Use ( ... ), [ ... ], and \{ ... \} for direct display
Use \left( ... \right), \left[ ... \right], \left{ ... \right} for scaled display
* Notice the different with/without scaling
( x + 5)^2, ( \dfrac x2 +5)^2\( ( x + 5)^2 \), \( ( \dfrac x2 +5)^2 \)
\left( x + 5\right)^2, \left( \dfrac x2 +5\right)^2\( \left( x + 5\right)^2 \), \( \left( \dfrac x2 +5\right)^2 \)
6 Fraction
Use \frac or \dfrac (display mode)
* Remember to group appropriately
\frac ab, \frac {(x+1)^2}{(\frac x2-1)^5}\( \frac ab \), \( \frac {(x+1)^2}{(\frac x2-1)^5} \)
\dfrac ab, \dfrac {(x+1)^2}{(\frac x2-1)^5}\( \dfrac ab \), \( \dfrac {(x+1)^2}{(\frac x2-1)^5} \)
7 Radical sign \sqrt{x}, \sqrt[5]{x_i}\( \sqrt{x} \), \( \sqrt[5]{x_i} \)
8Operator
Use + - \times \div \pm \mp for +, −, ×, ÷, ±, ∓
Use \lt \gt \le \ge \neq \approx for <, >, ≤, ≥, ≠, ≈
Use \cup \cap for ∪, ∩
+ - \times \div\( + - \times \div \)
9 Functions
Most functions in mathematic are available, such as \sin, \cos, \sum, \int, \lim, \log etc.
\sin x, \lim_{x \to \infty} \frac {1}{x}, \lim \limits_{x\to 0} 3x, \int_0^{10} x\, dx\( \sin x \), \( \lim_{x\to \infty} \frac {1}{x} \), \(\lim \limits_{x\to 0} 3x \), \( \int_0^{10} x\, dx \)
10Spacing
a b or even a b will have the same result (\( a b \))
You need \,, \;, \quad and \qquad for small, medium, big, large space respectively.
\int x^2\,dx\( \int x^2\,dx\)
11Accents and diacritical marks\hat x, \widehat {xyz}, \vec P, \overrightarrow {xy}, 3.\dot4\dot3\(\hat x\), \(\widehat {xyz}\), \(\vec P\), \(\overrightarrow {xy}\), \(3.\dot4\dot3\)
12Matrices
Use \begin{matrix} ... \end{matrix} to form a matrix.
Separate each elements with & and end each row with \\.
Few variant of matrix are available, i.e. matrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix
\begin{matrix} 1 & 2 \\ 3 & 4\end{matrix}\(\begin{matrix} 1 & 2 \\ 3 & 4\end{matrix}\)
\begin{pmatrix} ... \end{pmatrix}\(\begin{pmatrix} 1 & 2 \\ 3 & 4\end{pmatrix}\)
\begin{bmatrix} ... \end{bmatrix}\(\begin{bmatrix} 1 & 2 \\ 3 & 4\end{bmatrix}\)
\begin{Bmatrix} ... \end{Bmatrix}\(\begin{Bmatrix} 1 & 2 \\ 3 & 4\end{Bmatrix}\)
\begin{vmatrix} ... \end{vmatrix}\(\begin{vmatrix} 1 & 2 \\ 3 & 4\end{vmatrix}\)
\begin{Vmatrix} ... \end{Vmatrix}\(\begin{Vmatrix} 1 & 2 \\ 3 & 4\end{Vmatrix}\)
13Aligned equation
To align a series of equations, use \begin{align} ... \end{align}.
Insert & at the align point of each line.
End each line with \\.
\begin{align} y & = (x^2 + 5)_{x=3} \\& 3^2 + 5 \\ & 15 \end{align}\( \begin{align} y & = (x^2 + 5)_{x=3} \\ & = 3^2 + 5 \\ & = 15 \end{align} \)