I use amsthm. All theorem-like environments use a common counter. As I have some very long proofs I want to add the theorem number to which the proof refers at the end of proof just next to the box/square/qed mark.

Renewing command \qedsymbol like this:


works almost fine. The only problem is that if there is some fact or lemma inside my proof,


then the number by \qed is this fact's number instead of the theorem number.

I was disappointed because looking at the proof definition in amsthm.sty file

  \normalfont \topsep6\p@\@plus6\p@\relax

I can see that the qed is handled somehow and put on some stack when the environment is being initialized, then it is just popped. So it could remember the original theorem number.

I suspect that my problem is caused by fact that evaluation of my \qedsymbol is postponed until the proof environment is getting closed.

Is there a way to force it to evaluate it somewhere around \pushQED{\qed}%?

Or maybe someone could explain what is actually going on in these lines so that I could fiddle with it myself?:

  \begingroup\let\qed@elt\popQED@elt \QED@stack\relax\relax\endgroup

My most advanced idea was


but it didn't work as well.


2 Answers 2


why not take advantage of the \label facility? for example:





This is a theorem.

This is the proof.


this method doesn't require a single counter for everything. that means, for example, that proofs can be in an order different from the order of theorems. or a variation on the above code could be constructed allowing the post-tombstone insertion to include a fuller identification of what's being proved, say "Theorem m" or "Lemma n". (construction is left as an exercise.)

  • Thank you. This is not exactly what I'm looking for but quite interesting workaround.
    – misiek
    Nov 29, 2011 at 20:49

It seems that you have something like


Then, after \begin{fact}...\end{fact} the theorem counter will be stepped and \arabic{theorem} will become the number assigned to fact.

You can use \pushQED, but redefining it:


The purpose of \begingroup and \endgroup is just not leaving a defined \x around.

  • Thank you for the answer. It works however I'd love to achieve this only touching \qedsymbol. Do you think this is impossible? I tried something similar to your solution \let\ORIqedsymbol\qedsymbol \def\qedsymbol{\edef\x{\ORIqedsymbol~\arabic{theorem}}\x} but it doesnt work. Could you point out where is the magic in your code that make it work? I see you use some commands to postpone some expansion. My intuition would be to use something like \expand instead of \noexpand. What am I missing?
    – misiek
    Nov 29, 2011 at 20:37
  • Btw. your code works even if I replace \unexpanded{#1}\noexpand simply by #1. Are these two commands redundant?
    – misiek
    Nov 29, 2011 at 20:46
  • No, you can't act only on \qedsymbol, because its expansion happens only when the symbol has to be printed and it's too late for accessing at the correct theorem number. Your intuition about \expand is wrong.
    – egreg
    Nov 29, 2011 at 22:12

You must log in to answer this question.

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