添加

添加

在此輸入影像描述在此輸入影像描述我正在嘗試排版一些舊書,其中我注意到所有數字都被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

在此輸入影像描述

相關內容