Reputation: 944
Based off of the answser by user3143179, I created custom.sty to specify both the fonts and LaTeX packages to use to render a PDF with rmarkdown
.
Content of custom.sty below:
% custom.sty
\usepackage{sectsty} \sectionfont{\centering} \chaptertitlefont{\centering}
\usepackage{xcolor}
% fonts
\usepackage{fontspec}
\setmainfont{LiberationSerif-Regular.ttf}[
BoldFont = LiberationSerif-Bold.ttf,
ItalicFont = LiberationSerif-Italic.ttf,
BoldItalicFont = LiberationSerif-BoldItalic.ttf ]
\setsansfont{LiberationSans-Regular.ttf}[
BoldFont = LiberationSans-Bold.ttf,
ItalicFont = LiberationSans-Italic.ttf,
BoldItalicFont = LiberationSans-BoldItalic.ttf ]
\setmonofont{LiberationMono-Regular.ttf}[
BoldFont = LiberationMono-Bold.ttf,
ItalicFont = LiberationMono-Italic.ttf,
BoldItalicFont = LiberationMono-BoldItalic.ttf ]
\endinput
I used the fontspec manual to create the code above with regards to the specific system fonts.
I ran the following R code:
rmarkdown::render("custom.Rmd", pdf_document(highlight = "kate",
fig_caption = FALSE, latex_engine = "lualatex", keep_tex = TRUE, includes
= includes(in_header = "custom.sty")))
This is the output from running the R code:
processing file: custom.Rmd
|.................................................................| 100%
ordinary text without R code
output file: custom.knit.md
/usr/bin/pandoc +RTS -K512m -RTS custom.utf8.md --to latex
--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output custom.tex --template /rmarkdown/rmd/latex/default.tex --highlight-style kate
--latex-engine lualatex --include-in-header custom.sty --variable graphics=yes
/usr/bin/pandoc +RTS -K512m -RTS custom.utf8.md --to latex
--from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures
--output custom.pdf --template /rmarkdown/rmd/latex/default.tex --highlight-style kate
--latex-engine lualatex --include-in-header custom.sty --variable graphics=yes
Error
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.95 \setmainfont{LiberationSerif-Regular.ttf}[
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
I also have the raw .tex file in case you need to review it as well. There is \begin{document}
in the .tex file.
What other component(s) are needed in the .sty file so that the LaTeX file is properly rendered into PDF format using rmarkdown?
Is there anything else needed in the call to rmarkdown::render
?
Upvotes: 0
Views: 1151
Reputation: 26843
It works for me when I remove the \endinput
from custom.sty
. Problem is that includes
just like \include
in TeX inputs the file literally. So it makes more sense to rename custom.sty
to header.tex
.
Upvotes: 1