3

I want to automatically generate enumerated labels for enumerations in ConTeXt. However, I've tried the following and failed:

\definecounter[lol]
\incrementcounter[lol]\decrementcounter[lol]
\starttext
\incrementcounter[lol]
\placeformula[thm{\getnumber[lol]}]
\startformula
x^2+y^2=z^2
\stopformula
\placeformula[notatheorem]
\startformula
e^{i\pi}+1=0
\stopformula
\incrementcounter[lol]
\placeformula[thm{\getnumber[lol]}]
\startformula
\varphi = \frac{\sqrt{5}+1}{2}
\stopformula
I want to reference \in[thm1], \in[thm2] and \in[notatheorem]. Is that possible?
\stoptext

Is there any way to do it?

4

While you can refer to the counter in a way which works in references with the \rawcountervalue command there is a simpler counter mechanism which works without problem in your case.

I modified your example to use the \newcounter mechanism where you can access the value as argument for other commands without problems. The mechanism uses three main commands:

  • \newcounter\...
    • Create a new counter with the start value 0.
    • Reset the value of the counter because there is no dedicated reset command.
  • \increment\...
    • Increment the value of the counter by 1.
    • When you use braces as argument to the command you increment the counter by a specified amount, e.g. \increment(\...,3) increases the counter by 3.
  • \decrement\...
    • Decrement the counter value by 1
    • When you use braces as argument to the command you decrease the counter by a specified amount, e.g. \decrement(\...,2) decreases the counter by 2.

\newcounter\LolCounter
%\increment\LolCounter
%\decrement\LolCounter

\starttext

\increment\LolCounter
\startplaceformula[reference={thm\LolCounter}]
    \startformula
        x^2+y^2=z^2
    \stopformula
\stopplaceformula

\startplaceformula[reference={notatheorem}]
    \startformula
        e^{i\pi}+1=0
    \stopformula
\stopplaceformula

\increment\LolCounter
\startplaceformula[reference={thm\LolCounter}]
    \startformula
        \varphi = \frac{\sqrt{5}+1}{2}
    \stopformula
\stopplaceformula

I want to reference \in[thm1], \in[thm2] and \in[notatheorem]. Is that possible?

\stoptext
  • Wow, thank you very much! – JairoAraujo Sep 22 '19 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.