MHB Is it possible to use \ifthenelse

  • Thread starter Thread starter MarkFL
  • Start date Start date
AI Thread Summary
The discussion focuses on using the \ifthenelse construct within TikZ diagrams, specifically how to incorporate the "ifthen" package. It is confirmed that the package must be included in the preamble since it is not a TikZ library, allowing the construct to function properly. An example code snippet demonstrates how to use \ifthenelse to conditionally fill circles based on a variable. The user expresses a need for conditionals to accurately depict direction fields in their diagrams. Overall, the thread provides practical guidance for implementing conditional logic in TikZ graphics.
MarkFL
Gold Member
MHB
Messages
13,284
Reaction score
12
Hello!

I was interested in using the \ifthenelse construct in one of my diagrams, and wanted to know how I would go about adding support for the "ifthen" package. :)
 
Physics news on Phys.org
MarkFL said:
Hello!

I was interested in using the \ifthenelse construct in one of my diagrams, and wanted to know how I would go about adding support for the "ifthen" package. :)

Apparently the ifthen package has to be added in the preamble (since it's not a tikzlibrary), after which it works out of the box:
\begin{tikzpicture}
%preamble \usepackage{ifthen}
\foreach \x in {0,...,4} {
\ifthenelse{\x=3}{}{\fill (\x,0) circle (0.1);}
}
\end{tikzpicture}
[latexs]\begin{tikzpicture}
%preamble \usepackage{ifthen}
\foreach \x in {0,...,4} {
\ifthenelse{\x=3}{}{\fill (\x,0) circle (0.1);}
}
\end{tikzpicture}[/latexs]
 
I like Serena said:
Apparently the ifthen package has to be added in the preamble (since it's not a tikzlibrary), after which it works out of the box:
\begin{tikzpicture}
%preamble \usepackage{ifthen}
\foreach \x in {0,...,4}{
\ifthenelse{\x=3}{}{\fill (\x,0) circle (0.1);}
}
\end{tikzpicture}
[latexs]\begin{tikzpicture}
%preamble \usepackage{ifthen}
\foreach \x in {0,...,4}{
\ifthenelse{\x=3}{}{\fill (\x,0) circle (0.1);}
}
\end{tikzpicture}[/latexs]

I would have sworn I tried that, but I'll give it another go...thanks for the prompt help! (Yes)

I'm working on elaborating on the diagram I posted in the TikZ Challenge thread to create a general purpose template for plotting direction fields, and I need conditionals to get the direction of the little slope lines correct so that they point in the right direction. :)
 

Similar threads

Replies
12
Views
2K
Replies
8
Views
6K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
3
Views
3K
Replies
25
Views
2K
Back
Top