[Tex/LaTex] LaTeX programming comparison operators

comparisonprogramming

The example for the forloop package is \newcounter{ct}\forloop{ct}{1}{\value{ct} < 5}{\arabic{ct}}. I need to compare two counters having the first run up to the second. <= doesnt work, neither does \leq or ...+1. I know I can solve it with \not or \or, but those are workarounds. How does it really work?

  1. Can I and if so how can I do a "real" <=?
  2. Can I and if so how can I use formulas (like \value{a}<\value{b}+1)?

Best Answer

  1. No. It is based on TeX's \ifnum, and only <, =, > is supported.

  2. Use eTeX primitive \numexpr:

    \newcounter{ct} \forloop{ct}{1}{\value{ct} < \numexpr\value{page}+10}{\arabic{ct} }
    

    Or you can use etoolbox package (looks awful for this simple bool expression, I agree):

    \newcounter{ct}
    \setcounter{ct}{1}
    \whileboolexpr{test {\ifnumcomp{\value{ct}}<{\value{page}+10}}}
      {\arabic{ct} \stepcounter{ct}}
    
Related Question