Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spanish characters in R Markdown are working in headers but not the body, even though it does work in pure Latex

R Markdown is working properly on the headers of my document, but not the body, as spanish characters look different. When I use pure Latex (Overleaf) it works in both the body and header.

If I copy-paste spanish characters (eg. á, é, ñ, ó) they are preserved as such, but if I use the backslash-hyphen method (\'a, \'e, \~n, \'o) they only translate properly in the headers of the document but not the body.

I already checked if i was using utf8 (I was), and the headers-include and \usepackage functions didn't help either.

\section{Secci\'on \~n}
Hola, esta es mi primera edici\'on de texto
\subsection{Subsecci\'on}
Esto deber\'ia ser una subsecci\'on.
Ahora, anotaré una f\'ormula, tal que $\lim_{x \rightarrow y} x = y$

This is how it currently knits:

https://i.stack.imgur.com/P91QF.png

As you can see, the headers display said characters properly, while the body only renders spanish characters correctly if It type them directly (the e), which I can't do because my keyboard doesn't have them. Using unicode is a not an ideal solution.

like image 812
Emiliano Andrés Núñez Avatar asked Nov 06 '22 13:11

Emiliano Andrés Núñez


1 Answers

You don't have to use such native TeX commands as \' to add characters with accents to your document if you set xelatex as the latex_engine.

---
title: "Untitled"
author: "Author"
date: "2020/4/16"
output:
  pdf_document2:
  #bookdown::pdf_document2: #When you need cross-referencing of figures and tabular
    latex_engine: xelatex
---

# Sección ñ

Hola, esta es mi primera edición de texto

## Subsección

Esto debería ser una subsección.
Ahora, anotaré una fórmula, tal que $\lim_{x \rightarrow y} x = y$
like image 156
Carlos Luis Rivera Avatar answered Nov 15 '22 07:11

Carlos Luis Rivera