3

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}
Eric
  • 65
  • 6

1 Answers1

0

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

ViviG
  • 1,613
  • 1
  • 9
  • 23
  • Thanks very much. Basically, my point was for any type of Latex input (not especially the Latex symbol), I tought it was easier to explain it like that but it may have created confusion! Sorry ! I'll try the different syntaxes with something else than the LateX symbol which might be a special case. Thanks so much. – Eric Jan 11 '21 at 19:52
  • But using the $ sign does work for other LaTeX inputs, have you tried? – ViviG Jan 12 '21 at 05:39
  • I did using a simple table. Unfortunately, I did try all the possible syntaxes but it does not work. I post the table code into the question. – Eric Jan 12 '21 at 20:39
  • You should ask another question in this case. But this question regarding tables has been asked before [here](https://stackoverflow.com/questions/38386808/render-latex-tables-in-html-using-rmarkwown). Anyway, I recommend you taking a look at the package [kableExtra](https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf) – ViviG Jan 13 '21 at 00:55
  • Tks for your message and suggestion. I did look at the link. Very interesting! I'll look at the kableExtra package also. I was looking for a solution for teaching purposes so I will restrict to a simple solution (no add. package) and deepen my knowledge of all that. Thanks agian! – Eric Jan 14 '21 at 13:30