What is the best way to declare a constant to be used within TikZ? I am using \pgfmathsetmacro because I have seen others do it on this site. A constant should be a simple thing, so I am bit confused why it should be necessary to use a low level(pgf) command for this!?
When using the ellipse command I have a strange problem where I need to wrap the constant in an extra set of {} when used like this:
\draw (6,6) ellipse (\r and 1);.
Error:
! Package PGF Math Error: Unknown operator 'a' or 'an' (in '1and 1').
Why is that?
Related: Problems with TikZ calculations
MWE:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\r}{1}
\draw (0,0) ellipse (1 cm and 1 cm); %ok
\draw (1,1) ellipse (1 and 1); %ok
\draw (2,2) ellipse (1 cm and \r cm); %ok
\draw (3,3) ellipse (1 and \r); %ok
\draw (4,4) ellipse (\r cm and 1 cm); %ok
\draw (5,5) ellipse ({\r} and 1); %ok
\draw (6,6) ellipse (\r and 1); %not ok
\draw (7,7) ellipse (\r{} and 1); %ok
\end{tikzpicture}
\end{document}
Edit: From @marmot's comment and experiment I have found, that \constant{} also works as in \draw (7,7) ellipse (\r{} and 1);... but what is the correct way to declare and use a constant - I can not find it in the TikZ manual. Should I always use \constant{}, or maybe only when problems arise?
\r andexpands to1andwhich the parser cannot make sense of. – May 08 '18 at 03:51\r{}!? Like in\newcommand{\abc}{\emph{abc}}\abc{}. – hpekristiansen May 08 '18 at 04:03\documentclass{article} \begin{document} Hello Car\LaTeX how's your day? \end{document}– May 08 '18 at 04:10\LaTeX{}(as I do not use xspace). -but does\pgfmathsetmacrowork the same way as commands? – hpekristiansen May 08 '18 at 15:03\pgfmathsetmacrobut with the fact that\ris a macro and trailing spaces get eaten up, just like spaces after\LaTeXdo. – May 08 '18 at 16:43