A puzzle with TeX \ifnum

Denis Girou Denis.Girou at idris.fr
Tue Oct 5 10:34:13 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.
-----------------------------------------------------------------------------

>>>>> "Isaiah.Shavitt" == Isaiah Shavitt <shavitt at chemistry.ohio-state.edu> writes:

    Isaiah.Shavitt> Can somebody tell me why

    Isaiah.Shavitt> 	\ifnum\ylen>0\else\pssetlength{\ylen}{-\ylen}\fi

    Isaiah.Shavitt> works (forcing \ylen to be positive), while

    Isaiah.Shavitt> 	\ifnum\ylen<0 \pssetlength{\ylen}{-\ylen}\fi

    Isaiah.Shavitt> does not?  It does not work even if I put \relax after the <0, 
    Isaiah.Shavitt> or put the \pssetlength command in braces, or try a few other 
    Isaiah.Shavitt> variations.  The \pssetlength command is just not executed.
    Isaiah.Shavitt> Or is there a better way to get the absolute value of \ylen 
    Isaiah.Shavitt> 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 oiwn 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.

-----------------------------------------------------------------------------
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