Zusatz

Zusatz

Bildbeschreibung hier eingebenBildbeschreibung hier eingebenIch versuche, ein altes Buch zu setzen, in dem mir auffällt, dass alle Zahlen von einem Punkt umgeben sind (außer wenn sie die erste in einer Zeile sind, in diesem Fall steht davor kein Punkt, oder wenn sie die letzte in einer Zeile ist, in diesem Fall steht danach kein Punkt). Wenn vorhanden, befindet sich der Punkt innerhalb des normalen Wortzwischenraums (als würde er allein keinen Raum einnehmen).

Gibt es in (Lua)TEX (ich verwende Kontext) eine Möglichkeit, Zahlen auf diese Weise zu setzen?

Ich habe es auf eine sehr naive Art versucht, aber dabei werden die Punkte am Anfang oder Ende der Zeilen nicht verworfen und ich vermute, dass es auch Probleme gibt, wenn der Kleber zu stark schrumpft.

\starttext

\dorecurse{100}{
Le \llap{.}1\rlap{.} element. }

\stoptext

Habe es versucht cleaders(was verwerflich ist), aber die Punkte sind zentriert (und nicht in der Nähe der Ziffer) und scheinen sich nicht so zu dehnen, wie ich es erwartet hätte.

Bild zur Veranschaulichung hinzugefügt. Dies zeigt, dass die Punkte am Ende der Zeilen verworfen werden, aber immer noch zu viel Abstand um die Zahlen herum besteht.

Beispiel für alte Typografie (Olivetan French Bible, pdf verfügbar unterhttp://www.e-rara.ch/gep_g/content/titleinfo/1751440wenn Sie gotische Typografie mögen. Aus dem Buch lässt sich nicht leicht ersehen, wie groß der Abstand ist.

Antwort1

Die Reihenfolge, in der Sie die beiden Sprünge (den \leadersund den Nicht- \leaderseins) kombinieren, spielt keine Rolle: Sie verschwinden immer als Einheit.

% 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}

Dies ist die Ausgabe, die ich erhalte:

Ausgabe des Codes

Zusatz

Vielleicht wäre es besser, größere Abstände um Zahlen mit Punkten zu verwenden. Und es wäre noch besser, dem Benutzer die Möglichkeit zu geben, diesen Aspekt anzupassen.

% 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}

Leider mussten wir aus technischen Gründen, um einen Zeilenumbruch zu erzwingen, den \linebreakBefehl auch durch unseren ersetzen \nwdlinebreak.

Ausgabe:

Ausgabe des zweiten Codebeispiels

Ein zusätzlicher Freiheitsgrad: ein Faktor, der auch die Backspacing-Menge beeinflusst. Darüber hinaus stellt der folgende Codeausschnitt eine alternative und robustere Implementierung dar:

\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

Weiterführende Literatur

Der Trick, eine Box in einen Klecks Klebstoff einzufügen \leaders, um sie bei Zeilen- oder Seitenumbrüchen verschwinden zu lassen, ist wohlbekannt: Soweit ich weiß, wurde er erstmals 2007 von Marcin Woliński vorgeschlagen, sieheSo lässt du ein Kästchen bei einem Zeilenumbruch verschwinden.

Siehe auch:

Antwort2

\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

Bildbeschreibung hier eingeben

Wenn der Punkt an die Zahl angehängt werden soll, ist es sogar noch einfacher.

\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

Bildbeschreibung hier eingeben

verwandte Informationen