How to print special Latin characters in Markdown pdfs - r-markdown

I need to knit my Markdown script into a pdf file, but when knitted, the pdf file does not show special Latin characters, such as those used in the International Phonetic Alphabet (IPA).
---
title: "MarkdownIPA"
date: '2022-07-06'
output:
pdf_document:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
`Print IPA`
```{r}
'[aɪ.pʰiː.ɛɪ]'
```
Which rends:
How can I fix this?

You'll need to use a font that supports those glyphs. A (IMHO) rather nice one is Source Sans Pro and the monospace variant Source Code Pro.
To use Source Code Pro, you can add the respective LaTeX code directly:
---
title: "MarkdownIPA"
date: '2022-07-06'
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{sourcecodepro}
---
Result:
The sourcecodepro package is likely already installed; otherwise you'd have to install it first.

Related

How to have roboto font in bookdown::pdf_document2?

Anyone suggestions on how to get roboto font in bookdown::pdf_document2?
The code below works fine, when I change the font to Roboto it does not, see also picture. The Roboto and the Comic Sans MS font are in my c:\Windows\Fonts, I use Miktex for pdf-ing. Thanks!
---
header-includes:
- \usepackage{fontspec}
- \setmainfont{Comic Sans MS}
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
You can do \usepackage{roboto}. See README of the package for further detailed usage. If you knit the document without roboto package, programmes for knitting documents using LaTeX (e.g. R's tinytex or even MikTeX) will automatically install the missing package(s). See the relevant page of R Markdown Cookbook.
To make specific texts san serif
---
header-includes:
- \usepackage{roboto}
# - \usepackage[sfdefault]{roboto} # To make every texts san serif
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
`\textsf{This is a san serif text.}`{=latex}
To make every texts san serif
---
header-includes:
#- \usepackage{roboto}
- \usepackage[sfdefault]{roboto} # To make every texts san serif
output:
bookdown::pdf_document2:
toc: false
latex_engine: xelatex
---
# Title
This is some text.
This is some more text.
`\textsf{This is a san serif text.}`{=latex}

Problem with ligatures in Rmarkdown / bookdown pdf output

In my Rmarkdown project, I'm having trouble in correctly exporting ligatures in PDF file.
font-config.tex file -
\usepackage{fontspec}
\setmainfont{Noto Sans}
YAML front-matter in Rmd file -
---
title: "test"
author: "author"
date: "22/02/2021"
output:
pdf_document:
latex_engine: xelatex
includes:
in_header: font-config.tex
---
The following text is in hindi language.
गुरु
Output shown in PDF -
Output expected -
The Nakula font is correctly displayed, but it does not have bold-face type font.
The Noto Sans font I'm using works fine in html output, but have problem with ligature in PDF output.
I tried, the pandoc documentation and other similar questions on stackoverflow and tex.stackexchange, but no luck.
I'm new to TeX, and hopefully it has a very simple solution.
This may work for you, following the information given here:
---
title: "Hindi"
author: "bttomio"
output:
pdf_document:
latex_engine: xelatex
header-includes:
- \usepackage{fontspec}
- \setmainfont{Noto Sans}
- \usepackage{polyglossia}
- \setdefaultlanguage{hindi}
- \setotherlanguage{english}
- \newfontfamily\devanagarifont[Scale=MatchUppercase]{Nakula}
- \newfontfamily\devtransl[Mapping=DevRom]{Times New Roman}
---
The following text is in hindi language.
गुरु
-output

Running code chunk in R-markdown using exam document class

I would like to run a code chunk under a question level in the exam document class, but I keep receiving errors. I am assuming this is because it believes the output from the R-code is Latex code.
---
output: pdf_document
documentclass: exam
header-includes: \usepackage{float}
---
\begin{questions}
\question Answer question...
```{r}
iris%>%
group_by(Species)%>%
summarize(Total=n())
```
\end{questions}
Sometimes \begin{"some environment") ... \end{"some environment") doesn't play well with R chuncks. One work around is to define a new environment.
For example, I defined a file preamble.tex with the following information:
preamble.tex
\usepackage{float}
\newcommand{\bQ}{\begin{questions}}
\newcommand{\eQ}{\end{questions}}
Then, I ran the following.
exam.Rmd
---
documentclass: exam
geometry: margin=.5in
output:
pdf_document:
highlight: haddock
includes:
in_header: preamble.tex
before_body: doc-prefix.tex
after_body: doc-suffix.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\bQ
## Including Plots
\question You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
```{r cars}
summary(cars)
```
\question We can keep the pound signs.
\eQ
Here is the resulting output.
Output
I managed to get something working. It needs some libraries and uses knitr to create the output.
---
output:
pdf_document:
keep_tex: true
documentclass: exam
header-includes: \usepackage{float}
---
```{r setup, include=TRUE,echo=FALSE,message=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(knitr)
```
\begin{questions}
\question Answer question...
```{r, echo=F, comment=NA}
summary = iris %>% group_by(Species) %>% summarize(Total=n())
kable(summary, format='latex')
```
\end{questions}
The problem seems to be the inclusion of # in the output from R for processing by Latex. I avoid this by using kable.

RMarkdown Beamer TOC empty

Using beamer in RMarkdown for presentations, I can't figure out why the TOC is empty. I have tried using a MacBook and Windows.
---
title: "test"
author: "my name"
date: "12/6/2016"
output:
beamer_presentation:
keep_tex: true
toc: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Slide 1
Slide content
# Slide 2
Slide content
Outputs the pdf presentation with a title slide, an empty page (where the TOC should be), and then the two slides.
On Windows platform:
> R.version
platform x86_64-w64-mingw32
arch x86_64
os mingw32
system x86_64, mingw32
status
major 3
minor 3.1
year 2016
month 06
day 21
svn rev 70800
language R
version.string R version 3.3.1 (2016-06-21)
nickname Bug in Your Hair
RStudio:0.99.896
Rmarkdown: 1.2
knitr: 1.15.1
Somewhat related question here: Table of content in beamer generated with R markdown/knitr
Using the keep_tex: true argument in the YAML, I see from the tex file that the level 1 headers (i.e. # Section) are not being properly converted to sections in the tex file. For example, from the tex file:
\begin{frame}{Slide 1}
Slide content
\end{frame}
It seems that RMarkdown is not making the tex file correctly.
As pointed out here, the TOC will list the sections (as defined by single #'s), and the slide level must be a level below the sections (defined below in the YAML as slide_level: 2 and in the presentation by ##'s). I don't completely understand why you can't have sections at the slide level, but at least this works.
---
title: "test"
author: "my name"
date: "12/6/2016"
output:
beamer_presentation:
keep_tex: true
toc: true
slide_level:2
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
# Section 1
## Slide 1
Slide content
# Section 2
# Slide 2
Slide content

How to add an index to a PDF rendered from an Rmarkdown document using Rstudio on Windows?

The example document below is intended to include an index after the appendix. In a Sweave document, Rstudio would run a shell escape command to create the index .idx file, but I've not been able to find a way to do this for an Rmarkdown document. Is there a simple header command I'm missing?
---
title: "Untitled"
output:
pdf_document:
toc: yes
header-includes:
- \usepackage{makeidx}
- \makeindex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# R Markdown
This is an \index{R Markdown} R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
# Appendix - A
End of the document
\printindex
I've tried this from both the Knit button and using:
rmarkdown::render(rmd.file, output_format = "pdf_document", clean = FALSE)
I'm looking for a solution that can run as part of an automated process.
UPDATE:
I was able to get the index to work by changing the output type to bookdown::pdf_document2. The additional latex packages were required for a combination of indexing, cross referencing, and formatting.
---
title: "Untitled"
output:
bookdown::pdf_document2:
toc: no
geometry: margin=0.8in
header-includes:
- \usepackage{attachfile2}
- \usepackage{booktabs}
- \usepackage{caption}
- \usepackage{float}
- \usepackage[utf8]{inputenc}
- \usepackage{makeidx}
- \makeindex
- \usepackage{multirow}
- \usepackage{setspace}
- \usepackage{relsize}
- \usepackage[table]{xcolor}
- \setcounter{tocdepth}{5}
- \setcounter{secnumdepth}{0}
- \hypersetup{unicode=true,pdfusetitle,bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,breaklinks=false,backref=false,colorlinks=true,linkcolor=blue}
---
While this would work when manually pushing the create PDF button, the call to rmarkdown::render() still does not process the indexing.