6

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:

opening single quotes in matrix

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>
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419

1 Answers1

6

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>
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Awesome, thanks! I wish I could vote this answer useful, but my reputation is too low for my vote to be displayed. – user2070174 Apr 13 '21 at 20:07
  • Don't worry. I don't really care. You may mark the answer as accepted if it works for you, or file a bug report to the Github repo `yihui/xaringan`. Thank you! – Yihui Xie Apr 13 '21 at 20:59