一開始我使用以下程式碼。到目前為止,一切都很好。
\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
我檢查了using的值\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
。