2

I want to use the LaTeX syntax for writing french accents/special characters in RMarkdown, but it doesn't work. \'{a} for instance doesn't compile but is literally printed in the pdf document. So far I didn't encounter any problems using arbitrary LaTeX code in my RMD documents. Are there some special compiling options I have to set maybe? I'm using RStudio to edit and compile the document.

Minimal example:

---
header-includes:
   - \usepackage[utf8]{inputenc}
   - \usepackage[french]{babel}
   - \usepackage[T1]{fontenc}
output:
  pdf_document: default
  html_document: default
---

r\^{o}les apr\`{e}s cong\'{e}
3

Why this happens is because Rmarkdown pass to LaTeX unchanged only what is recognized as LaTeX code as:

\begin{whatever} ... whatever... \end{whatever} 

or

\whatever{whatever} 

or even

{\whatever whatever} 

Where \whatever could be any name, even a single letter, but not a sign. So special characters with letters as \H{o} or \c{c} are recognized as commands, but not \={o} or \~{o}. I guess that this is because recognize signs as command names could complicate the recognition algorithm or produce undesired effects, o simply was an unexpected use case because:

  • It is harder to write is this way.
  • It is harder to read the source is this way.

Anyway, you can always include these specials characters in a recognizable latex environment:

\newcommand\latexcode[1]{#1}

\latexcode{r\^{o}les apr\`{e}s cong\'{e}} 

But the more important is that even if a special command as \^{o} can be passed unchanged to LaTeX, it must be completely ignored when exported to HTML or Word, while ô is perfectly exportable to the three formats.

So, keep it simple, and use the keyboard to make composed characters as far as possible:

---
lang: fr
output:
  html_document: default
  pdf_document: default
---

rôle après congé
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.