When can I use functions and do calculations in TikZ?
How do I make this work:
\draw (0,0) arc(0:90:sqrt(15)); %not ok
why is this working:
\draw (0,0) arc(0:asin(1):5); %ok
with \usetikzlibrary{calc}
is this:
\draw (0,0) -- ($ (4,0) + sqrt(7)*(0,1) $); %ok
the only way to do single coordinate calculations? why is this
\draw (0,0) -- ($ (4,sqrt(7)) $); %not ok
not working?
Minimal example:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) arc(0:90:sqrt(15)); %not ok
\draw (0,0) arc(0:asin(1):5); %ok
\draw (0,0) -- ($ (4,0) + sqrt(7)*(0,1) $); %ok
\draw (0,0) -- ($ (4,sqrt(7)) $); %not ok
\end{tikzpicture}
\end{document}
Best Answer
You need to wrap the expression into
{ }
to hide the second pair of( )
from the TeX parser. Without the{ }
a(
will be closed by the next)
even if it belongs to another(
. This meansarc(0:90:sqrt(15))
will be taken asarc(0:90:sqrt(15)
without the second)
. This causes basically two errors, one in the expression because it misses the)
and another one in the\draw
path which doesn't know what to do with a single)
. With the{ }
it works because any{
must be closed first with a}
before the)
is taken.