I would like to implement a command in LaTeX which would sum two numbers before comparing them to a third number as follows:
\ifnum #1+45>0
above
\else
left
\fi
where #1
is an angle in degrees.
Unfortunately it doesn't work.
Please, could you help me how to fix that?
Many thanks.
The whole code after advice from Werner:
\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{arrows}
\makeatletter
\newcommand{\compare}[1]{%
\ifdim\dimexpr#1pt+45pt\relax>\z@\relax
above%
\else
left%
\fi
}
\makeatother
% define arrows
% general right to left double harpoon
% define four connection position #5 and connect the arrows in +-5degrees
% first parameter define origin node
% second parameter define destination node,
% third parameter label of top arrow
% fourth parameter label of bottom arrow
% fifth parameter define connection point - angle in degrees on the origin node
\newcommand{\grldh}[5]{
\draw[-left to,thick] ({#1}.{#5+5}) -- node[\compare{#5}] {\scriptsize #3} ({#2}.{#5+175});
\draw[left to-,thick] ({#1}.{#5+355}) -- node[below] {\scriptsize #4} ({#2}.{#5+185});
}
\begin{document}
\pagenumbering{gobble}
\begin{tikzpicture}[
state/.style={
% The shape:
circle,minimum size=3mm,rounded corners=3mm,
},
scale=1.5]
% draw nodes
\path
(0,5) node (N05) [state] {$C$}
(1,5) node (N15) [state] {$O$}
(1,4) node (N14) [state] {$I$};
% draw paths
\grldh{N05}{N15}{$\alpha$}{$\beta$}{0};
\grldh{N05}{N14}{$\gamma$}{$\delta$}{-45};
\grldh{N15}{N14}{$\gamma$}{$\delta$}{-90};
\end{tikzpicture}
\end{document}
Best Answer
One would assume that you're dealing with real numbers that you want to compare. In that sense, a comparison of numbers is not appropriate, since they do not work with fractional components. Dimensions (or lengths) on the other hand do. You can trick a function to work with lengths rather than numbers in the following way:
The function
\compare{<num>}
uses<num>
in a "dimension" form as<num>pt
, adds45pt
to that, checks if this is greater than\z@
(or0pt
) and conditions accordingly.Note the use of
%
to avoid spurious spaces. See What is the use of percent signs (%
) at the end of lines?