r-使用自定义LaTeX样式文件通过rmarkdown渲染PDF时出错 [英] r - error using custom LaTeX style file to render PDF using rmarkdown

查看:421
本文介绍了r-使用自定义LaTeX样式文件通过rmarkdown渲染PDF时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于user3143179的答案 ,我创建了custom.sty以同时指定用于使用rmarkdown呈现PDF的字体和LaTeX包.

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.

以下 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手册来创建上述有关特定系统字体的代码.

I used the fontspec manual to create the code above with regards to the specific system fonts.

我运行了以下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代码的输出:

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

错误

! 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}.

I also have the raw .tex file in case you need to review it as well. There is \begin{document} in the .tex file.

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

What other component(s) are needed in the .sty file so that the LaTeX file is properly rendered into PDF format using rmarkdown?

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

Is there anything else needed in the call to rmarkdown::render?

推荐答案

当我从custom.sty中删除\endinput时,它对我有用.问题是includes就像TeX中的\include一样直接输入文件.因此,将custom.sty重命名为header.tex更有意义.

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.

这篇关于r-使用自定义LaTeX样式文件通过rmarkdown渲染PDF时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆