45

I want to use parentheses in coordinate calculation in tikz. There should be a simple way, but I couldn't find it. For example,

\def\x{10};
\draw (0,0) -- (1+1/\x,0);

this works fine. But,

\def\x{10};
\draw (0,0) -- (1+1/{\x+1},0);

this doesn't work. Other parentheses didn't work either. What is the expression for parentheses?

1 Answer 1

60

If your expression contains parentheses or commas, you may use {} around the whole expression:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
  \def\x{10};
  \draw (0,0) -- (1+1/\x,0);
  \draw (0,0) -- ({1+1/(\x+1)},0);
\end{tikzpicture}
\end{document}
2
  • 3
    Why "you may" ? After experimenting with some Tikz calculation, I'd rather say "you must".
    – kebs
    Dec 27, 2017 at 15:09
  • 4
    @kebs Another solution: you may use \pgfmathsetmacro\mytemp{1+1/(\x+1)}; \draw (0,0) -- (\mytemp,0);. Or use a let operation... Dec 28, 2017 at 3:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .