【问题标题】:LearnR Rmd knit to pdf failed to compile after update of MikTex更新 MikTex 后 LearnR Rmd knit to pdf 无法编译
【发布时间】:2021-07-13 17:51:06
【问题描述】:

在我将 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。 安然无恙

【问题讨论】:

  • 我的猜测是一个或多个正在加载的乳胶包没有安装。手动安装它们或确保已设置 miktex/tinytex 以便它们自动安装软件包。
  • @Till 错误看起来会有所不同,类似于! LaTeX Error: File filename.sty not found.
  • 谢谢!当我删除一个字母的新命令时它可以工作

标签: r command latex learnr


【解决方案1】:

最好的解决方案是避免使用一个字母的宏名称


您的代码不再有效,因为 \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}}

(但你仍然不应该这样做,如果是一个字母名称,请使用其他一些宏名称)


结论:不要使用一个字母的宏名

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-08
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2021-05-16
    • 1970-01-01
    • 2017-03-20
    • 1970-01-01
    相关资源
    最近更新 更多