Skip to main content
Became Hot Network Question
Clarify my post by mentioning the boolean operation + floating point arithmetic.
Source Link
underflow
  • 1.1k
  • 6
  • 11

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} 

It is not working because \ifthenelse does not allow \a+\b.

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

Bonus questionEDIT: Is there a way to e.g. define \c = \a

Actually what I needed is \a + 1.414*\b < 4 AND \a \b in advance so- 1.414*\b > 0. I thought I can use \c elsewherecould handle the rest once I know how to insert arithmetic operations into \ifthenelse, in \ifthenelsebut apparently it's more complicated than that. Apologies for the mixup and subsequence \draw commands?thanks for your help.

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} 

It is not working because \ifthenelse does not allow \a+\b.

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} 

It is not working because \ifthenelse does not allow \a+\b.

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

EDIT:

Actually what I needed is \a + 1.414*\b < 4 AND \a - 1.414*\b > 0. I thought I could handle the rest once I know how to insert arithmetic operations into \ifthenelse, but apparently it's more complicated than that. Apologies for the mixup and thanks for your help.

added 22 characters in body; edited tags
Source Link
Werner
  • 625k
  • 145
  • 1.5k
  • 2.4k

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} 

It is not working because \ifthenelse\ifthenelse does not allow "\a+\b"\a+\b.

Bonus question: Is there a way to e.g. define \c\c = \a\a + \b\b in advance soso I can use \c\c elsewhere, in \ifthenelse\ifthenelse and subsequence \draw\draw commands?

THANKS!

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} 

It is not working because \ifthenelse does not allow "\a+\b".

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

THANKS!

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} \end{document} 

It is not working because \ifthenelse does not allow \a+\b.

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

Source Link
underflow
  • 1.1k
  • 6
  • 11

arithmetic operations with \ifthenelse

Is there a way to add arithmetic operations to \ifthenelse statements? Here is a minimal (non)example:

\documentclass{amsart} \usepackage{tikz, ifthen} \begin{document} \begin{tikzpicture} \foreach \a in {-6,...,6} { \foreach \b in {-6,...,6} { \ifthenelse{ (\a + \b) < 4 } { \node at ( (\a, \b ) {(\a, \b)}; } {} } } \end{tikzpicture} 

It is not working because \ifthenelse does not allow "\a+\b".

Bonus question: Is there a way to e.g. define \c = \a + \b in advance so I can use \c elsewhere, in \ifthenelse and subsequence \draw commands?

THANKS!