41

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

53

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
  • 3
    @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

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.