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.

enter image description here

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

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
\def\LoadConstants{}
\newcommand\const[3][3]{%
    \edef\temporary{round(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \edef\LoadConstants{\LoadConstants
            \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)
    \LoadConstants
    \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).

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido}
\usepackage[nomessages]{fp}
\def\LoadConstants{}
\newcommand\const[3][3]{%
    \edef\temporary{round(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \edef\LoadConstants{\LoadConstants
            \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)%
    \LoadConstants%
    \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}
%\def\LoadConstants{}
%\newcommand\const[3][3]{%
    %\edef\temporary{round(#3}%
    %\expandafter\FPeval\csname#2\expandafter\endcsname
        %\expandafter{\temporary:#1)}%
        %\edef\LoadConstants{\LoadConstants\ignorespaces
            %\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)%
    %\LoadConstants%
    \psline(1.5,0)(!1.5 Yfinal)%
    \multido{\n=0.0+0.5}{15}%
    {%
        \const[1]{Yt}{\y(\n)}%
        %\LoadConstants%
        \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}
share|improve this question
    
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
1  
@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

1 Answer 1

up vote 6 down vote accepted
+1500

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

enter image description here

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}
\def\LoadConstants{}
\newcommand\const[3][3]{%
    \edef\temporary{round(#3}%
    \expandafter\FPeval\csname#2\expandafter\endcsname
        \expandafter{\temporary:#1)}%
        \edef\LoadConstants{\LoadConstants
            \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)%
    \LoadConstants%
    \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.

share|improve this answer
    
Do I have to do this in every project? Or will it be fixed for the next release of fp-pow.sty? –  stalking is prohibited 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. –  stalking is prohibited 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

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.