TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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{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)};
share|improve this question
up vote 13 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


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.