# What makes my line get shifted to the left when I invoke \LoadConstants?

In the beginning I use the following code. So far so good.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\noexpand\pstVerb{/#2 \csname#2\endcsname\space def}}%
}

\const[1]{G}{9.8}
\const[1]{Tfinal}{2.0}
\def\y(#1){-G/2*#1^2}
\const[1]{Yfinal}{\y(Tfinal)}

\SpecialCoor
\usepackage{siunitx}
\begin{document}
\begin{pspicture}[showgrid=false](3.5,\Yfinal)
\psline(1.5,0)(1.5,\Yfinal)
\multido{\n=0.0+0.5}{5}
{
\const[1]{Yt}{\y(\n)}%
\rput[r](*1.25 {\y(\n)}){$\SI{\Yt}{\meter}$}
\psline(1.4,\Yt)(1.6,\Yt)
\rput[l](*1.75 {\y(\n)}){$t=\SI{\n}{\second}$}
\pscircle*(*3.5 {\y(\n)}){5pt}
}
\end{pspicture}
\end{document}


I changed my mind to use Yt instead of \Yt for the following. Because Yt is in PostScript world, I have to invoke an extra \LoadConstants again (see it in the looping).

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\noexpand\pstVerb{/#2 \csname#2\endcsname\space def}}%
}

\const[1]{G}{9.8}
\const[1]{Tfinal}{2.0}
\def\y(#1){-G/2*#1^2}
\const[1]{Yfinal}{\y(Tfinal)}

\SpecialCoor
\usepackage{siunitx}
\begin{document}
\begin{pspicture}[showgrid=false](3.5,\Yfinal)%
\psline(1.5,0)(!1.5 Yfinal)%
\multido{\n=0.0+0.5}{15}%
{%
\const[1]{Yt}{\y(\n)}%
\LoadConstants%This is needed to provide Yt in PostScript world.
\rput[r](*1.25 {\y(\n)}){$\SI{\Yt}{\meter}$}%
\psline(!1.4 Yt)(!1.6 Yt)%
\rput[l](*1.75 {\y(\n)}){$t=\SI{\n}{\second}$}%
\pscircle*(*3.5 {\y(\n)}){5pt}%
}%
\end{pspicture}%
\end{document}


Unfortunately, the vertical line gets shifted to the left. I have tried to find the cause of problem but I give up. You can see I have removed all possible white spaces but the problem still exists.

Could you find the source of problem? It is a hard puzzle!

## Edit:

I checked the value of Yt using \psPrintValue and they use , instead of . as the decimal separator. Is it OK?

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
%\newcommand\const[3][3]{%
%\edef\temporary{round(#3}%
%\expandafter\FPeval\csname#2\expandafter\endcsname
%\expandafter{\temporary:#1)}%
%\noexpand\pstVerb{/#2 \csname#2\endcsname\space def}\ignorespaces}\ignorespaces%
%}
\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\pstVerb{/#2 \csname#2\endcsname\space def}%
}

\const[1]{G}{9.8}
\const[1]{Tfinal}{2.0}
\def\y(#1){-G/2*#1^2}
\const[1]{Yfinal}{\y(Tfinal)}

\SpecialCoor
\usepackage{siunitx}
\usepackage{pst-tools}
\begin{document}
\begin{pspicture}[showgrid=false](5,\Yfinal)%
\psline(1.5,0)(!1.5 Yfinal)%
\multido{\n=0.0+0.5}{15}%
{%
\const[1]{Yt}{\y(\n)}%
\rput[r](*1.25 {\y(\n)}){$\SI{\Yt}{\meter}$}%
\psline(!1.4 Yt)(!1.6 Yt)%
\rput[l](*1.75 {\y(\n)}){$t=\SI{\n}{\second}$}%
\pscircle*(*3.5 {\y(\n)}){5pt}%
\rput(*4 {\y(\n)}){\psPrintValue{Yt}}
}%
\end{pspicture}%
\end{document}

• Similar to your other question Why do I have to place % at the end of line preceding \pstVerb?, there may be a missing \ignorespaces in the code that is revealed through this example... – Werner Apr 8 '13 at 16:52
• @Karl'sstudents You can save a few keystrokes: \SI{\Yt}{\meter} --> \SI{\Yt}{\m} and \SI{\n}{\second} --> \SI{\n}{\s}. – Svend Tveskæg Apr 8 '13 at 16:56
• @Herbert is right, adding \pst@killglue after the \FPeval statement solves the problem. – Stephan Lehmke Apr 8 '13 at 21:55

There's an unprotected end of line in fp-exp.sty; add this to your preamble

\makeatletter
\def\FP@pow#1#2#3{% <---- This was unprotected
% #1 macro, which gets the result
% #2 base
% #3 exponent
%
\FP@beginmessage{POW}%
%
{\def\FP@beginmessage##1{}%
\def\FP@endmessage##1{}%
%
\FPifzero{#2}%
\FP@pow@zero{#3}%
\else%
\FPln\FP@tmpd{#2}%
\FPmul\FP@tmpd\FP@tmpd{#3}%
\FPexp\FP@tmp\FP@tmpd%
\fi%
%
\global\let\FP@tmp\FP@tmp%
}%
%
\FP@endmessage{}%
%
\let#1\FP@tmp%
}
\makeatother


Here's the complete code for double checking. There are many % that I wouldn't use, but I left them nonetheless.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\noexpand\pstVerb{/#2 \csname#2\endcsname\space def}}%
}

\const[1]{G}{9.8}
\const[1]{Tfinal}{2.0}
\def\y(#1){-G/2*#1^2}
\const[1]{Yfinal}{\y(Tfinal)}

\SpecialCoor
\usepackage{siunitx}

\makeatletter
\def\FP@pow#1#2#3{%
% #1 macro, which gets the result
% #2 base
% #3 exponent
%
\FP@beginmessage{POW}%
%
{\def\FP@beginmessage##1{}%
\def\FP@endmessage##1{}%
%
\FPifzero{#2}%
\FP@pow@zero{#3}%
\else%
\FPln\FP@tmpd{#2}%
\FPmul\FP@tmpd\FP@tmpd{#3}%
\FPexp\FP@tmp\FP@tmpd%
\fi%
%
\global\let\FP@tmp\FP@tmp%
}%
%
\FP@endmessage{}%
%
\let#1\FP@tmp%
}
\makeatother

\begin{document}

\begin{pspicture}[showgrid=false](3.5,\Yfinal)%
\psline(1.5,0)(!1.5 Yfinal)%
\multido{\n=0.0+0.5}{15}%
{%
\const[1]{Yt}{\y(\n)}%
\LoadConstants%This is needed to provide Yt in PostScript world.
\rput[r](*1.25 {\y(\n)}){$\SI{\Yt}{\meter}$}%
\psline(!1.4 Yt)(!1.6 Yt)%
\rput[l](*1.75 {\y(\n)}){$t=\SI{\n}{\second}$}%
\pscircle*(*3.5 {\y(\n)}){5pt}%
}%
\end{pspicture}%
\end{document}


The unprotected end-of-line is on line 444 of fp-exp.sty.

• Do I have to do this in every project? Or will it be fixed for the next release of fp-pow.sty? – kiss my armpit Apr 8 '13 at 22:01
• @Karl'sstudents As far as I can tell, fp hasn't been touched since 1995, so I can't foresee a "next release". You probably have better to edit the original file or make an amended copy of it in the local tree. However, you can raise the question in the TeX Live list and probably the maintainers will amend the file themselves (it's just a typo). – egreg Apr 8 '13 at 22:05
• There is no fp-pow but fp-exp. Thank you. The bounty will be offered until the bounty button is available. – kiss my armpit Apr 8 '13 at 22:12
• @Karl'sstudents Yes, it's fp-exp; I was confused with the name of the macro. – egreg Apr 8 '13 at 22:14
• The package fp has been updated in January 2019 and the patch is no longer needed. – egreg Jan 22 at 10:12