一开始我使用下面的代码。到目前为止一切顺利。
\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}
我改变了主意,使用Yt
而不是\Yt
来进行以下操作。因为Yt
是在 PostScript 世界中,所以我必须\LoadConstants
再次调用一个额外函数(在循环中查看)。
\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}
不幸的是,垂直线向左移动了。我试图找出问题的原因,但我放弃了。你可以看到我已经删除了所有可能的空白,但问题仍然存在。
你能找到问题的根源吗?这是一个难题!
编辑:
Yt
我检查了使用的值\psPrintValue
,他们使用,
而不是.
作为小数点分隔符。这样可以吗?
\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}
答案1
有一个未受保护的行尾fp-exp.sty
;将其添加到您的序言中
\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
这是双重检查的完整代码。其中有很多%
我不会用到,但我还是保留了它们。
\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}
未受保护的行尾位于 的第 444 行fp-exp.sty
。