\SetMathAlphabet 與 \rm 混淆

\SetMathAlphabet 與 \rm 混淆

請考慮以下最小範例:

\documentclass{article}
\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{\rmdefault}{m}{n}%

\begin{document}
\parindent0pt
X$\rm -1$\\
X$\rm -1$\\
X$\rm -1$

\end{document}

這會產生以下 dvi 輸出 (Texlive2019):

編譯後的MWE的螢幕截圖

為什麼第一行中的減號像二元運算子一樣間隔,但在所有後續行中像一元運算子一樣間隔?

(而且我知道我不應該使用純文字字體開關;這段程式碼被簡化以顯示核心問題,並且是一個更大的樣式表的一部分,該樣式表可以追溯到2008 年並且必須向後相容,所以我可以' t省略\rmX$-1$

答案1

您可以嘗試新增修復程序https://github.com/latex3/latex2e/commit/06692e這解決了www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/3357

\documentclass{article}
\usepackage{etoolbox}

\makeatletter
\patchcmd\document@select@group{#1{#4}}{\expandafter#1\ifx\math@bgroup\bgroup{#4}\else#4\fi}{}{\fail}
\makeatother

\SetMathAlphabet{\mathrm}{normal}{\encodingdefault}{\rmdefault}{m}{n}%
\begin{document}
\parindent0pt
X$\rm -1$\\
X$\rm -1$\\
X$\rm -1$


\end{document}

相關內容