7.1 Syntax Comparison with LaTeX
For LaTeX users, switching to R Markdown is almost seamless.
R Markdown supports LaTeX math syntax. So, mathematical writing are pretty much the same as those in the LaTex.
Inline math:
$\sqrt{x}$
Display format:
$$f(x)=x^2$$
or\[ f(x)=x^2 \]
.
The only minor difference is that any math environment has to be placed inside math mode. For example,
\[
\begin{pmatrix}
a & b \\ c & d
\end{pmatrix}
\]
Most LaTeX syntax works fine R Markdown. For example, if the LaTeX color package is loaded in R Markdown, then we can use
\textcolor{red}{texts}
to change the color of texts to red.Of course, R Markdown has its own set of syntax as well (for non-LaTex users). The following table compares some common text syntax between LaTex and R Markdown.
Task | LaTeX | R Markdown |
---|---|---|
Bold | {\bf xyz} |
**xyz** |
Italic | {\it xyz} |
*xyz* |
Footnote | a\footnote{b} |
a^[b] |
Superscript | a\textsuperscript{2} |
a^2^ |
Subscript | a\textsubscript{2} |
a~2~ |
Text Backslash | \textbackslash |
\\ |
Inline verbatim | \verb|code| |
`code` |
Hyperlink | \href{url}{text} |
![text](url) |