Skip to content
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 \pgfmathdeclarefunction #508

Closed
pgf-tikz-bot opened this issue Jan 26, 2019 · 5 comments
Closed

spurious spaces in \pgfmathdeclarefunction #508

pgf-tikz-bot opened this issue Jan 26, 2019 · 5 comments

Comments

@pgf-tikz-bot
Copy link

Migrated from SourceForge
Author: u_fischer
Timestamp: 2019-01-26 21:41:33.503000

I'm not quite sure if this count as a bug. In the following example the definition of testA contains a spurious space. This space deplaces the bounding box of the resulting tikzpicture/plot but curiously only with pdflatex and lualatex. With xelatex both bounding boxes are fine.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\pgfmathdeclarefunction{testA}{1}{%
        \pgfmathparse{2} %spurious space
    }


\pgfmathdeclarefunction{testB}{1}{%
        \pgfmathparse{2}%
    }

xx\begin{tikzpicture}
\begin{axis}
  \addplot {testA(1)};
\end{axis}
\end{tikzpicture}yy



xx\begin{tikzpicture}
\begin{axis}
  \addplot {testB(1)};
\end{axis}
\end{tikzpicture}yy

\end{document}
@pgf-tikz-bot
Copy link
Author

Migrated from SourceForge
Author: hmenke
Timestamp: 2019-01-27 10:22:56.331000

  • status: open --> closed-fixed
  • assigned_to: Henri Menke

@pgf-tikz-bot
Copy link
Author

Migrated from SourceForge
Author: hmenke
Timestamp: 2019-01-27 10:22:57.188000

Fixed in https://sourceforge.net/p/pgf/git/ci/00f4e8d4154dcb3133ed4a106b6254b8faf874e2/ but it broke gcd. I hope it won't break too much else.

As a little gimmick you can get a spaces inside the definition using ~ like in expl3.

@cfeuersaenger
Copy link

I fear the solution breaks legal statements.

Take, for example

\documentclass{standalone}

\usepackage{tikz}

\begin{document}
%
\makeatletter

\def\test#1#2{%
	\pgfmathdeclarefunction{#1}{0}{#2}%
}%

\pgfmathdeclarefunction{XXX}{0}{\edef\pgfmathresult{\pgfkeysvaluesof{/pgf/bar width}}}

\test{YYY}{\edef\pgfmathresult{\pgfkeysvaluesof{/pgf/bar width}}}

\show\pgfmathXXX@

\show\pgfmathYYY@

\end{document}

The result is

> \pgfmathXXX@=macro:
->\edef \pgfmathresult {\pgfkeysvaluesof {/pgf/barwidth}}.
l.17 \show\pgfmathXXX@
                      
? 
> \pgfmathYYY@=macro:
->\edef \pgfmathresult {\pgfkeysvaluesof {/pgf/bar width}}.
l.19 \show\pgfmathYYY@

-- one results in a compile error whereas the second works correctly.

\catcode hackery is always prone to such issues, and given

  1. that the solution actually hinders most attempts to access key-value pairs (which often contain spaces) inside of math functions,
  2. the benefit of auto-correct user errors by filtering out spaces appears to be negligible,
    I will revert the change.

That means: users must not write spurious spaces into the definition of math functions. I know that this is hard to understand for all normal users and even non-TeX programmers, but I fear this is how TeX works -- you must care for spurious spaces, sorry.

@cfeuersaenger cfeuersaenger reopened this May 30, 2019
cfeuersaenger pushed a commit that referenced this issue May 30, 2019
This reverts 'Ignore spaces in #3 of \pgfmathdeclarefunction #509'
(github #508).

See the github comments for details
@hmenke
Copy link
Member

hmenke commented Sep 2, 2020

I've now provided a workaround that can be enabled by the user which will not affect already defined instances.

@hmenke
Copy link
Member

hmenke commented Sep 3, 2020

@u-fischer I had a look at this again and it seems that this is exclusively a pgfplots problem. It doesn't happen when I just use \draw plot (\x,{testA(1)}); in a tikzpicture. Looks like pgfplots switches to a text font and doesn't switch back to nullfont for plotting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants