检测显示数学的使用:\everydisplaymath{}

检测显示数学的使用:\everydisplaymath{}

我希望能够检测是否使用了显示数学环境:所以,寻找一个\everydisplaymath{}钩子。我并不关心是否$\displaystyle \frac{}{}计算了类似的东西。

在下面的 MWE 中,我使用 计算了显示数学环境的数量\everymath{},因此希望替换该行。

在此处输入图片描述

其他奇闻:

  • 看起来好像\[ \]没有检测到使用\everymath{}
  • 使用align*似乎已将计数增加了 4?

梅威瑟:

\documentclass{article}
\usepackage{amsmath}

\newcounter{DisplayMathUsedCounter}
\everymath{\stepcounter{DisplayMathUsedCounter}}%

\begin{document}
Display Math Used: \arabic{DisplayMathUsedCounter}

Inline math should not be counted $F = ma$

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 0)

\[
    E = mc^2
\]

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 1)
\begin{align*}
    F &= ma \\
    E &= mc^2
\end{align*}

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 2)

Ideally this should not be counted, but am ok if it is $\displaystyle \frac{1}{2}$

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 2 or 3)
\end{document}

答案1

你的意思是\everydisplay

\documentclass{article}
\usepackage{amsmath}

\newcounter{DisplayMathUsedCounter}
\everydisplay{\stepcounter{DisplayMathUsedCounter}}

\begin{document}

Display Math Used: \arabic{DisplayMathUsedCounter}

Inline math should not be counted $F = ma$

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 0)
\[
    E = mc^2
\]

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 1)
\begin{align*}
    F &= ma \\
    E &= mc^2
\end{align*}

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 2)

Ideally this should not be counted, but am ok if it is $\displaystyle \frac{1}{2}$

Display Math Used: \arabic{DisplayMathUsedCounter} (this should be reported as 2 or 3)

\end{document}

在此处输入图片描述

相关内容