[comp.text] Strange Event in LaTeX

carllee@math.rutgers.edu (Carl Lee) (02/13/90)

I must be doing something wrong, but I do not understand what.  Maybe
someone out there can solve this puzzle.

I have the following file:

----------------------------------------

\documentstyle{article}
\begin{document}

\long\def\text#1{\long\def\textx{#1}}
\long\def\print{\if\empty\textx\else{Text: \textx}\fi}

\text{Hello}
\print

\text{I: Hello}
\print

\text{II: Hello}
\print

\end{document}

----------------------------------------

When I process it with LaTeX, the output is:

Text: Hello

Text: I: Hello

:Hello

----------------------------------------

In other words, the presence of "II" causes the command "print" to
malfunction.  Does this happen to you?  What is going on? 

Carl Lee
carllee@dimacs.rutgers.edu

carllee@math.rutgers.edu (Carl Lee) (02/13/90)

->I must be doing something wrong, but I do not understand what.  Maybe
->someone out there can solve this puzzle.
->
->I have the following file:
->
->----------------------------------------
->
->\documentstyle{article}
->\begin{document}
->
->\long\def\text#1{\long\def\textx{#1}}
->\long\def\print{\if\empty\textx\else{Text: \textx}\fi}
->
->\text{Hello}
->\print
->
->\text{I: Hello}
->\print
->
->\text{II: Hello}
->\print
->
->\end{document}
->
->----------------------------------------
->
->When I process it with LaTeX, the output is:
->
->----------------------------------------
->
->Text: Hello
->
->Text: I: Hello
->
->:Hello
->
->----------------------------------------
->
->In other words, the presence of "II" causes the command "print" to
->malfunction.  Does this happen to you?  What is going on? 

Addendum:  It seems that when "II" is replaced with any pair of
identical characters, this behavior results.

Carl Lee
carllee@dimacs.rutgers.edu

steiner@topaz.rutgers.edu (Dave Steiner) (02/13/90)

In article <Feb.12.13.07.48.1990.20578@math.rutgers.edu> carllee@math.rutgers.edu (Carl Lee) writes:

> \long\def\text#1{\long\def\textx{#1}}
> \long\def\print{\if\empty\textx\else{Text: \textx}\fi}

Change your \if to an \ifx.  \if will test if the character codes
agree and will expand it's arguments so you were really comparing the
first two tokens of \textx.  \ifx will compare tokens without
expansion.

ds
-- 

arpa: Steiner@TOPAZ.RUTGERS.EDU
uucp: ...{ames, cbosgd, harvard, moss}!rutgers!topaz.rutgers.edu!steiner