yihui / xfun

Miscellaneous R functions
https://yihui.org/xfun/
Other
135 stars 28 forks source link

Label rows and columns of a matrix in R Markdown with Latex and HTML rendering #51

Closed oliviergimenez closed 3 years ago

oliviergimenez commented 3 years ago

Hi there,

I have asked the question below on stackoverflow here, to which @yihui answered that this was a bug of xaringan. He suggested a simple workaround which consists in moving \end{array} to the end of the previous line. This works like a charm. He also suggested that I'd file a bug report. So here I am.

Original question: 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:

GGTtr

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>

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

yihui commented 3 years ago

Thank you! I just realized that it was a bug of xfun::protect_math(), so I'm moving this issue to the repo yihui/xfun.

yihui commented 3 years ago

Should be fixed now. Thanks for the report!