Below is my experimental RMarkdown document (named tikz-cyrillic.Rmd):
---
title: "TikZ cyrillic test"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
dev: tikz
html_document: default
word_document: default
---
```{r,engine='tikz', fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg'}
\begin{tikzpicture}
\path (0,0) node
(x) {Hello World!}
(3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
\draw[->,blue]
(x) -- (y);
\draw[->,red]
(x) -| node[near start,below] {мир!} (y);
\draw[->,orange] (x) .. controls +(up:1cm) and +(left:1cm) .. node[above,sloped] {Привет} (y);
\end{tikzpicture}
```
It is based on example from 17.11 of pgfmanual.pdf.
Gummi using TeXLive with XeTeX with simple preamble
\usepackage[main=russian,english]{babel}
\usepackage{fontspec}
\setmainfont[Ligatures={TeX,Historic}]{Times New Roman}
gives me the following output:
You can test it in OverLeaf.
But in RStudio I can't understand where should I enter preamble for TikZ device, so I have wrong output (HTML as example):
What should I change in RMarkdown document to get correct output in TikZ diagram?
I need the same image appearance for HTML, PDF and Word document (docx).
Note: I'm using Gummi and RStudio 1.1.456 on Ubuntu 16.04 LTS with TeXLive 2015 if it matters.
Configuring the knitr engine is possible, see e.g. https://stackoverflow.com/a/51143900/8416610 for references. Your case is different, since you need both PDF and SVG output. Since SVG output uses DVI, we cannot use xelatex for processing the tikz graphic. Instead we have to setup standard latex to output Cyrillic:
---
title: "TikZ cyrillic test"
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
html_document: default
mainfont: Liberation Serif
monofont: Liberation Mono
---
```{r,engine='tikz', fig.ext = if (knitr:::is_latex_output()) 'pdf' else 'svg', engine.opts = list(template = "tikz2pdf-cyr.tex")}
\begin{tikzpicture}
\path (0,0) node
(x) {Hello World!}
(3,1) node[circle,draw](y) {$\int_1^2 x \mathrm d x$};
\draw[->,blue]
(x) -- (y);
\draw[->,red]
(x) -| node[near start,below] {мир!} (y);
\draw[->,orange] (x) .. controls +(up:1cm) and +(left:1cm) .. node[above,sloped] {Привет} (y);
\end{tikzpicture}
```
With tikz2pdf-cyr.tex:
\documentclass{article}
\usepackage{libertine}
\usepackage[T2A]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[active,tightpage]{preview}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{preview}
%% TIKZ_CODE %%
\end{preview}
\end{document}
Note that here different fonts are used for the image and the main text. At the moment I cannot upload any screen shots ...
Related
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}
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.
I am using flextable to produce tables for a pdf document rendered with rmarkdwown. I want to cross-reference the tables, but they do not produce the label needed for the cross reference to work.
My Minimum Reproducible Example
What follows is the content of the file test.Rmd:
---
title: "document title"
author: "author here"
date: "2022-01-20"
output:
pdf_document:
fig_caption: yes
includes:
in_header: header.tex
number_sections: yes
toc: yes
toc_depth: 4
latex_engine: xelatex
keep_tex: true
---
```{r, include = FALSE}
library(flextable)
library(bookdown)
opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, out.width = "85%", fig.align = "center")
```
```{r, tab.id = "anyTable", tab.cap = "Invented data", tab.lp = "tab:"}
a = data.frame(id = LETTERS[1:3], x = 1:3)
flextable(a) |> theme_vanilla()
```
```{r secondTable}
b = data.frame(id = LETTERS[4:6], x = 4:6)
flextable(b) |> theme_vanilla() |> set_caption(caption = "This is secondTable")
```
# Standard rmarkdown crossreference
Trying anyTable: \ref{tab:anyTable}.
Trying secondTable: \ref{tab:secondTable}.
# Bookdown crossreference
Trying anyTable: \#ref(tab:anyTable).
Trying secondTable: \#ref(tab:secondTable).
Contents of header.tex:
\usepackage{caption}
\renewcommand{\contentsname}{Contenidos}
\captionsetup[table]{name=Tabla}
\captionsetup[figure]{name=Figura}
%\usepackage{float} #use the 'float' package
%\floatplacement{figure}{H}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{xcolor}
\usepackage{multicol}
\usepackage{pdflscape}
\newcommand{\blandscape}{\begin{landscape}}
\newcommand{\elandscape}{\end{landscape}}
When I do rmarkdown::render("test.Rmd", output_file = "test.pdf") the file is rendered in pdf, but the following warning comes out:
Output created: test.pdf
Warning message:
LaTeX Warning: Reference `tab:anyTable' on page 1 undefined on input line 198.
LaTeX Warning: Reference `tab:secondTable' on page 1 undefined on input line 20
0.
LaTeX Warning: There were undefined references.
If I check the .tex file, I can see that the captions are there, but they do not have the labels. The relevant lines of the intermediate test.tex file:
lines 106 to 109
\begin{longtable}[c]{|p{0.75in}|p{0.75in}}
\caption{Invented data
}\\
lines 153 to 156
\begin{longtable}[c]{|p{0.75in}|p{0.75in}}
\caption{This is secondTable
}\\
I expected that the caption line in the tex file was something like \caption{This is secondTable}\label{tab:secondTable}\\
What I've tried
Changing latex engines (lualatex, pdflatex, xelatex).
Editing the tex file (adding the label after the caption), but it fails to convert to dvi with multiple errors (mostly "undefined control sequence")
What am I doing wrong?
How can I cross-reference the tables produced by flextable?
Alternatively, I am open to other packages you may suggest. As some of the headers in my real data are somewhat complex (multi-span headers and the like), I would like to steer away from kable and kableExtra if at all possible.
You need to use a format from bookdown to get cross references, see https://bookdown.org/yihui/rmarkdown-cookbook/cross-ref.html
---
title: "document title"
author: "author here"
date: "2022-01-20"
output:
bookdown::pdf_document2:
fig_caption: yes
number_sections: yes
toc: yes
toc_depth: 4
latex_engine: xelatex
keep_tex: true
---
```{r, include = FALSE}
library(flextable)
library(knitr)
library(bookdown)
opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, out.width = "85%", fig.align = "center")
```
```{r, tab.id = "anyTable", tab.cap = "Invented data"}
a = data.frame(id = LETTERS[1:3], x = 1:3)
flextable(a) |> theme_vanilla()
```
```{r secondTable}
b = data.frame(id = LETTERS[4:6], x = 4:6)
flextable(b) |> theme_vanilla() |> set_caption(caption = "This is secondTable")
```
# Bookdown crossreference
Trying anyTable: \#ref(tab:anyTable).
Trying secondTable: \#ref(tab:secondTable).
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
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