30

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?

34

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}
  • Why "you may" ? After experimenting with some Tikz calculation, I'd rather say "you must". – kebs Dec 27 '17 at 15:09
  • 2
    @kebs Another solution: you may use \pgfmathsetmacro\mytemp{1+1/(\x+1)}; \draw (0,0) -- (\mytemp,0);. Or use a let operation... – Paul Gaborit Dec 28 '17 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.