请考虑以下示例:
\documentclass[danish,a4paper,12pt]{article}
\usepackage{babel}
\usepackage[hmargin=2.4cm,vmargin=3cm]{geometry}
\usepackage{pstricks}
\begin{document}
\begin{figure}[htbp]
\def\h{150 }
\def\w{45 }
\def\hb{8 }
\def\hd{18 }
\def\a{1 }
\def\b{1 }
\def\c{1 }
\def\d{1.5mm}
\def\N{5 }
\centering
\SpecialCoor
\psset{unit=0.8mm}
\begin{pspicture}(-25.5,-7)(23.5,150)
\pstVerb{%
/f {neg \h div 1 add \w mul \c dup add sub 0.5 mul} def
/hbh 0.5 1 \hd \h div add mul def
}
\pspolygon(!\w 2 div neg 0)(!\w 2 div 0)(0,\h)
\psforeach{\iA}{1,2,..,\N}{%
\pstVerb{/z \iA\space 1 sub \b \hd add mul def}
\pspolygon(!z f neg z)(!z f z)(!z \hd add dup f exch)(!z \hd add dup f neg exch)
\pscircle(!0 0.5 \hd mul \iA\space 1 sub \hd \b add mul add){\d}
}
\pspolygon(!hbh neg \w mul \a sub \hb neg)%
(!hbh \w mul \a add \hb neg)%
(!0.5 \w mul \a add 0)%
(!-0.5 \w mul \a sub 0)
\end{pspicture}
\end{figure}
\noindent
\textsf{Bem{\ae}rkning:} Figuren er ikke i m{\aa}lestoksforholdet~$1{:}10$, men dens m{\aa}l passer i forhold til hinanden.
\end{document}
latex
如果我想要\noindent
图后面的内容,该如何使代码在使用时可编译?
答案1
\pstVerb{
/f { neg \h div 1 add \w mul \c dup add sub 0.5 mul } def
/hbh 0.5 1 \hd \h div add mul def }
}
这是一个全球的PostScript 代码的定义,使用一个字符作为变量名是危险的。这是其中一种情况:/f
由 TeX 本身定义。至少使用/ff
\pstVerb{
/ff { neg \h div 1 add \w mul \c dup add sub 0.5 mul } def
/hbh 0.5 1 \hd \h div add mul def }
}
并将其他表达式也改为ff
。然而,类似
/svend@f { ... }
确实很安全。
答案2
您还可以使用userdict begin ... end
它来避免与现有的名称冲突。
\documentclass[pstricks,border=12pt]{standalone}
\def\h{150 }
\def\w{45 }
\def\hb{8 }
\def\hd{18 }
\def\a{1 }
\def\b{1 }
\def\c{1 }
\def\d{1.5mm}
\def\N{5 }
\SpecialCoor
\psset{unit=0.8mm}
\begin{document}
\begin{pspicture}(-25.5,-7)(23.5,150)
\pstVerb
{
userdict begin
/f {neg \h div 1 add \w mul \c dup add sub 0.5 mul} def
/hbh 0.5 1 \hd \h div add mul def
end
}%
\pspolygon(!\w 2 div neg 0)(!\w 2 div 0)(0,\h)
\psforeach{\iA}{1,2,..,\N}
{%
\pstVerb
{
userdict begin
/z \iA\space 1 sub \b \hd add mul def
end
}%
\pspolygon
(!userdict begin z f neg z end)
(!userdict begin z f z end)
(!userdict begin z \hd add dup f exch end)
(!userdict begin z \hd add dup f neg exch end)
\pscircle(!0 0.5 \hd mul \iA\space 1 sub \hd \b add mul add){\d}
}
\pspolygon
(!userdict begin hbh neg \w mul \a sub \hb neg end)
(!userdict begin hbh \w mul \a add \hb neg end)
(!0.5 \w mul \a add 0)
(!-0.5 \w mul \a sub 0)
\end{pspicture}
\end{document}