Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I defined a variable \@afwezig that holds people that were not present at a certain meeting.

\long\def\@afwezig{}
\def\afwezig#1{\def\@afwezig{#1}}

Now I want to make the header of the meeting report as follows :

\newcommand{\makeheader}{
\noindent
\begin{tabularx}{\linewidth}{l X}
  Aanwezig&: \@aanwezig \\
  Verontschuldigd&: \@verontschuldigd \\
 \ifx\@afwezig\@empty
  \relax
 \else
 Afwezig&: \@afwezig \\
 \fi %

\end{tabularx}

}

This is supposed to give a table with "Afwezig:" if I specify \afwezig{somename} in my document, but a table without the part "Afwezig:" if nothing is specified. Problem is, the part "Afwezig:" is displayed if I didn't specify '\afwezig', and I get tons of errors when I put \afwezig{} in my document file.

The first error:

! Incomplete \ifx; all text was ignored after line 10.

What am I doing wrong here?

PS : could somebody create a label with condition or if-else or so? thx

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You should internally think about tabular cells as being local groups, so you can't open an \ifx in one cell and close it in another. To work around this problem, you need to use an expansion trick:

\ifx\@afwezig\@empty
  \expandafter\@firstoftwo
\else
  \expandafter\@secondoftwo
\fi
{}
{Afwezig&: \@afwezig \\}

In general, this is a much cleaner way to deal with TeX conditions. Programming packages such as expl3 and etoolbox provide an easier way to write these constructs; e.g., in the former:

\tl_if_empty:NTF \@afwezig
  {}
  {Afwezig&: \@afwezig \\}
share|improve this answer
    
thx for the info. I figured out that if I delete the \relax, the code actually works as expected. I'll surely take a look at the packages you provided. –  Joris Meys Oct 13 '10 at 14:43
    
Even if it does in that case, be sure to be careful around conditionals and tabular material :-) –  Will Robertson Oct 14 '10 at 14:47
    
I realized. I took your advice and rewrote the part already. Thx again for the help. –  Joris Meys Oct 15 '10 at 11:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.