如何解决更新 MikTex 后,LearnR Rmd knit to pdf 无法编译
在我将 MikTex 更新到最新版本后,我的 Rmd 文件不再编译。我安装了 tinytex,多次重新安装了 miktex、R 和 RStudio。我在包含在 Rmd 文件中的 tex 文档中使用了一些新命令,如 \C、\G 等。我使用 Windows 10,最新版本的 R、RStudio 和 Miktex。
我也请一位同事(没有编译问题)更新他的 MikTex。更新他的 MikTex 后,他遇到了同样的问题。
这是 Rmd 代码:
---
documentclass: scrartcl
fontsize: 11pt
output:
pdf_document:
includes:
in_header: commands.tex
---
This is an example:
\begin{itemize}
\item hello
\item world
\end{itemize}
这里是tex代码:
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{icomma}
\usepackage[right,official]{eurosym}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage[shortlabels]{enumitem}
\usepackage{setspace}
\singlespacing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Seitenformat und Layoutparameter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hbadness=1000
\tolerance=10000
\voffset-2.80cm
\hoffset-2.60cm
\topmargin1.50cm
\headheight0.65cm
\headsep1.0cm
\topskip0cm
\textheight24.00cm
\footskip1.5cm
\footnotesep11pt
\evensidemargin2.50cm
\oddsidemargin2.50cm
\textwidth16cm
%\parindent0cm
%\parskip1.5ex plus0.5ex minus 0.5ex
% simple letters
\newcommand{\A}{{\mathbb A}}
\newcommand{\B}{{\mathbb B}}
\renewcommand{\C}{{\mathbb C}}
\newcommand{\D}{{\mathbb D}}
\newcommand{\E}{{\mathbb E}}
我得到:
处理文件:example1.Rmd |................................................................ …………| 100% 没有R代码的普通文本
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS example1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output example1.tex --lua -filter "C:\Users\saski\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\saski\Documents\R\win-library \4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --include-in-header commands.tex --variable graphics 输出文件:example1.knit.md
! LaTeX 错误:命令 \C 未定义。
Fehler:LaTeX 无法编译 example1.tex。有关调试提示,请参阅 https://yihui.org/tinytex/r/#debugging。有关更多信息,请参见 example1.log。 Ausführung angehalten
解决方法
最好的解决方案是避免使用一个字母的宏名称
您的代码不再有效,因为 \C
现在仅在某些情况下由 hyperref 定义,有关详细信息,请参阅 https://tex.stackexchange.com/questions/582625/command-c-already-defined-and-the-hyperref-package/582630#582630
如果您使用 \newcommand
而不是 \renewcommand
,您可以看到错误消失了
% simple letters
\newcommand{\A}{{\mathbb A}}
\newcommand{\B}{{\mathbb B}}
\newcommand{\C}{{\mathbb C}}
\newcommand{\D}{{\mathbb D}}
\newcommand{\E}{{\mathbb E}}
(但你仍然不应该这样做,如果是一个字母名称,请使用其他一些宏名称)
结论:不要使用一个字母的宏名称
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。