-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spurious spaces in function get typeset #370
Comments
It is a known thingy, coming from \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
\pgfmathdeclarefunction{test}{1}{%
\pgfmathparse{sin(#1)} % <--- spurious space here
}
\begin{tikzpicture}[x=.5pt]
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\draw plot[domain=0:360,samples=20] (\x,{test(\x)});
\end{tikzpicture}
\end{document} |
If this was a bug, it would be a bug of pgf, not pgfplots. However, IMHO it is not a bug. Things are written clearly in section 96 of the pgfmanual v3.1.6. You only need to set
|
Very good observation! I think I've found it: diff --git a/tex/generic/pgf/libraries/pgflibraryfpu.code.tex b/tex/generic/pgf/libraries/pgflibraryfpu.code.tex
index c3bb9582..556e2fec 100644
--- a/tex/generic/pgf/libraries/pgflibraryfpu.code.tex
+++ b/tex/generic/pgf/libraries/pgflibraryfpu.code.tex
@@ -132,6 +132,7 @@
\else
\pgfmathfloatparse@output
\fi
+ \ignorespaces
}%
\def\pgfmathfloat@char@asterisk{*}% |
I agree. The \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{fpu}
\makeatletter
\def\pgfmathfloatparse@#1{%
\edef\pgfmathfloat@expression{#1}%
\expandafter\pgfmathfloatparse@@\pgfmathfloat@expression\pgfmathfloat@
\ifpgfmathfloat@scaleactive
\expandafter\pgfmathfloatmultiply@\expandafter{\pgfmathresult}{\pgfmathfloatscale}%
\pgfmathfloattofixed{\pgfmathresult}%
\else
\pgfmathfloatparse@output
\fi
\ignorespaces %<- works
}%
\makeatother
\begin{document}
\tikzset{myfun/.cd,a 1/.initial=1}
% \pgfkeys{/pgf/declare function/ignore spaces=true} %<- does not work
\pgfmathdeclarefunction{test}{1}{%
\pgfmathparse{sin(\pgfkeysvalueof{/tikz/myfun/a 1}*#1)} % <--- spurious space here
}
\begin{tikzpicture}[x=.5pt,]
\pgfkeys{/pgf/fpu=true,/pgf/fpu/output format=fixed}%
\draw plot[domain=0:360,samples=35] (\x,{test(\x)});
\end{tikzpicture}
\end{document} |
Not a |
Brief outline of the bug
When there are spurious spaces in the definition of a
\pgfmathdeclarefunction
, these spaces end up in the document, shifting the plot on the page. Some people think that this is an issue in PGF (pgf-tikz/pgf#508, pgf-tikz/pgf#915) because it can be worked around by ignoring spaces in the definition of the function, but I believe this is a pgfplots problem. The reason is that a similar MWE with a regular\draw plot
does not exhibit the shifting. This is potentially due to the fact that TikZ switches to nullfont inside the picture whereas pgfplots switches to a text font and fails to switch back to nullfont for the plot (just a hypothesis).Minimal working example (MWE)
Here is the pgfplots example which exhibits the shift:
This “equivalent” TikZ example does not exhibit a shift:
The text was updated successfully, but these errors were encountered: