Pstricks 手册里有 MultTable 宏的例子,我直接复制代码粘贴到 tex 文件中,还是不行,谁能帮我修改一下?
\documentclass[pstricks,margin=1mm]{standalone}
\usepackage{pstricks,pst-poly,pst-text,pst-key}
\begin{document}
\begin{pspicture*}(12,3)
% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values
% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}
\def\MultTable@i{{%
\use@par% Assignment of local parameters
\pst@cnth=\MultTable@End
\advance\pst@cnth-\MultTable@Start
\advance\pst@cnth\@ne
\multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
\pst@cntg=\iValue
\multiply\pst@cntg\MultTable@Value
\iValue$\times$\MultTable@Value = \the\pst@cntg
\ifnum\multidocount=\pst@cnth\else; \fi}}}
\MultTable
\MultTable[Value=9]
\setkeys{psset}{Value=6}
\MultTable[Start=6,End=11]
\MultTable[Start=19742,End=19742]
\end{pspicture}
\end{document}
答案1
关于代码的文档有点少;初步定义应该放在和之间\makeatletter
,\makeatother
最好在之前\begin{document}
。在这种情况下,没有必要使用pspicture
,因为你实际上并不是在绘图。
\documentclass{article}
\usepackage{pstricks,pst-poly,pst-text,pst-key}
\makeatletter
% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values
% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}
\def\MultTable@i{{%
\use@par% Assignment of local parameters
\pst@cnth=\MultTable@End
\advance\pst@cnth-\MultTable@Start
\advance\pst@cnth\@ne
\multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
\pst@cntg=\iValue
\multiply\pst@cntg\MultTable@Value
\iValue$\times$\MultTable@Value = \the\pst@cntg
\ifnum\multidocount=\pst@cnth\else; \fi}}}
\makeatother
\begin{document}
\MultTable
\MultTable[Value=9]
\setkeys{psset}{Value=6}
\MultTable[Start=6,End=11]
\MultTable[Start=19742,End=19742]
\end{document}
应该如何multtable.sty
编写包?这里是
\ProvidesPackage{multtab}[2017/01/14 v. 0]
\RequirePackage{pstricks,pst-poly,pst-text,pst-key}
% “Start”, “End” and “Value” parameters
\define@key{psset}{Start}{\pst@getint{#1}{\MultTable@Start}}
\define@key{psset}{End}{\pst@getint{#1}{\MultTable@End}}
\define@key{psset}{Value}{\pst@getint{#1}{\MultTable@Value}}
\setkeys{psset}{Start=1,End=5,Value=2}% Default values
% Main macro for “multiplication table” object
\def\MultTable{\def\pst@par{}\pst@object{MultTable}}
\def\MultTable@i{{%
\use@par% Assignment of local parameters
\pst@cnth=\MultTable@End
\advance\pst@cnth-\MultTable@Start
\advance\pst@cnth\@ne
\multido{\iValue=\MultTable@Start+\@ne}{\pst@cnth}{%
\pst@cntg=\iValue
\multiply\pst@cntg\MultTable@Value
\iValue$\times$\MultTable@Value = \the\pst@cntg
\ifnum\multidocount=\pst@cnth\else; \fi}}}
\endinput
将其保存为multtable.sty
,然后\usepackage{multtable}
命令\MultTable
将完成其工作:
\documentclass{article}
\usepackage{multtable}
\begin{document}
\MultTable
\MultTable[Value=9]
\setkeys{psset}{Value=6}
\MultTable[Start=6,End=11]
\MultTable[Start=19742,End=19742]
\end{document}