如何在普通 (Xe)TeX 中绘制方框

如何在普通 (Xe)TeX 中绘制方框

我用 Plain TeX 编写文档,其中包含一些15 拼图图表。我编写了以下宏来生成此类图表:

\def\tablerule{\noalign{\hrule}}
\def\puzzlebox#1{\vbox to 2em{\vfil\hbox to 2em{\hfil#1\hskip .5em}\vfil}}
\long\def\sixteenpuzzle#1{\vbox{\offinterlineskip\hrule\tabskip=0pt
\halign{\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}\vrule\cr#1}}}

该宏可以像这样使用并且工作正常:

\sixteenpuzzle{
&1&2&3\cr\tablerule
4&5&6&7\cr\tablerule
8&9&10&11\cr\tablerule
12&13&14&15\cr\tablerule}

但是,我希望用对角线填充空网格点,这样可以清楚地看到网格点未被占用。使用 XeTeX,如何用对角线填充网格的一个单元格?

如果这样做需要完全改变\sixteenpuzzle宏,那么我可以接受,因为无论如何它感觉有点像离合器。

答案1

对于文档来说,纯 TeX 是一种奇怪的格式选择(除了制作测试用例之外),但无论如何,

在此处输入图片描述

\def\tablerule{\noalign{\hrule}}
\def\puzzlebox#1{%
\vbox to 2em{\vfil\hbox to 2em{%
\ifx\relax#1\relax
\special {pdf: content q 0.5 0.5 0.5 RG 0 -10 m 20 10 l b Q }%
\special {pdf: content q 0.5 0.5 0.5 RG 0 -5  m 15 10 l b Q }%
\special {pdf: content q 0.5 0.5 0.5 RG 0 0   m 10 10 l b Q }%
\special {pdf: content q 0.5 0.5 0.5 RG 0 5   m 5  10 l b Q }%
%
\special {pdf: content q 0.5 0.5 0.5 RG 5  -10 m 20 5  l b Q }%
\special {pdf: content q 0.5 0.5 0.5 RG 10 -10 m 20 0  l b Q }%
\special {pdf: content q 0.5 0.5 0.5 RG 15 -10 m 20 -5 l b Q }%
\hfill
\else
\hfil#1\hskip .5em\fi}\vfil}}
\long\def\sixteenpuzzle#1{\vbox{\offinterlineskip\hrule\tabskip=0pt
\halign{\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}\vrule\cr#1}}}


\sixteenpuzzle{
&1&2&3\cr\tablerule
4&5&6&7\cr\tablerule
8&9&10&11\cr\tablerule
12&13&14&15\cr\tablerule}


\bye

答案2

这是我根据以下人的好回答编写的宏大卫·卡莱尔

\def\boxaround#1{\vbox{\hrule\hbox{\vrule\kern2pt\vbox{\kern2pt#1\kern2pt}\kern2pt\vrule}\hrule}}
\def\hatchpattern{%
\special{pdf: content q 0 G 0.4 w  0   8 m  2  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   6 m  4  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   4 m  6  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   2 m  8  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   0 m 10  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -2 m 12  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -4 m 14  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -6 m 16  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -8 m 18  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0 -10 m 20  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  2 -10 m 20   8 l b Q}%
\special{pdf: content q 0 G 0.4 w  4 -10 m 20   6 l b Q}%
\special{pdf: content q 0 G 0.4 w  6 -10 m 20   4 l b Q}%
\special{pdf: content q 0 G 0.4 w  8 -10 m 20   2 l b Q}%
\special{pdf: content q 0 G 0.4 w 10 -10 m 20   0 l b Q}%
\special{pdf: content q 0 G 0.4 w 12 -10 m 20  -2 l b Q}%
\special{pdf: content q 0 G 0.4 w 14 -10 m 20  -4 l b Q}%
\special{pdf: content q 0 G 0.4 w 16 -10 m 20  -6 l b Q}%
\special{pdf: content q 0 G 0.4 w 18 -10 m 20  -8 l b Q}}
\def\puzzlebox#1{\vbox to 2em{\vfil\hbox to 2em{\ifx\relax#1\relax\hatchpattern\hss\else\hfil#1\hskip .5em\fi}\vfil}}
\long\def\sixteenpuzzle#1{\boxaround{\offinterlineskip\hrule\tabskip=0pt
\halign{\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}&\vrule\puzzlebox{##}\vrule\cr#1}}}

最终的拼图图如下所示:

排列和解决的 15 谜题

我后来进一步改进了这个宏集:

\def\boxaround#1#2{\hbox{\kern-0.2pt\vbox{\kern-0.2pt\hrule\hbox{\vrule\kern#1\vbox{%
\kern#1#2\kern#1}\kern#1\vrule}\hrule\kern-0.2pt}\kern-0.2pt}}
\def\hatchpattern{%
\special{pdf: content q 0 G 0.4 w  0   8 m  2  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   6 m  4  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   4 m  6  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   2 m  8  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0   0 m 10  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -2 m 12  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -4 m 14  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -6 m 16  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0  -8 m 18  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  0 -10 m 20  10 l b Q}%
\special{pdf: content q 0 G 0.4 w  2 -10 m 20   8 l b Q}%
\special{pdf: content q 0 G 0.4 w  4 -10 m 20   6 l b Q}%
\special{pdf: content q 0 G 0.4 w  6 -10 m 20   4 l b Q}%
\special{pdf: content q 0 G 0.4 w  8 -10 m 20   2 l b Q}%
\special{pdf: content q 0 G 0.4 w 10 -10 m 20   0 l b Q}%
\special{pdf: content q 0 G 0.4 w 12 -10 m 20  -2 l b Q}%
\special{pdf: content q 0 G 0.4 w 14 -10 m 20  -4 l b Q}%
\special{pdf: content q 0 G 0.4 w 16 -10 m 20  -6 l b Q}%
\special{pdf: content q 0 G 0.4 w 18 -10 m 20  -8 l b Q}}
\def\puzzlebox#1{\boxaround{-0.2pt}{\vbox to 2em{\vfil\hbox to 2em{\hfil%
\ifx?#1$\bigcirc$\else#1\fi\ifcat A#1\hfil\else\hskip0.5em\fi}\vfil}}}
\def\hatchbox{\vbox to 2em{\vfil\hbox to 2em{\hatchpattern\hss}\vfil}}
\def\puzzlesquare#1{\ifx\relax#1\relax\hatchbox\else\puzzlebox{#1}\fi}
\def\puzzlediagram#1{\boxaround{2.2pt}{\offinterlineskip\tabskip=0pt\halign{&\puzzlesquare{##}\cr#1\crcr}}}

现在您可以排版任意大小的图表,例如:

\halign{#\qquad&#\qquad&#\qquad&#\cr
\puzzlediagram{
1&3&8&9\cr
10&6&&4\cr
2&12&5&15\cr
14&7&13&11\cr}&
\puzzlediagram{
1&3&&\cr
&6&&4\cr
2&&5&\cr
&7&&\cr}&
\puzzlediagram{
?&?&A&A\cr
B&?&A&?\cr
?&C&?&D\cr
E&?&D&D\cr}&
\puzzlediagram{
1&3&&\cr
?&6&&4\cr
2&?&5&?\cr
?&7&?&?\cr}
\cr
\hfil(a)\hfil&\hfil(b)\hfil&\hfil(c)\hfil&\hfil(d)\hfil\cr}

得到以下图表:

在此处输入图片描述

相关内容