Problems related to custom AMS theorem module

Rudi Gaelzer rgaelzer at
Fri Jul 23 20:14:38 UTC 2021

On sexta-feira, 23 de julho de 2021 14:40:38 -03 Paul A. Rubin wrote:
> I've never used the totcount package, so this may be a bit naive. For the
> first issue, can you set the relevant counters (equation at totc) etc. to zero
> with a \setcounter command in the preamble of the first document and, if
> so, will that zero value get written to the file if no environments of the
> type counted appear in the document? That would (hopefully) give you a
> starting value for the next document.

I thought about doing something similar, but not exactly as you suggested. 
With the totcount package, you register the counters you'll want to keep track of with the 
It will create the counter thm at totc and set it to zero.  At the end of the run, the counter is 
written into  I need to inform this file name to the next lecture.
So, inside the InPreamble, I registered all theorem counters.
Two problems resulted:
1. I got a lot of "!Missing number, treated as zero" errors.  
2. If I ignore the errors and finish the processing, the total counters of the environs that 
are NOT used in the document are written in, all set to zero, as expected.  
The problem is that the counters that ARE used are again incremented every time the file 
is processed until all cross-references are right.
This time, I inserted the \setcounter{defn}{\totvalue{defn}}
command in the *.inc file.

> For the second issue, can you wrap your preamble code in AtBeginDocument{}
> and, if so, does that allow ams-theorem to load first and your code to
> execute correctly?

That seems to work.  Thanks for pointing out the command.
So, I inserted 
\regtotcounter[auxfile=\]{thm}, etc
in the  appropriate places in the *.inc file.  The command \currfilebase comes from the 
currfile package.  It just contains the base file name, without the extension.
And then, if I know that in the next lecture the Definition and Exercise environs are used, 
inserting in the InPreamble

	\setcounter{xca}{\totvalue{xca}} }

does the trick.  The counters are set after all the rest of the preamble is processed.

Thank you.

Incidentally, in order to create locally the *.aux and *.tc files needed for cross-referencing, 
I have to first export the document to LaTeX and then manually run 
pdflatex --draftmode <doc>

Is there a way to instruct Lyx to write certain auxiliary files into the local directory, instead 
of in /tmp/lyx_tmpdirxxx?
Rudi Gaelzer
Institute of Physics
Federal University of Rio Grande do Sul
Registered linux user # 153741
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the lyx-users mailing list