# How to fix some compilation issues using R Markdown and Latex markups?

Hi everyone! I've been using Latex for years now and used it for my PHD, but now I've changed my workflow, I'd like to use R Markdown in every file I work on, especially research articles. To this purpose, I've built a YAML preamble and insert some Latex markups in order to output a documentclass book, but I have some complications:

1. I use fontspec and a specific font and when I compile my file, dashes are not displayed between pages numbers while it displays correctly with the standard font. Why? And how to fix that?

2. The TOC displays wrong numbers in the frontmatter as you can see on the picture:

3. In the backmatter, the header display the previous chapter, not the current one. Why? and how to fix that?
Those are my MWE and my preamble.tex:

---
title: A title
date:
documentclass: book
fontsize: 12pt
geometry: left=6cm,right=6cm,top=7cm,bottom=7cm
linestretch: 1.1
toc-title: Table
bibliography: "r-references.bib"
csl: "apa7-fr-couture.csl"
- \usepackage[french]{babel}
- \usepackage{hyperref}
- \usepackage{fontspec}
- \setmainfont[Numbers=OldStyle,Mapping=tex-text]{Janson Text LT Std}
output:
pdf_document:
includes:
latex_engine: xelatex
toc: yes
toc_depth: 1
number_sections: yes
html_document:
toc: yes
toc_depth: '5'
df_print: paged
word_document:
toc: yes
toc_depth: 5
---

\frontmatter

# Synopsis

\mainmatter

# A chapter

\backmatter

# A chapter

# References



My preamble.tex :

\frenchspacing

\usepackage{fancyhdr}

\pagestyle{fancy}
% We don’t want chapter and section numbers
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\fancyhf{} % sets both header and footer to nothing
\fancyfoot{}
\fancyhead[CE]{\textit{A title}} % even pages: chapter title
\fancyhead[CO]{\textit\leftmark} % odd pages: book title

\usepackage{titlesec}
\usepackage{titling}
\titleformat*{\section}{\normalsize\itshape}
\titleformat*{\subsection}{\normalsize\itshape}
\titleformat*{\subsubsection}{\normalsize\itshape}
\titleformat{\chapter}[display]%
{\centering\Large\bfseries}% format of chapter
{\large\normalfont\MakeUppercase{\chaptertitlename}\enskip\thechapter}% format of the label
{.5\baselineskip}{} % space between the two
\titlespacing*{\chapter}{0pt}{25pt}{35pt} % spaces around \chapter{}, {left}{before}{after}

%\titleformat{\chapter}[display]
%{\normalfont\bfseries}{}{0pt}{\Huge}

\setlength\parindent{15pt}\setlength{\parskip}{0.0pt plus 1.0pt}


The \frontmatter has to be placed before \maketitle. But, as \maketitle was not inserted into my file, it could not work.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.