commath 和 \ifinner

commath 和 \ifinner

commath包使用 TeX 命令\ifinner在内联数学模式和显示数学模式之间进行选择。因此,它无法在某些显示数学环境中正常工作。

breqn 包中,我们发现:

该测试\ifinner无法可靠地区分我们是处于显示公式中还是内联公式中:(...) 因此,我们提供了更可靠的测试。但它可能已由 amsmath 包提供。

更可靠的测试应该是\if@display但只能替换\ifinner\if@display不起作用commath.sty。有什么建议吗?

答案1

让我们看看commath应该如何定义它的宏。

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}

%%% Here start the definitions
\newcommand{\dif}{\mathop{}\!\mathrm{d}}
\newcommand{\Dif}{\mathop{}\!\mathrm{D}}

\makeatletter
\newcommand{\spx}[1]{%
  \if\relax\detokenize{#1}\relax
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {^{#1}}%
}
\makeatother

\newcommand\pd[3][]{\frac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\newcommand\tpd[3][]{\tfrac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\newcommand\dpd[3][]{\dfrac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}

\newcommand{\md}[6]{\frac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}
\newcommand{\tmd}[6]{\tfrac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}
\newcommand{\dmd}[6]{\dfrac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}

\newcommand{\od}[3][]{\frac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}
\newcommand{\tod}[3][]{\tfrac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}
\newcommand{\dod}[3][]{\dfrac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}

\newcommand{\genericdel}[4]{%
  \ifcase#3\relax
  \ifx#1.\else#1\fi#4\ifx#2.\else#2\fi\or
  \bigl#1#4\bigr#2\or
  \Bigl#1#4\Bigr#2\or
  \biggl#1#4\biggr#2\or
  \Biggl#1#4\Biggr#2\else
  \left#1#4\right#2\fi
}
\newcommand{\del}[2][-1]{\genericdel(){#1}{#2}}
\newcommand{\set}[2][-1]{\genericdel\{\}{#1}{#2}}
\let\cbr\set
\newcommand{\sbr}[2][-1]{\genericdel[]{#1}{#2}}
\let\intoo\del
\let\intcc\sbr
\newcommand{\intoc}[2][-1]{\genericdel(]{#1}{#2}}
\newcommand{\intco}[2][-1]{\genericdel[){#1}{#2}}
\newcommand{\eval}[2][-1]{\genericdel.|{#1}{#2}}
\newcommand{\envert}[2][-1]{\genericdel||{#1}{#2}}
\let\abs\envert
\newcommand{\sVert}[1][0]{%
  \ifcase#1\relax
  \rvert\or\bigr|\or\Bigr|\or\biggr|\or\Biggr
  \fi
}
\newcommand{\enVert}[2][-1]{\genericdel\|\|{#1}{#2}}
\let\norm\enVert
\newcommand{\fullfunction}[5]{%
  \begin{array}{@{}r@{}r@{}c@{}l@{}}
  #1 \colon & #2 & {}\longrightarrow{} & #3 \\
            & #4 & {}\longmapsto{}     & #5
  \end{array}
}
%%% end of the definitions

\linespread{2} % just for this test file

\begin{document}

$f(x)\dif x\quad f(x)\Dif x$

$\pd{f}{x}\displaystyle\pd[2]{f}{x}$

$\tpd{f}{x}\displaystyle\tpd[2]{f}{x}$

$\dpd{f}{x}\displaystyle\dpd[2]{f}{x}$

$\od{f}{x}\displaystyle\od[2]{f}{x}$

$\tod{f}{x}\displaystyle\tod[2]{f}{x}$

$\dod{f}{x}\displaystyle\dod[2]{f}{x}$

$\md{f}{5}{x}{2}{y}{3}\displaystyle\md{f}{5}{x}{2}{y}{3}$

$\tmd{f}{5}{x}{2}{y}{3}\displaystyle\tmd{f}{5}{x}{2}{y}{3}$

$\dmd{f}{5}{x}{2}{y}{3}\displaystyle\dmd{f}{5}{x}{2}{y}{3}$

$\del{\dfrac{1}{2}}\del[0]{x}\del[1]{x}\del[2]{x}\del[3]{x}\del[4]{x}$

$\sbr{\dfrac{1}{2}}\sbr[0]{x}\sbr[1]{x}\sbr[2]{x}\sbr[3]{x}\sbr[4]{x}$

$\set{\dfrac{1}{2}}\set[0]{x}\set[1]{x}\set[2]{x}\set[3]{x}\set[4]{x}$

$\intoo{a,b}\intoo[0]{a,b}\intoo[1]{a,b}\intoo[2]{a,b}\intoo[3]{a,b}\intoo[4]{a,b}$

$\intcc{a,b}\intcc[0]{a,b}\intcc[1]{a,b}\intcc[2]{a,b}\intcc[3]{a,b}\intcc[4]{a,b}$

$\intoc{a,b}\intoc[0]{a,b}\intoc[1]{a,b}\intoc[2]{a,b}\intoc[3]{a,b}\intoc[4]{a,b}$

$\intco{a,b}\intco[0]{a,b}\intco[1]{a,b}\intco[2]{a,b}\intco[3]{a,b}\intco[4]{a,b}$

$
\eval{f(x)}_a^b
\eval[0]{f(x)}_a^b
\eval[1]{f(x)}_a^b
\eval[2]{f(x)}_a^b
\eval[3]{f(x)}_a^b
\eval[4]{f(x)}_a^b
$

$\abs{x}\abs[0]{x}\abs[1]{x}\abs[2]{x}\abs[3]{x}\abs[4]{x}$

$\norm{x}\norm[0]{x}\norm[1]{x}\norm[2]{x}\norm[3]{x}\norm[4]{x}$

\linespread{1}\selectfont % return to normal

$\fullfunction{f}{A}{B}{x}{y}$
\end{document}

我省略了那些\...ref更容易管理的宏cleveref

正如您所见,它只是一些有用但值得怀疑的宏的集合。

主要错误:和commath的定义明显错误。 的使用完全错误;作者想要用和做的事情,标准宏已经(更好地)做到了。\dif\Dif\ifinner\ifinner\tfrac\dfrac\frac

“分隔符”宏是错误的,因为它们默认使用\left\right,这是有争议的;我将它们保留在原始状态,但根据通用宏来定义它们。

在此处输入图片描述

相关内容