![添加](https://linux22.com/image/353563/%E6%B7%BB%E5%8A%A0.png)
我正在尝试排版一本旧书,我注意到其中的所有数字都用 1 个点包围(除非它是一行中的第一个,在这种情况下前面没有点,或者它是一行中最后一个,在这种情况下后面没有点)。如果存在,则该点位于正常的单词间空间内(好像它本身不占用空间)。
有没有办法在(lua)TEX(我使用上下文)中以这种方式排版数字?
我尝试过非常简单的方法,但是它不会丢弃行首或行末的点,而且我猜如果胶水收缩太多也会出现问题。
\starttext
\dorecurse{100}{
Le \llap{.}1\rlap{.} element. }
\stoptext
已尝试cleaders
(可丢弃)但点位于中心(并且不靠近数字)并且似乎没有像我预期的那样伸展。
添加了用于说明的图片。这显示了行尾的点被丢弃,但数字周围的间距仍然太大。
旧版印刷术示例(法语版 Olivetan 圣经,pdf 可从http://www.e-rara.ch/gep_g/content/titleinfo/1751440如果你喜欢哥特式字体。从书上很难看出间距是多少。
答案1
\leaders
两个跳过(和非)的组合顺序\leaders
并不重要:它们始终会作为一个单元消失。
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\makeatletter
\newsavebox\@NWD@dot@box
\newlength\@NWD@space@skip
\newcommand*\numberwithdots[1]{%
\unskip
\setbox\@NWD@dot@box \hbox{.}% use current font
\@NWD@space@skip
\fontdimen\tw@ \font
\@plus \fontdimen\thr@@ \font
\@minus \fontdimen 4 \font
\hskip \glueexpr \@NWD@space@skip-\wd\@NWD@dot@box
\cleaders \copy\@NWD@dot@box \hskip \wd\@NWD@dot@box
#1%
\cleaders \copy\@NWD@dot@box \hskip \wd\@NWD@dot@box
\hskip \glueexpr \@NWD@space@skip-\wd\@NWD@dot@box
\ignorespaces
}
\makeatother
\begin{document}
\numberwithdots{1} note that the indent does \emph{not} count as a ``begin of
line'': not sure if this is what is wanted. Some text \numberwithdots{2} that
includes \numberwithdots{3} some numbers: I~hope that \numberwithdots{4} some
\numberwithdots{5} of them will fall \numberwithdots{6} on a line boundary,
although \numberwithdots{7} it is \numberwithdots{8} always possible
\numberwithdots{9} to arrange things in order \numberwithdots{10} to make
\numberwithdots{11} this happen. And it \numberwithdots{12} is also
possible\linebreak[4] \numberwithdots{13} to force \numberwithdots{14} a line
\numberwithdots{15} break\linebreak[4] at a specific \numberwithdots{16}
position.
Two numbers in a row, though, do not \numberwithdots{123} \numberwithdots{456}
look well.
\end{document}
这是我得到的输出:
添加
或许,在带点的数字周围使用更宽的空间会更好;并且允许用户自定义这方面会更好。
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\makeatletter
\newsavebox\@NWD@dot@box
\newlength\@NWD@space@skip
\newcommand*\@NWD@factor{1.5} % redefine default as you please
\newcommand*\numberwithdots[1]{%
\unskip
\setbox\@NWD@dot@box \hbox{.}% use current font
\@NWD@space@skip
\@NWD@factor\fontdimen\tw@ \font
\@plus \fontdimen\thr@@ \font
\@minus \fontdimen 4 \font
\hskip \glueexpr \@NWD@space@skip-\wd\@NWD@dot@box
\cleaders \copy\@NWD@dot@box \hskip \wd\@NWD@dot@box
#1%
\cleaders \copy\@NWD@dot@box \hskip \wd\@NWD@dot@box
\hskip \glueexpr \@NWD@space@skip-\wd\@NWD@dot@box
\ignorespaces
}
\newcommand*\nwdsetdotspacing[1]{\def\@NWD@factor{#1}}
\newcommand*\nwdlinebreak{\unskip\unskip\linebreak}
\makeatother
\begin{document}
\numberwithdots{1} note that the indent does \emph{not} count as a ``begin of
line'': not sure if this is what is wanted. Some text \numberwithdots{2} that
includes \numberwithdots{3} some numbers: I~hope that \numberwithdots{4} some
\numberwithdots{5} of them will fall \numberwithdots{6} on a line boundary,
although \numberwithdots{7} it is \numberwithdots{8} always possible
\numberwithdots{9} to arrange things in order \numberwithdots{10} to make
\numberwithdots{11} this happen. And it \numberwithdots{12} is also
possible\nwdlinebreak[4] \numberwithdots{13} to force \numberwithdots{14} a line
break \numberwithdots{15}\nwdlinebreak[4] at a specific \numberwithdots{16}
position.
Two numbers in a row, though, do not \numberwithdots{123} \numberwithdots{456}
look well.
\nwdsetdotspacing{} % empty argument amounts to 1
\numberwithdots{1} note that the indent does \emph{not} count as a ``begin of
line'': not sure if this is what is wanted. Some text \numberwithdots{2} that
includes \numberwithdots{3} some numbers: I~hope that \numberwithdots{4} some
\numberwithdots{5} of them will fall \numberwithdots{6} on a line boundary,
although \numberwithdots{7} it is \numberwithdots{8} always possible
\numberwithdots{9} to arrange things in order \numberwithdots{10} to make
\numberwithdots{11} this happen. And it \numberwithdots{12} is also
possible\nwdlinebreak[4] \numberwithdots{13} to force \numberwithdots{14} a line
break \numberwithdots{15}\nwdlinebreak[4] at a specific \numberwithdots{16}
position.
\nwdsetdotspacing{2}
\numberwithdots{1} note that the indent does \emph{not} count as a ``begin of
line'': not sure if this is what is wanted. Some text \numberwithdots{2} that
includes \numberwithdots{3} some numbers: I~hope that \numberwithdots{4} some
\numberwithdots{5} of them will fall \numberwithdots{6} on a line boundary,
although \numberwithdots{7} it is \numberwithdots{8} always possible
\numberwithdots{9} to arrange things in order \numberwithdots{10} to make
\numberwithdots{11} this happen. And it \numberwithdots{12} is also
possible\nwdlinebreak[4] \numberwithdots{13} to force \numberwithdots{14} a line
break \numberwithdots{15}\nwdlinebreak[4] at a specific \numberwithdots{16}
position.
\end{document}
不幸的是,由于技术原因,为了强制换行,我们还必须\linebreak
用我们的命令替换该命令\nwdlinebreak
。
输出:
额外的自由度:也是退格量的一个因素。除此之外,以下代码摘录提供了另一种更强大的实现方式:
\makeatletter
% Alternative approach that permits nesting: use temporaries, but with grouping:
\newcommand*\@NWD@dot@factor{}
\newcommand*\@NWD@spc@factor{1.5}
\newcommand*\numberwithdots[1]{%
\unskip
\setbox\z@ \hbox{.}% use current font
\dimen@ \@NWD@dot@factor\wd\z@
\skip@
\@NWD@spc@factor\fontdimen\tw@ \font
\@plus \fontdimen\thr@@ \font
\@minus \fontdimen 4 \font
% More elegant with subroutines (or perhaps not):
\@NWD@nonleader@hskip \@NWD@leader@hskip
{#1}%
\@NWD@leader@hskip \@NWD@nonleader@hskip
\ignorespaces
}
\newcommand*\@NWD@nonleader@hskip{%
\hskip \glueexpr \skip@-\dimen@ \relax % for robustness
}
\newcommand*\@NWD@leader@hskip{%
\cleaders \copy\z@ \hskip \wd\z@
}
\newcommand*\nwdsetdotspacing[2][]{%
\def\@NWD@dot@factor{#1}%
\def\@NWD@spc@factor{#2}%
}
\newcommand*\nwdlinebreak{\unskip\unskip\linebreak}
\makeatother
进一步阅读
将方框放入一团胶水中\leaders
,以便使其在换行符或分页符处消失,这种技巧众所周知:据我所知,它是由 Marcin Woliński 于 2007 年首次提出的,请参阅如何让换行符处的框消失。
也可以看看:
答案2
\input expl3-generic % just for not using ConTeXt
\ExplSyntaxOn
\cs_set_eq:NN \dorecurse \prg_replicate:nn
\ExplSyntaxOff
\def\num#1{\unskip\adddot#1\adddot\ignorespaces}
\def\adddot{%
\cleaders\hbox to 1.5\dimexpr\fontdimen2\font-\fontdimen4\font\relax{\hss.\hss}%
\hskip1.5\fontdimen2\font plus \fontdimen3\font minus \fontdimen4\font
}
\dorecurse{100}{The \num{2} element \num{2} xy. }
\bye
如果将句点附加到数字上,那就更简单了。
\input expl3-generic
\ExplSyntaxOn
\cs_set_eq:NN \dorecurse \prg_replicate:nn
\ExplSyntaxOff
\newbox\periodbox
\def\num#1{\leavevmode\addleftdot#1\addrightdot}
\def\addleftdot{%
\setbox\periodbox=\hbox{.}%
\cleaders\copy\periodbox\hskip\wd\periodbox\relax
}
\def\addrightdot{%
\setbox\periodbox=\hbox{.}%
\cleaders\copy\periodbox\hskip\wd\periodbox\relax
}
\dorecurse{100}{The \num{2} element \num{2} xy. }
\bye