I am having trouble rendering some Latex code with R Markdown in HTML using the excellent xaringan R package. Specifically I would like to label the rows and columns of a matrix as described here. The thing is that, as far as I understand, some Latex packages cannot be used in R Markdown. Therefore, I am using a <div class="math">My matrix in Latex here</div>
. I'm almost there but I keep getting random opening single quotes that I cannot get rid of:
Must be something silly. Any help would be much appreciated.
The Rmd code is as follows:
---
title: 'Matrix'
output:
xaringan::moon_reader
---
<div class="math">
\[
\begin{array}{cc} &
\begin{array}{ccc} a & b & c
\end{array}
\\
\begin{array}{ccc}
p \\
q \\
r
\end{array}
&
\left(
\begin{array}{ccc}
.1 & .1 & 0 \\
.4 & 1 & 0 \\
.8 & 0 & .4
\end{array}
\right)
\end{array}
\]
</div>
In our experience, it is also mostly workable to include LATEX code in R markdown documents. Recall that documents in R markdown are converted from Rmd to md by the knitting process, and then into LATEX by pandoc, and then into PDF by a LATEX compiler (pdflatex, xetex or similar).
If you're using R Studio with the visual editor, you can add columns using Insert > DIV , creating an empty wrapper DIV of class . columns and adding child DIV's with Classes set to . column and width=x% in 'Other'.
Rmd file, you may now add text to your document. You may start with the most basic word processing—simply typing your text below the YAML header section. If you want to start a new paragraph, you can simply hit Enter twice on your key- board, and begin writing again.
This is a bug of xaringan. A workaround is to move \end{array}
to the end of the previous line, e.g.,
---
title: 'Matrix'
output:
xaringan::moon_reader
---
<div class="math">
\[
\begin{array}{cc} &
\begin{array}{ccc} a & b & c\end{array}
\\
\begin{array}{ccc}
p \\
q \\
r\end{array}
&
\left(
\begin{array}{ccc}
.1 & .1 & 0 \\
.4 & 1 & 0 \\
.8 & 0 & .4\end{array}
\right)\end{array}
\]
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With