Just for demo purpose, below logic only run into if clause but never run to else clause.  \documentclass[tikz,border=2pt]{standalone} \usepackage{ifthen} \begin{document}     \begin{tikzpicture}     \pgfmathtruncatemacro{\x}{10}     \foreach \i in {1,...,4} {         \ifthenelse{\x = 0}{             \pgfmathtruncatemacro{\x}{1}              \draw (0,0) circle (\i);          }{             \pgfmathtruncatemacro{\x}{0}             \draw[red,line width=2pt] (0,0) circle (\i);          }          }     \end{tikzpicture} \end{document}   Maybe the variable \x define is wrong! how can I get the varialbe \x value changed each time the if check run? Now the if clause always think \x = 0. but actually I changed it in the if clause.
122254
I need to update a variable defined in a pgfmathsetmacro command inside a foreach loop. Apparently, the var is only updated when it is used after the update command. Here is a MWE:  \begin{tikzpicture} \draw [help lines] (0,0) grid (3,3); \pgfmathsetmacro{\a}{1} \foreach \b in {2,3} {     \node [blue] at (\a,0) {\a};     \pgfmathsetmacro{\a}{\b}     \node [red] at (0,\a) {\a}; } \end{tikzpicture}   The red nodes are printed at updated positions and the value printed is also updated; the blue nodes are not: they keep their initial value (1) and are located at the initial position (0,1).  Why is this? Thanks José
34951
It's a really basic question but i can't think at the second. How do i set up a loop that asks each time the function inside runs whether to do it again. So it runs it then says something like;  "loop again? y/n"
351
Can someone explain what does [count=\i] in a foreach mean?  Antal S-Z's answer to  use this. It is also mentioned in , but I am not able to locate documentation on this in the TikZ-PGF manual (V2.10)
113163
\documentclass[margin=5pt]{standalone} \usepackage{tikz} \usetikzlibrary{shapes,calc} \begin{document} \begin{tikzpicture}  \foreach \x [evaluate=\x as \name using \x*20] in{0,0.05,0.1,0.15,...,5}    \node(\name)[regular polygon, regular polygon sides=12,inner sep=0pt,minimum size=\x cm]{};  \node at(1){test}; \end{tikzpicture} \end{document}   I get an error saying that there is no shape named "1". The loop works fine (if you add a "draw" option the 12-polygons show up) except for the evaluating part.  edit: I just discovered that 0.05*20 yields 1,00006 instead of 1, so it cannot find a node named 1. Why is that? How can I get 1 from 0,05*20?
74010
I am trying to use the etoolbox \ifblank (and its cousin \notblank), but I want to expand any macros in its test statement.  For example:  \documentclass{article} \usepackage{etoolbox}  \begin{document}  \newtoggle{longformt} \newcommand{\longform}{\toggletrue{longformt}} \newcommand{\iflong}[2]{\iftoggle{longformt}{#1}{#2}}  \newcommand{\quoteifnotblank}[1]{%     \notblank{#1}{``#1''}{}% }  % Try commenting this line. \longform  This should be completely blank if the form is short: \quoteifnotblank{\iflong{Some long quoted text}{}}  \end{document}   The problem here is that \notblank sees its argument of \iflong{Some long quoted text}{} as a string, not as code to be expanded, so the quotes always appear.  How do I expand arguments before they are passed to \notblank?
78279
I'm sure there's a simpler way of doing this that's just not occurring to me.  I'm calling a bunch of methods that return a list.  The list may be empty.  If the list is non-empty, I want to return the first item; otherwise, I want to return None.  This code works:  my_list = get_list() if len(my_list) &gt; 0: return my_list[0] return None   It seems to me that there should be a simple one-line idiom for doing this, but for the life of me I can't think of it.  Is there?  Edit:  The reason that I'm looking for a one-line expression here is not that I like incredibly terse code, but because I'm having to write a lot of code like this:  x = get_first_list() if x:     # do something with x[0]     # inevitably forget the [0] part, and have a bug to fix y = get_second_list() if y:     # do something with y[0]     # inevitably forget the [0] part AGAIN, and have another bug to fix   What I'd like to be doing can certainly be accomplished with a function (and probably will be):  def first_item(list_or_none):     if list_or_none: return list_or_none[0]  x = first_item(get_first_list()) if x:     # do something with x y = first_item(get_second_list()) if y:     # do something with y   I posted the question because I'm frequently surprised by what simple expressions in Python can do, and I thought that writing a function was a silly thing to do if there was a simple expression could do the trick.  But seeing these answers, it seems like a function is the simple solution.
7945
What is the difference between &gt;&gt; and &gt;&gt;&gt; in verilog/system verilog? I know that == tests for only 1 and 0, while === tests for 1, 0, X, Z. So how is that similar to the shift operator?
75455
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&lt;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. &lt;to be read again&gt;
123344
\documentclass{standalone} \usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=1.15}  \begin{document}     \newcommand{\xmax}{14}     \newcommand{\fmin}{(pi/3)}     \newcommand{\fmax}{(2*pi)} \begin{tikzpicture}[domain=0:\xmax, samples=500]  \draw[ultra thick, red] plot (\x, {sin(deg(exp(ln(\fmin)+\x/\xmax*(ln(\fmax)-ln(\fmin)))*\x))} );  \end{tikzpicture} \end{document}   I would understand if LaTeX repeat the code below this statement many times.
57366
Trying to convert a coment into a complete answer for  I think that my solution there worked by chance and that MWijnand  found a wrong behavior in to path library when {x|y}scale has negative values.  Take a look at this example:  \documentclass[tikz,border=2mm]{standalone} \usepackage{bondgraph}           \usetikzlibrary[petri]   \begin{document} \begin{tikzpicture}[thin,&gt;=stealth, every place/.style={draw,thick,minimum size=6mm}]     \node[place] (pG) {$p_G$};     \node[place,right=3cm of pG] (pR) {$p_R$};     \draw[-&gt;] (pR) to [out=150, in=30] (pG);     \begin{scope}[yscale=-1]     \draw[-&gt;,blue] (pR) to [out=150, in=30] (pG);     \end{scope}      \begin{scope}[xscale=-1]     \draw[-&gt;,red] (pR) to [out=150, in=30] (pG);     \end{scope}      \begin{scope}[scale=-1]     \draw[-&gt;,green] (pR) to [out=150, in=30] (pG);     \end{scope}  \end{tikzpicture} \end{document}   and its strange result.    What I would expect was that pR.center was the paths origin and pG.center was the path end. The path would have a out angle affected by scale factor and the drawn path would start on corresponding intersection point over pR border. This is what happens with out angle as you can see around pR node.  But this doesn't happen with in angle (pG node). in angle fixes final anchor at  pG.30 and not at pG.center as expected. It also changes incidence angle for which scale factor is applied.   I think this is wrong and I'll fill a . If I'm wrong or you have a better solution, please let us know.
32175
I feel really stupid for asking this, but how do you form more complex if conditionals in TeX? I'm looking for something like:  \ifnum\x=1 OR \ifnum\x=14     {do this} \else     {do that} \fi   I don't want to have to resort to copy-pasting the entire condition just to change the expression when the body is the same.
38396
In a Tikz Figure, I'm doing some computation and want to print results as label of nodes. The problem is that I only need the integer part of the number to print.  I tried with round() function. It round the values correctly but they are printed with .0  \begin{tikzpicture}    \foreach \i in {1,2,3,4,5,6} {       \pgfmathparse{round(\i*100/3) }        \let\theIntINeed\pgfmathresult        \draw (\i,0) node {\theIntINeed};    }  \end{tikzpicture}  % Results: 33.0 67.0 100.0 133.0 167.0 200.0   Thank you in advance.
62153
I understand test -n &lt;expression&gt; to return false if the expression evaluates to a string length of greater than 0.  Why then does the following happen?  Macbook:~ echo ${#undeclared_variable} 0 Macbook:~ test -n $undeclared_variable &amp;&amp; echo Foo Foo   Bash 4.x  My expectation is that since test -n $undeclared_variable should evaluate false, that Foo should not be echoed.  If I use [[  ]] instead of test, it works as expected.
55678
TikZ: variable in calc syntaTikZ: variable in calc syntax 1 x 1
45364
I have seen the following technique used many times on many different shells, to test if a variable is empty:  if [ "x$1" = "x" ]; then      # Variable is empty fi   Are there any advantages on using this over the more canonical if [ -z "$1" ]? Could it be a portability issue?
1022
The following code works as expected in both Python 2.5 and 3.0:  a, b, c = (1, 2, 3)  print(a, b, c)  def test():     print(a)     print(b)     print(c)    # (A)     #c+=1       # (B) test()   However, when I uncomment line (B), I get an UnboundLocalError: 'c' not assigned at line (A). The values of a and b are printed correctly. This has me completely baffled for two reasons:   Why is there a runtime error thrown at line (A) because of a later statement on line (B)? Why are variables a and b printed as expected, while c raises an error?   The only explanation I can come up with is that a local variable c is created by the assignment c+=1, which takes precedent over the "global" variable c even before the local variable is created. Of course, it doesn't make sense for a variable to "steal" scope before it exists.  Could someone please explain this behavior?
23695
I am using \if condition in a custom command in my LaTeX document. I would like to know where I can find some good explanation about \if command. I followed a  but it's just an example; there are not any explanation.