
我剛剛收到.tex
一位同事寄來的文件,該文件有幾個\rm
數學模式的命令。我們都使用 Windows,但他使用 WinEdt,我使用 TeXmaker。在他的電腦上,該檔案的編譯沒有錯誤,但在我的筆記本上,我收到錯誤訊息,指出\rm
這是一個未定義的命令。到底是怎麼回事?
非常感謝。
答案1
\rm
Latex 格式中沒有定義。一些類別定義它是為了與 LaTeX 2.09(即 1993 年之前編寫的文檔)相容。 Koma 類別之前定義它時帶有警告,但最近的版本沒有定義它,因此如果使用它,您會收到錯誤。
經過 20 年的棄用之後,scrartcl
作者認為不再需要它並非沒有道理。
您用來編寫檔案的編輯器(winedt、texmaker 等)對此完全沒有影響。
答案2
您使用的編輯器無關緊要。重要的是scrartcl
您使用的是哪個年份的葡萄酒。直到最近(2016 年 6 月),KOMA 腳本文檔類別 -- scrartcl
、scrreprt
和scrbook
--有點容忍已棄用的字體切換指令\rm
、\bf
、\it
等,同時在遇到這些指令時發出大量警告訊息。然而,2016 年 6 月,KOMA-Script 類別中對這些指令的支援完全停止。
如果你真的、積極地、絕對地必須使用\rm
和其他已棄用的字體切換指令,您可以將以下程式碼(直接從其提升article.cls
)添加到序言中:
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
請注意,\sl
和\sc
只能在文字模式下工作,但是不是在數學模式下。看這個帖子有關此主題的更多資訊。
完整的 MWE:
\documentclass{scrartcl}
% The following code is from the file `article.cls`
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\begin{document}
$a$ $\it a$ $\rm a$ $\bf a$ $\sf a$ $\tt a$
\end{document}