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.

In the code snippet below I would have expected both r(x) and s(x) to be the same line, but the output is two radically different lines as shown below.

enter image description here

If there is a problem using the name r as a function name, then I would have expected some sort of error message, but did not find one.

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}

\pgfmathdeclarefunction{r}{1}{\pgfmathparse{(2.0)}}
\pgfmathdeclarefunction{s}{1}{\pgfmathparse{(2.0)}}

\tikzstyle{MyPlotStyle}=[domain=-5:5, samples=50, ultra thick]

\begin{document}
Plot of $r(x)=2$ and $s(x)=2$ using PGF Version \pgfversion.

\begin{tikzpicture}
  \begin{axis}
    \addplot[MyPlotStyle, red ]{r(x)};
    \addplot[MyPlotStyle, blue]{s(x)};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this question

1 Answer 1

up vote 11 down vote accepted

In pgfmathparser.code.tex, r is defined as a math operator that applies the deg function, to be able to specify angles in radians (\pgfmathparse{3.14r}\pgfmathresult yields (almost) 180), so you shouldn't use this name for your own functions. I agree, though, that there should be an error message if you try to define a new function with a name that's already taken by an operator, especially since operators seem to take precedence. You might want to file a bug report / feature request for this.

share|improve this answer
    
I suspected it was something like that but since I saw no error message, I wasn't sure. Where do I file this bug report? –  Peter Grill May 31 '11 at 9:57
    
@Peter: The PGF project uses Sourceforge: sourceforge.net/tracker/?group_id=142562 –  Jake May 31 '11 at 10:02

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.