In RMarkdown, how to include latex code when using an HTML or Word output

Viewed 1241

I have a very basic question. I did not find an answer anywhere. My fear is that the answer is simply no.

Using R Markdown, I would like to use LaTex code with an HTML or Word output.

A very simple MVE :

I would like to execute the following code :

This text has been written with both \LaTeX{} and Rmd codes.

With a LaTex/PDF output, no problem. I get 'This text has been written with both Latex and Rmd codes.' (with the nice LaTeX logo !)

With an HTML or Word output, I get 'This text has been written with both and Rmd codes.'

So the LateX code disappears with non-LateX output.

Do you know if there is a way to fix this?

Thanks in advance,

Eric

EDIT: Here is another example using a simple table

\begin{table}[h]
\centering
\caption{A simple table}
\begin{tabular}{|l|c|c|}
\hline
a & b & c \\
d & e & f \\
\hline
\end{tabular}
\end{table}
1 Answers

It will work if you put the LaTeX output between dollar signs. In HTML, it will not work if you are offline though! :

This text has been written with both $\LaTeX{}$ and Rmd codes.

In R Markdown, Pandoc converts LaTeX into Office Math Markup (OMML). So you can get LaTeX output in Word, but you won't get the logo, as far as I know.

For LaTeX output in Word, remove the backslash and add the dollar signs, like this:

This text has been written with both $LaTeX{}$ and Rmd codes.

Or leave a space between the backslash and the output:

This text has been written with both $\ LaTeX{}$ and Rmd codes

Here is a snapshot from a document generated in Word:

Code and output in Word

Related