# Can't use \pgfmathdeclarefunction even though I use package pgfplots? [duplicate]

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}
\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.

-

## marked as duplicate by Alain Matthes, percusse, Peter Grill, lockstep, cmhughesMar 19 '12 at 15:52

I don't get the error you describe, but get ! Extra \else. \pgfmath@operation@@process Following defining-a-piecewise-function-for-pgfplots and using \pgfmathdeclarefunction{p}{1}{\pgfmathparse{(and(#1>0, #1<1)*1)}} everything works fine. Is your tex distribution up to date?  –  cmhughes Mar 19 '12 at 3:07
I'm usin Texshop for mac. I just downloaded the last version but I still get the same error. –  Skuge Mar 19 '12 at 5:07
TeXShop is just an editor, not the tex distribution that does the actual typesetting. And Welcome to TeX.SE. –  Peter Grill Mar 19 '12 at 5:17

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:

\documentclass{article}
\usepackage{pgfplots}

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

\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}

-
or with \pgfmathparse{and(less(#1,1),greater(#1,0))} –  Alain Matthes Mar 19 '12 at 7:51
@Altermundus: Yep, or as per cmhughes' comment above. I was trying to keep it as close to the original post.. –  Peter Grill Mar 19 '12 at 13:54

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.

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 7:13