I know that
amsmath typesets at least twice its material, the first one for measurement and that it takes measures (sic) to avoid some counters being updated twice.
Is there a switch a macro writer could use to inform LaTeX not to update counters (which are global in LaTeX) when it is needed to typeset some unknown contents
#1 inside a box, which will be discarded later?
update from info gathered from
egreg's answer and a (belated) look in the sources. It is not as I said above that
amsmath avoids for some counters to be updated; it avoids it for all, because it uses a list of all counter names which is kept up-to-date by the latex kernel, and designed to allow anyone using it to do things with all these names. The conclusion is thus that
amsmath defines the macro pair
\savecounters@/\restorecounters@ because it needs the functionality, but that anyone can copy their definitions (
\savecounters@ defines what
\restorecounters@ will do) and use them with the same effect without having to load
amsmath or even any portion of it. Just replace