A puzzle with TeX \ifnum

Isaiah Shavitt shavitt at chemistry.ohio-state.edu
Tue Oct 5 23:07:37 CEST 1999


-----------------------------------------------------------------------------
This is the PSTricks mailing list, devoted to discussions about computational
graphics in (La)TeX using the PSTricks package from Timothy van Zandt.
For help using this mailing list, see instructions at the end of message.
-----------------------------------------------------------------------------

Thank you for your response.  Actually, I did try 

 	\ifdim\ylen<0pt\pssetlength{\ylen}{-\ylen}\fi

and also 

 	\ifdim\ylen<\z@\pssetlength{\ylen}{-\ylen}\fi

(with the appropriate declarations preceding, and with the correct 
setting for the @ catcode) and neither worked.  When I put in 
\typeout{\the\ylen} after the test, nothing was output and the 
\pssetlength was never executed.  But when I added another
\typeout{\the\ylen} *before* the test, the macro did work.  The 
complete code section that worked is:

\pssetlength{\ylen}{#3}\psaddtolength{\ylen}{-#2}
\typeout{\the\ylen}
\ifdim\ylen<\z@\typeout{\the\ylen}\pssetlength{\ylen}{-\ylen}\fi

(a \newlength{\ylen} declaration had appeared earlier}.  The values 
of \ylen were listed correctly, and the resetting of \ylen occurred.
But if I left out the second line in the above 3-line segment, the 
\pssetlength statement in the third line was never executed.

At 10:34 AM 10/5/99 +0200, Denis Girou wrote:
>>>>>> "Isaiah.Shavitt" == Isaiah Shavitt <shavitt at chemistry.ohio-state.edu> 
>writes:
>
>> Can somebody tell me why
>>
>> 	\ifnum\ylen>0\else\pssetlength{\ylen}{-\ylen}\fi
>>
>> works (forcing \ylen to be positive), while
>>
>> 	\ifnum\ylen<0 \pssetlength{\ylen}{-\ylen}\fi
>>
>> does not?  It does not work even if I put \relax after the <0, 
>> or put the \pssetlength command in braces, or try a few other 
>> variations.  The \pssetlength command is just not executed.
>> Or is there a better way to get the absolute value of \ylen 
>> without using PS code?
>
>  The \ifnum macro allow the comparison of two integers, but here you want to
>compare lengths (or dimensions). You obviously must have declare \ylen with
>\newlength if you use LaTeX or with \newdimen if you use plain.
>
>  So you must use the \ifdim macro and you must compare your \ylen own value
>with a length (dimension), not an integer.
>
>  P.S. If you want to build your own macros inside a personal package,
>you can better use the internal \z@ macro (which require as usual to have
>changed the catcode of @). You can take a look at some parts of the PSTricks
>code itself:
>...
>\newdimen\pslinearc
>...
>\def\psline at iii{%
>\ifdim\pslinearc>\z@
>...
>
>------------------------------------------------------------------------------
>
>\documentclass{article}
>\usepackage{pstricks}
>\newlength{\ylen}
>\pagestyle{empty}
>
>\begin{document}
>
>\typeout{Default value:\the\ylen}
>
>\setlength{\ylen}{-1pt}
>\ifdim\ylen>0pt\else\typeout{Point 1}\pssetlength{\ylen}{-\ylen}\fi
>
>\setlength{\ylen}{-1pt}
>\ifdim\ylen<0pt\typeout{Point 2}\pssetlength{\ylen}{-\ylen}\fi
>
>\end{document}
>
>D.G. 

--------------------------------------------------------------------------
Isaiah Shavitt
Professor Emeritus
Department of Chemistry           Telephone: 614-292-1668
The Ohio State University         Fax:       614-292-1685
Columbus, OH 43210-1185           E-mail: shavitt at chemistry.ohio-state.edu
--------------------------------------------------------------------------

-----------------------------------------------------------------------------
The list interface (subscription, information, access to the archives) is on:
http://www.tug.org/cgi-bin/lwgate/pstricks
Otherway to unsubscribe, send mail to pstricks-request at mail.tug.org
with a blank subject and in body the line unsubscribe <email-address>
-----------------------------------------------------------------------------



More information about the PSTricks mailing list