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

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:



% 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
    \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}); 

    % The shape:
    circle,minimum size=3mm,rounded corners=3mm,
    % draw nodes
          (0,5)  node (N05) [state] {$C$}
          (1,5)  node (N15) [state] {$O$}
          (1,4)  node (N14) [state] {$I$};
    % draw paths


migrated from stackoverflow.com Feb 10 '13 at 12:42

This question came from our site for professional and enthusiast programmers.

  • Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – percusse Feb 10 '13 at 13:12
  • 1
    Also have you seen the tikz-cd package? – percusse Feb 10 '13 at 13:12

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:

enter image description here

$1$ is \compare{1}, % 1 + 45 = 46 > 0 -> above
while $-90$ is \compare{-90} % -90 + 45 = -45 < 0 -> left
and $-45$ is \compare{-45}. % -45 + 45 = 0 ... -> left

The function \compare{<num>} uses <num> in a "dimension" form as <num>pt, adds 45pt to that, checks if this is greater than \z@ (or 0pt) and conditions accordingly.

Note the use of % to avoid spurious spaces. See What is the use of percent signs (%) at the end of lines?

  • Thanks a lot, your example works perfectly. In my case, I intend to include the \compare command in definition of other command (please see the updated code attached), which does not work. Do you know what could be the problem? – Tomas Feb 9 '13 at 10:02
  • @Tomas: Remove both \relax commands within \compare. Give some feedback once you've tested. – Werner Feb 10 '13 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.