什么时候真正需要 \ensuremath ?

什么时候真正需要 \ensuremath ?

一个相当流行的问题是 何时不应使用 \ensuremath 作为数学宏?那里的一些好答案解释了为什么\ensuremath经常被过度使用。egreg 有一个“\ensuremath仅在真正需要时才使用”的活动。

我的问题是: 什么时候才真正\ensuremath需要?


例如,我自己倾向于(可能过于热衷)使用具有局部作用域的宏,*而我这样做的方式会\ensuremath在我的 LaTeX 中产生很多问题。我的借口是宏的作用域很小,我想这可以节省“一些输入”。我通过使用\funS~and而不是 来节省了 1 个字符,而不是 2 个字符$\funS$~and

当然,这似乎不是一个\ensuremath地方真的需要——尽管我喜欢我的设置——所以我要求提供证据来证明 egreg 的活动是“\ensuremath仅在真正需要时”而不是“\ensuremath根本不需要”:)

% ...
% New Math Symbol
\newcommand*{\nms}[1]{\ensuremath{#1}}

% Terminology
\newcommand*{\termino}[1]{\emph{#1}}

% #1: #2 -> #3
\newcommand*{\morphism}[3]{#1\colon#2\to#3}

% Formatting for mathematical object types
\newcommand*{\category}[1]{\mathcal{#1}}
\newcommand*{\functor}[1]{#1}
% ...
\begin{document}
% Some stuff in my document.
% ...
{
    \nms{\catA}{\category{A}}
    \nms{\catB}{\category{B}}
    \nms{\catC}{\category{C}}
    \nms{\funS}{\functor{S}}
    \nms{\funT}{\functor{T}}
    We now have the following generic theorem I am using for this example:
    \begin{theorem}
        Let \(
            \morphism{\funS}{\catA}{\catB}
        \) and~\(
            \morphism{\funT}{\catB}{\catC}
        \) be functors between three categories.
        Then the \termino{composition} of the functors \funS~and~\funT\
        is a functor~\(
            \morphism{\funT\funS}{\catA}{\catC}
        \).
    \end{theorem}
    \begin{proof}
        The nonsense proof of the dull theorem above begins.
        The important part about it is that we can use
        the local commands referring to the mathematical objects
        we are manipulating in this context,
        for example \catC\ or~\funT.
    \end{proof}
}
% ...
% Some more stuff in my document,
% fortunately not polluted by local commands.
\end{document}

[*] 为什么我看到使用本地宏的人这么少?这是不好的做法吗?也许我应该就此发表一个单独的问题,因为它有点偏离主题。

相关内容