1

I would like to be able to detect if a display math environment was used: So, looking for a \everydisplaymath{} hook. Am not bothered if something like $\displaystyle \frac{}{} is counted or not.

In the MWE below I count the number of display math environments using \everymath{}, so looking to replace that line.

enter image description here

Other Curiosities:

  • It looks like the use \[ \] was not detected by \everymath{}?
  • Using align* seems to have incremented the count by 4?

MWE:

\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}
0

1 Answer 1

1

You mean \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}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .