3

I have seen the commands \pushQED and \popQED used in quite a few examples, many connected with the amsthm proof environment, but I cannot find any documentation explaining what they actually do or why you would need them. What do they do?

  • 1
    Looks like https://tex.stackexchange.com/a/491666/250119 has some explanation, but documentation indeed looks sparse. amsclass source code documentation just has this much explanation. – user202729 Apr 17 '23 at 23:20
  • @user202729 -- While that is the exact description given in amsclass.pdf, looking there for where and how the two commands are used is also instructive. (Briefly, the intent is to make it possible to place a qed symbol at the end of the last line of an equation or a nested list, when that ends a proof, rather than on the next line by itself.) – barbara beeton Apr 18 '23 at 00:40

1 Answers1

2

The basic purpose of \pushQED and \popQED is to ensure that when \qedhere is used, no QED symbol will appear at \end{proof}.

This also allows nested proofs, which is why a stack is used.

\documentclass{article}
\usepackage{amsthm}

\newenvironment{innerproof}{% \renewcommand{\qedsymbol}{\ensuremath{\clubsuit}}% \proof[Inner proof] }{\endproof}

\makeatletter \AddToHook{cmd/endproof/before}{% \expandafter\typeout\expandafter{\detokenize\expandafter{\QED@stack}}% } \makeatother

\begin{document}

\begin{proof} This is a standard proof. \end{proof}

\begin{proof} This is a standard proof ending with an equation [ 1=1. \qedhere ] \end{proof}

\begin{proof} This proof has inner proofs inside it.

\begin{innerproof} This has only text. \end{innerproof}

Some text in between.

\begin{innerproof} This ends with an equation [ 0=0. \qedhere ] \end{innerproof}

Some final text. \end{proof}

\end{document}

The \AddToHook business is just for debugging, so we can see the stack at each call of \endproof. In the console (and log file) you'll see

\qed@elt {\qed }
\qed@elt {}
\qed@elt {\qed }\qed@elt {\qed }
\qed@elt {}\qed@elt {\qed }
\qed@elt {\qed }

This shows that when \qedhere is used, the top item in the stack, when \endproof is about to be executed, contains \qed@elt{}, so no \qed command is performed, because \qedhere has been found in the same environment. Basically, \qedhere replaces \qed@elt{\qed} as the top item in the stack with \qed@elt{}.

enter image description here

egreg
  • 1,121,712
  • Thank you for a very clearly written example, though your example doesn't use \pushQED or \popQED anywhere, so I'm still not sure when they're needed. – Joel Croteau Apr 18 '23 at 22:14
  • 1
    @JoelCroteau They're used by \proof and \endproof. You can use them if you want the same behavior without using the proof environment; often it's asked for exercises. – egreg Apr 18 '23 at 22:52