3

Possible Duplicate:
How do I use pgfmathdeclarefunction to create define a new pgf function?

I'm running the simple code:

\documentclass{minimal}
\usepackage{pgfplots}

\pgfmathdeclarefunction{p}{1}{%
  \pgfmathand{\pgfmathless{#1}{1}} {\pgfmathgreater{#1}{0}}%
}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    \addplot {p(x)};
  \end{axis}
\end{tikzpicture}

\end{document}

I get:

! Undefined controlsequence.

1.4 \pgfmathdeclarefunction

Any ideas what might be wrong? Other examples with pgf seem to work just fine.

If it helps, I'm using TexShop for mac. I have the most recent version.

Skuge
  • 284

2 Answers2

2

I believe this has something to do with expansion when using the \pgfmath... type functions within other \pgfmth....

But what does work is if you rewrite the function as:

 \pgfmathand{less({#1},1)}{greater({#1},0)}

This yields:

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\pgfmathdeclarefunction{p}{1}{%
  \pgfmathand{less({#1},1)}{greater({#1},0)}%
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot {p(x)};
  \end{axis}
\end{tikzpicture}
\end{document}
Peter Grill
  • 223,288
1

So it wasn't a problem with TexShop but a problem with TikZ. \pgfmathdeclarefunction is only available on the latest build.

Installing the package again should solve the problem.

Download Tikz

Torbjørn T.
  • 206,688
Skuge
  • 284
  • The builds found at TeXample are somewhat old, Altermundus have more recent builds. Also, \pgfmathdeclarefunction is found in the latest stable versions I believe (the build above is a development version), so simply updating your TeX distribution should help. – Torbjørn T. Mar 19 '12 at 07:13