Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This code snippet defines a simple function using \pgfmathdeclarefunction (e.g. f()) and \pgfmathparse. I would like to use the defined function f() within other coordinate, e.g. (0.2, f(0.2)) vs. (0.2, f(0.2). Note the latter has one fewer ). Both usage do plot the dot, but the former results pgfplots error:

error| Package pgfplots Error: Sorry, I could not read the plot coordinates near ')'

I would like to know are these usage of defined function f() correct?

\begin{tikzpicture}
  \pgfmathdeclarefunction{f}{1}{%
    \pgfmathparse{#1}%
  }
  \begin{axis}[xmin=0, xmax=1, ymin=0, ymax=1,]
    % this draw the plot, but also report an error
    \addplot[mark=*, blue] coordinates {(0.2, f(0.2))};
    % this works
    \addplot[mark=*, blue] coordinates {(0.2, f(0.2)};
  \end{axis}
\end{tikzpicture}
share|improve this question

1 Answer 1

up vote 12 down vote accepted

If the function is used inside a coordinate pair, then you get two closing parentheses:

(0.2, f(0.2))

This apparently confuses the parser. These parentheses are not matched like curly braces in \TeX, when an argument is read. A set of curly braces protects the inner parentheses:

(0.2, {f(0.2)})

Then the inner delimiters are hidden for the parser that looks for the closing coordinate pair delimiter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.