Quantcast
Channel: LaTeX Tikz: Compare two \def arguments - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

LaTeX Tikz: Compare two \def arguments

$
0
0

I am writing a macro definition that draws dimensions in the style of technical drawing. I need to perform an inequality of two of the arguments to know which is coordinate is higher up, but the console doesn't understand the condition I used as the \ifthenelse argument.

%   (#1,#2):    Starting coordinate%   (#3,#4):    Ending coordinate%   #5:         Vertical upwards distance from the body%   #6:         Dimension text\usetikzlibrary{calc}\def\DimensionTop(#1,#2)(#3,#4)[#5,#6]{    \ifthenelse{#2>#4}    {   %   If point (#1,#2) is higher than (#3,#4)        \coordinate (D1) at ($ (#1,#2) + (0,#5) $);        \coordinate (D2) at ($ (#3,#4) + (0,#2-#4) + (0,#5) $);    }    {   %   If point (#3,#4) is higher than (#1,#2)        \coordinate (D1) at ($ (#1,#2) + (0,#4-#2) + (0,#5) $);        \coordinate (D2) at ($ (#3,#4) + (0,#5) $);    }    \draw (#1,#2) -- (D1) -- ++(0,0.2);    \draw (#3,#4) -- (D2) -- ++(0,0.2);    \draw[ , >=latex, thin ] (D1) -- (D2) node[ fill=white, midway ] {$\mathtt{#6}$};}

The function is used like this in the main document

\documentclass[border=2pt,convert={outext=.png}]{standalone}\usepackage{tikz}\usetikzlibrary{patterns}\usetikzlibrary{arrows}\begin{document}    \begin{tikzpicture}        % Custom command for the background grid, ignore        \GuideCartesian(-2,-2)(8,8);        \draw[ very thick ] (0,4) -- (2,5);        \DimensionTop(0,4)(2,5)[1,1.50];    \end{tikzpicture}\end{document}

Since the console doesn't understand the condition, it goes directly to the else case, which works when the point on the right is higher than the point on the left as in the picture.

Horizontal Dimension

What would be a correct way to express this condition?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images