TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two counters, \definenumber[words] and \definenumber[items]. I have tried to use TeX conditionals to compare them, e.g.:

    This will print some text if the two counters have the same value.

This does not work. How can I use TeX conditionals to compare two counters in ConTeXt?

share|improve this question
up vote 8 down vote accepted

\definenumber is a synonym for \definestructurecounter. You can use the expandable version \rawstructurecountervalue to get the value of the structure counter and use them in TeX conditionals.

An alternative is to use the commands.doifelse(...) lua function to do the comparison. I present both versions below (using named arguments so that the macro is easy to understand. Either save this in a file with an extension .mkvi or use % macros=mkvi on the first line of the .tex file).

% macros=mkvi


    {\ctxcommand{doifelse(\rawstructurecountervalue[#counterA] #operator \rawstructurecountervalue[#counterB])}





  One is bigger
  Two is bigger

\doifelsecomparestructurecounter{>=}{one}{two}{Counter one is bigger}{Counter two is bigger}
\doifelsecomparestructurecounter{<}{one}{two}{Counter one is smaller}{Counter two is smaller}
\doifcomparestructurecounter{<}{one}{two}{Counter one is smaller}
\doifcomparestructurecounter{>}{one}{two}{Counter two is smaller}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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