考虑以下示例,其结果与这里,但代码是通用的。
代码
% pdflatex -shell-escape test.tex
\documentclass{article}
\usepackage{auto-pst-pdf,pst-node}
\usepackage{siunitx}
\def\path[#1]{%
\pscustom[dimen=middle,#1]{
\psarc(!\laengde \radius sub \radius){\radius}{-90}{90}
\psarc(!\laengde \radius sub 3 \radius mul){\radius}{-90}{90}
\psframe(\laengde,\bredde)
}\ignorespaces
}
\begin{document}
\begin{figure}
\def\laengde{216 }
\def\bredde{120 }
\edef\maksL{\the\numexpr\laengde+20\relax\space}
\edef\maksB{\the\numexpr\bredde+20\relax\space}
\edef\radius{\the\numexpr\bredde/4\relax\space} % Needs to be changed.
\centering
\psset{
unit=0.05
}
\begin{pspicture}(\maksL,\maksB)
\psclip{\path[linestyle=none]}
\psframe[
fillstyle=vlines,
hatchcolor=red,
hatchsep=1pt,
linestyle=none
](!\laengde \radius sub 0)(\laengde,\bredde)
\endpsclip
\path[]
\psdots(!\laengde \radius sub \radius)(!\laengde \radius sub 3 \radius mul)
\psset{
linestyle=dotted,
offset=12pt,
arrows=|<*->|*,
nrot=:U
}
\pcline(0,\bredde)(\laengde,\bredde)
\ncput*{\SI{\laengde}{\m}}
\pcline(\laengde,\bredde)(\laengde,0)
\ncput*{\SI{\bredde}{\m}}
\end{pspicture}
\end{figure}
\end{document}
输出
问题
我定义\radius
为
\def\radius{\the\numexpr\bredde/4\relax\space}
\bredde
但只有当它是 4 的倍数时,它才能正常工作。我尝试了这两种\dimexpr
方法,\newlength
但都无法正常工作(可能是由于一些微不足道的错误)。
答案1
\documentclass{article}
\usepackage{auto-pst-pdf,pst-node}
\usepackage{siunitx}
\def\path[#1]{%
\pscustom[dimen=middle,#1]{%
\psarc(\dimexpr\Laengde-\Radius,\Radius){\Radius}{-90}{90}
\psarc(\dimexpr\Laengde-\Radius,3\Radius){\Radius}{-90}{90}
\psframe(\Laengde,\Bredde)}}
\begin{document}
\psset{unit=0.05}
\def\laengde{216} \def\bredde{120}
\newlength\Laengde \Laengde=\laengde\psunit
\newlength\Bredde \Bredde=\bredde\psunit
\newlength\Radius \Radius=0.25\Bredde
\begin{pspicture}(\dimexpr\Laengde+5mm,\dimexpr\Bredde+5mm)
\psclip{\path[linestyle=none]}
\psframe[fillstyle=vlines,hatchcolor=red,hatchsep=1pt,linestyle=none]%
(\dimexpr\Laengde-\Radius,0)(\Laengde,\Bredde)
\endpsclip
\path[]
\psdots(\dimexpr\Laengde-\Radius,\Radius)(\dimexpr\Laengde-\Radius,3\Radius)
\psset{linestyle=dotted,offset=12pt,arrows=|<*->|*,nrot=:U}
\pcline(0,\Bredde)(\Laengde,\Bredde)
\ncput*{\SI{\laengde}{\m}}
\pcline(\Laengde,\Bredde)(\Laengde,0)
\ncput*{\SI{\bredde}{\m}}
\end{pspicture}
\end{document}
你是非常慷慨地结束你的行。这是不是总体来说,写一个好主意
\psset{
foo= ... ,
bar= ...
}
如果宏不删除尾随空格,那么文档中会有一些空格。如果要将其分成几行,请使用:
\psset{%
foo= ... ,
bar= ... %
}
其他宏也一样。
答案2
使用下面我的包,
% ========================================================
% Copyright (c) 2013 Bugbusters. All rights reservered.
% LPPL LaTeX Public Project License
% ========================================================
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{pst-sex}[2013/04/27 v3.141592654 Constant declator for StackEXchange]
\RequirePackage[nomessages]{fp}
\RequirePackage{pstricks}
% Removing a trailing space in the original fp.sty.
% I think this problem should be fixed directly to the fp.sty
% to make this package more compact.
\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%
}
\def\filter#1,#2#3\relax#4{%
\if t#1%
trunc(#4:#2)%
\else \if r#1%
round(#4:#2)%
\else \if c#1%
clip(#4)%
\else
\ERRORHERE
\fi\fi\fi}
% \pstVerb concatenator
\def\LoadConstants{}
% Constant declarator invoked in the preamble
\newcommand\const[3][]{%
\if\relax\detokenize{#1}\relax
\edef\temporary{#3}%
\else
\edef\temporary{\filter#1,any\relax{#3}}%
\fi
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\expandafter{\temporary}}%
\toks0=\expandafter{\LoadConstants\pstVerb}
\edef\LoadConstants{\the\toks0 {/#2 \csname#2\endcsname\space def}}}
\def\pst@@picture@i[#1]#2(#3,#4){%
% BEGIN - redefine \const for invocation inside pspicture
\renewcommand\const[3][]{%
\if\relax\detokenize{##1}\relax
\edef\temporary{##3}%
\else
\edef\temporary{\filter##1,any\relax{##3}}%
\fi
\expandafter\FPeval\csname##2\expandafter\endcsname
\expandafter{\expandafter{\temporary}}%
\pstVerb{/##2 \csname##2\endcsname\space def}\ignorespaces}%
% END - redefine \const for invocation inside pspicture
\@ifnextchar(% ignore anything between [] and ()
% BEGIN - inject \LoadConstants into pspicture
{\pst@@@picture[#1](#3,#4)\LoadConstants}%
{\pst@@@picture[#1](0,0)(#3,#4)\LoadConstants}%
% END - inject \LoadConstants into pspicture
}
\endinput
% pst-sex.sty
您的代码可以简化如下。
\documentclass[pstricks]{standalone}
\usepackage{pst-sex}
\usepackage{pst-node}
\usepackage{siunitx}
\const{laengde}{216}
\const{bredde}{120}
\const{maksL}{laengde+20}
\const{maksB}{bredde+20}
\const{radius}{bredde/4} % Needs to be changed.
\psset{unit=0.05}
\def\path[#1]{%
\pscustom[dimen=middle,#1]{
\psarc(!laengde radius sub radius){!radius}{-90}{90}
\psarc(!laengde radius sub 3 radius mul){!radius}{-90}{90}
\psframe(!laengde bredde)
}\ignorespaces
}
\begin{document}
\begin{pspicture}(\maksL,\maksB)
\psclip{\path[linestyle=none]}
\psframe[fillstyle=vlines,hatchcolor=red,hatchsep=1pt,linestyle=none](!laengde radius sub 0)(!laengde bredde)
\endpsclip
\path[]
\psdots(!laengde radius sub radius)(!laengde radius sub 3 radius mul)
\psset{linestyle=dotted,offset=12pt,arrows=|<*->|*,nrot=:U}
\pcline(!0 bredde)(!laengde bredde)
\ncput*{\SI{\laengde}{\m}}
\pcline(!laengde bredde)(!laengde 0)
\ncput*{\SI{\bredde}{\m}}
\end{pspicture}
\end{document}
编辑:
只要在序言中定义了每个选项,那么按照如下方式将其写在单独的行中也没有问题。
\usepackage
[
a4paper,
hmargin=1cm,
vmargin=2cm,% excessive commas are always ignored
]{geometry}
\psset
{
linewidth=2pt,
linecolor=red,
fillstyle=solid,
}