繁体   English   中英

r-使用自定义LaTeX样式文件使用rmarkdown渲染PDF时出错

[英]r - error using custom LaTeX style file to render PDF using rmarkdown

基于user3143179的答案,我创建了custom.sty来指定字体和LaTeX包,以使用rmarkdown渲染PDF。

下面的custom.sty内容:

%  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

我使用fontspec手册来创建以上有关特定系统字体的代码。

我运行了以下R代码:

rmarkdown::render("custom.Rmd", pdf_document(highlight = "kate",
fig_caption = FALSE, latex_engine = "lualatex", keep_tex = TRUE, includes 
= includes(in_header = "custom.sty")))

这是运行R代码的输出:

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

错误

! 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

我也有原始的.tex文件,以防您也需要查看它。 .tex文件中有\\begin{document}

.sty文件中还需要其他哪些组件,以便使用rmarkdown将LaTeX文件正确呈现为PDF格式?

调用rmarkdown::render还有其他需要吗?

当我从custom.sty删除\\endinput时,它对我\\endinput 的问题是, includes就像\\include在TeX的字面输入该文件。 因此,将custom.sty重命名为header.tex更有意义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM