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.

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.

share|improve this question

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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

2 Answers 2

up vote 2 down vote accepted

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}
share|improve this answer
    
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.

Download Tikz

share|improve this answer
    
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

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