4

Why does the following test using \ifthenelse not compile:

\documentclass[border=30pt, tikz]{standalone} \usepackage{tikz,tikz-3dplot} \usepackage{ifthen} \usepackage{animate, calc}%%%%%%%%%%%% \usepackage{animate} \usepackage{circuitikz} \begin{document} \foreach \x in {0.1,0.2,...,4}{ \begin{tikzpicture} \begin{circuitikz} \draw (0,0) to[V,v=$U_q$] (0,2) % The voltage source to[short] (2,2) to[R=$R_1$] (2,0) % The resistor to[short] (0,0); \draw (2,2) to[short] (4,2) to[R=$R_2$] (4,0) to[short] (2,0); \ifthenelse{\x<2}{\fill[color=red] (0,\x) circle (3pt);}{} \end{circuitikz} \end{tikzpicture} } \end{document} 

On compilation I get the following error:

! Missing = inserted for \ifnum. <to be read again> 

1 Answer 1

4

It doesn't work, because \ifnum (which is what \ifthenelse calls) only takes whole numbers (no fractions). Therefore you need another test. A very simple attempt:

\documentclass[border=30pt, tikz]{standalone} \usepackage{tikz,tikz-3dplot} \usepackage{xparse} \usepackage{animate, calc}%%%%%%%%%%%% \usepackage{animate} \usepackage{circuitikz} \ExplSyntaxOn \NewDocumentCommand { \xifnum } { } { \fp_compare:nTF } \ExplSyntaxOff \begin{document} \foreach \x in {0.1,0.2,...,4}{ \begin{tikzpicture} \begin{circuitikz} \draw (0,0) to[V,v=$U_q$] (0,2) % The voltage source to[short] (2,2) to[R=$R_1$] (2,0) % The resistor to[short] (0,0); \draw (2,2) to[short] (4,2) to[R=$R_2$] (4,0) to[short] (2,0); \xifnum{\x<2}{\fill[color=red] (0,\x) circle (3pt);}{} \end{circuitikz} \end{tikzpicture} } \end{document} 
3
  • 1
    Or using \foreach \x in {1,2,...,40} and comparing \x with 20, with (0,\x/10) as coordinate. Commented Apr 14, 2018 at 9:48
  • 1
    @egreg That sounds far too simple (and has no expl3) ;) Commented Apr 14, 2018 at 9:55
  • thank you for all, i used this reply to improve my question [about circuitikz ](tex.stackexchange.com/questions/426459/…) Commented Apr 14, 2018 at 10:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.