0

I have the following code:

\documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\newcount\x \x=-1
\begin{tikzpicture}
  \foreach \percentA in {33}
  {
    \if \percentA \empty \else
    \global\advance\x by 1
     \draw (\x,0) circle (0.2cm);
     \fi
  };
\end{tikzpicture}
\end{document}

If I use \if instead of \ifx, this code compiles to an empty document. If I would use 66 instead of 33, it would compile to an empty document as well. But if I would use any other value (like 32 or 34 or 65), it would work just fine, and would draw a circle.

Could somebody tell me why 33 equals to \empty? I know that I should have used \ifx, but I'm wondering why 33 and 66 are so special in this case, because I would expect the same behavior for every number.

frougon
  • 24,283
  • 1
  • 32
  • 55
  • 4
    \if expands tokens until it finds two non-expandable tokens. So \if\percentA \empty turns into \if33\empty, then 3 and 3 are compared and the result is true, so \empty is executed. – campa Feb 27 '20 at 13:25
  • 3
    What would be the reason to compare \percentA to \empty anyway? Could you please be more explicit about your real aim? – egreg Feb 27 '20 at 13:50
  • @egreg I wanted to generate a pie chart, and found this example as I was changing this to fit my purposes I somehow changed ifx to if. – stiefel Feb 28 '20 at 14:33
  • @stiefel The \ifx\percent\empty\else line is completely useless, because with the given data \percent is never empty. Remove it and the final \fi. – egreg Feb 28 '20 at 14:48

0 Answers0