If-Conditions and Counter Value Comparisons in LaTeX

1,103 views
Skip to first unread message

afuchs

unread,
Mar 5, 2008, 7:45:33 AM3/5/08
to LaTeX Users Group
Dear LaTeX-Lovers,

I am a student of linguistics with a rather formidable programming
experience.
I started using LaTeX very recently and enjoy the possibilities it
opens for me.

Now and then I am trying to solve problems on a programming level
rather intuitively, as I do not know anything about LaTeX programming.
So I search here and there (that's how I found this board) and usually
the problem is solved without active interference of other users. Not
this time, though.

I am trying to change my output formatting based on a value of a
counter I have defined. I need therefore to check and compare its
value to a given one.
I am using the intuitive \if{...} \then{...} \else{...} \fi structure,
but cannot get the condition \if{\value{my_counter}>9} work in a non-
trivial way.
What do I miss in the syntax of that expression? The ">"? The numeric
value?

Do you consider the whole enterprise inelegant? Should such thing be
taken out of a .tex file and into some other structure?

Thank you very much,
Alexey

Werner Grundlingh

unread,
Mar 5, 2008, 11:27:08 AM3/5/08
to LaTeX Users Group
Alexey,

The use of your commands are well justified. However, the primitives
are more often used in plain TeX than in LaTeX. Consequently, I think
you'd be interested in the xifthen package, available via CTAN from
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=xifthen
As stated in the package documentation, it adequately allows for the
kind of conditional constructs you require:
\ifthenelse{<test expression>}{<true code>}{<false code>}
where <test expression>, in terms of integers (or counters for that
matter), may include all the regular comparison tests. You will also
notice that it allows for calc-like comparisons for counters (the calc
package is also available via CTAN from
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=calc). Just
read the complete documentation to understand the availabilities.

Hope this helps,
Werner

afuchs

unread,
Mar 6, 2008, 5:32:52 AM3/6/08
to LaTeX Users Group
Werner,

Thank you very much.
I guess then that no numeric comparisons are possible in a standard
LaTeX if-clause.
The xifthen functionality helped to solve the problem.

Alexey
> package is also available via CTAN fromhttp://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=calc). Just

James McElhannon

unread,
Mar 6, 2008, 7:45:29 AM3/6/08
to Latex Lovers
Hi guys,
 
Is there a way to get LaTeX to number paragraphs?  I would like the numbers to appear in the outside margin (book layout of course).  I am using Memoir as my base class.
 
Thanks
James


Shed those extra pounds with MSN and The Biggest Loser! Learn more.

Werner Grundlingh

unread,
Mar 6, 2008, 11:33:13 AM3/6/08
to LaTeX Users Group
On Mar 6, 4:45 am, James McElhannon <james_mcelhan...@hotmail.com>
wrote:
> Hi guys,
>
> Is there a way to get LaTeX to number paragraphs?  I would like the numbers to appear in the outside margin (book layout of course).  I am using Memoir as my base class.
>
> Thanks
> James
> _________________________________________________________________
> Shed those extra pounds with MSN and The Biggest Loser!http://biggestloser.msn.com/

Yip, do a search through Google for numberpar - apparently there's no
formal package on CTAN that is supported. Code for this has been
modified through the years and it may therefore still be somewhat
unreliable, depending on the specific use. I found this link to
numberpar.sty
http://mechanics.civil.tohoku.ac.jp/~bear/bear-collections/style-files/numberpar.sty

Hope this helps,
Werner
Reply all
Reply to author
Forward
0 new messages