我从 PSTricks 开始。我使用以下宏来设置笛卡尔坐标:
\def\newPoint#1(#2,#3)
{
\expandafter\def\csname x#1\endcsname{#2}
\expandafter\def\csname y#1\endcsname{#3}
\expandafter\def\csname ponto#1\endcsname{#1(#2,#3)}
\expandafter\def\csname p#1\endcsname{#2,#3}
}
如您所见,这些坐标在内部定义了新的控制序列。
使用示例:
\newPoint A(-6,3)
\newPoint B(4,4)
\psline(\pA)(\pB) %or
%\psline(\xA,\yA)(\xB,\yB)
这种方法很方便,因为它使代码更简洁。
我再举一个例子:
\begin{figure}[H]
\centering
\begin{pspicture}[algebraic](-3.5,-1)(1,3)
\newPoint A(-2,2.5) \uput[ul](\pA){$ A $}
\newPoint B(-0.5,2.5) \uput[ur](\pB){$ B $}
\newPoint C(0.5,1) \uput[r](\pC){$ C $}
\newPoint D(-0.5,-0.5) \uput[dr](\pD){$ D $}
\newPoint E(-2,-0.5) \uput[dl](\pE){$ E $}
\newPoint F(-3,1) \uput[l](\pF){$ F $}
\pspolygon[showpoints=true]%
(\pA)(\pB)(\pC)(\pD)(\pE)(\pF)%
\psset{linestyle=dashed, dash=3pt 2pt, linewidth=.6pt}
\psline(\pA)(\pE)
\psline(\pA)(\pD)
\psline(\pA)(\pC)
\psline(\pF)(\pB)
\psline(\pF)(\pC)
\psline(\pF)(\pD)
\psline(\pE)(\pC)
\psline(\pE)(\pB)
\psline(\pD)(\pB)
\psdot(-1.25,1)
\end{pspicture}
\caption{An hexagon}
\end{figure}
我希望通过消除输入括号的需要来改进此过程。例如,我希望可以输入:
\pspolygon[showpoints=true]%
\pA\pB\pC\pD\pE\pF%
代替
\pspolygon[showpoints=true]%
(\pA)(\pB)(\pC)(\pD)(\pE)(\pF)%
这可能吗?有办法改进这个宏吗?
先感谢您。
答案1
\documentclass{article}
\usepackage{pst-node}
\makeatletter
\def\newPoint{\@ifnextchar[\newPoint@i{\newPoint@i[l]}}
\def\newPoint@i[#1]#2(#3){\pnode(#3){#2}\uput[#1](#3){$#2$}}
\makeatother
\begin{document}
\begin{pspicture}(-3.5,-1)(1,3)
\newPoint[ul]A(-2,2.5)
\newPoint[ur]B(-0.5,2.5)
\newPoint[r] C(0.5,1)
\newPoint[dr]D(-0.5,-0.5)
\newPoint[dl]E(-2,-0.5)
\newPoint F(-3,1)
\pspolygon[showpoints](A)(B)(C)(D)(E)(F)
\psset{linestyle=dashed, dash=3pt 2pt, linewidth=.6pt}
\psline(A)(E)(C)(A)(D)(B)(F)(D)
\psline(F)(C)\psline(E)(B)
\psdot(-1.25,1)
\end{pspicture}
\end{document}
\newPoints[..]...(..,..)[...]...(...)
也可能定义