Plain TeX: Probleme bei \ loop, um Parameter für \ parshape festzulegen

Dec 21 2020

Ich habe versucht, ein Makro zu schreiben, um Text um eine Figur zu wickeln. Mir ist bekannt, dass es in Latex verfügbar ist und es ein weiteres Paket gibt, figflow für plainTex. Ich lerne gerade, meine eigenen zu schreiben. Mein erster Schritt war die Verwendung von \ parshape, um einen leeren Bereich für die Figur zu erstellen. Ich bin hier festgefahren. Ich definiere das Makro wie folgt:

\newcount\ln
\def\wrap#1#2{\parshape=#1 \loop\relax\ifnum\ln<#1 0cm #2 \advance\ln by 1\repeat}

Es funktioniert nicht. Ich habe es versucht \edef, was auch nicht funktioniert hat. Kann mir bitte jemand helfen? Vielen Dank!

\parshape{6}{10cm} Here is the definitive guide to the use of TeX, written by the system's creator, Donald E. Knuth. TeX represents the state of the art in computer typesetting. It is particularly valuable where the document, article, or book to be produced contains a lot of mathematics, and where the user is concerned about typographic quality. TeX software offers both writers and publishers the opportunity to produce technical text of all kinds, in an attractive form, with the speed and efficiency of a computer system. Novice and expert users alike will gain from The TeXbook the level of information they seek. Knuth warns newcomers away from the more difficult areas, while he entices experienced users with new challenges. The novice need not learn much about TeX to prepare a simple manuscript with it. But for the preparation of more complex documents, The TeXbook contains all the detail required. Knuth's familiar wit, and illustrations specially drawn by Duane Bibby, add a light touch to an unusually readable software manual. The TeXbook is the first in a five-volume series on Computers and Typesetting, all authored by Knuth
\bye

Antworten

3 Skillmon Dec 21 2020 at 02:29

Eine Antwort, die eine ziemlich einfache Schleife mit zeigt \numexpr.

Wenn Sie \parshapenur eine bestimmte Anzahl von Zeilen verwenden und möchten, dass diese betroffen sind, müssen Sie eine zusätzliche Zeile hinzufügen 0cm \hsize, um nach Abschluss zu den normalen Zeilen zurückzukehren \parshape, da \parshapedie letzte Angabe für jede verbleibende Zeile des Absatzes wiederholt wird.

\catcode`\@=11
\long\def\@gobble#1{}
\long\def\@secondoftwo#1#2{#2}
\def\wrap#1#2%
  {%
    \parshape=\numexpr#1+1\relax \wrap@{0}{#1}{#2} 0cm \hsize\relax
  }
\def\wrap@#1#2#3%
  {%
    \ifnum#1<#2
      0cm #3
      \expandafter\@secondoftwo
    \fi
    \@gobble{\expandafter\wrap@\expandafter{\the\numexpr#1+1}{#2}{#3}}%
  }
\catcode`\@=12

\wrap{6}{10cm} Here is the definitive guide to the use of TeX, written by the
system's creator, Donald E. Knuth. TeX represents the state of the art in
computer typesetting. It is particularly valuable where the document, article,
or book to be produced contains a lot of mathematics, and where the user is
concerned about typographic quality. TeX software offers both writers and
publishers the opportunity to produce technical text of all kinds, in an
attractive form, with the speed and efficiency of a computer system. Novice and
expert users alike will gain from The TeXbook the level of information they
seek. Knuth warns newcomers away from the more difficult areas, while he entices
experienced users with new challenges. The novice need not learn much about TeX
to prepare a simple manuscript with it. But for the preparation of more complex
documents, The TeXbook contains all the detail required. Knuth's familiar wit,
and illustrations specially drawn by Duane Bibby, add a light touch to an
unusually readable software manual. The TeXbook is the first in a five-volume
series on Computers and Typesetting, all authored by Knuth.
\bye

4 sgmoye Dec 21 2020 at 03:02

Für eine relativ einfache Anwendung wie diese (der Einzug erstreckt sich nur über einen Absatz) bietet einfaches TeX \hangafter(die Anzahl der einzurückenden Zeilen, positiv, wenn von links, negativ, wenn von rechts, wie hier) und \hangindent(positiv, wenn der Einzug) beginnt nach der Zahl die von gegebene Zahl \hangafter, negativ, wenn in Zeile 1) begonnen wird - siehe Knuths The TeXbook , Seite 102.

\hangafter=-6 \hangindent=-6cm
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\bye

Um vollständig zu sein, könnte ein einfaches Makro \wrapdefiniert werden (die Ausgabe ist identisch):

\def\wrap#1#2{\hangafter-#1\hangindent-#2}

\wrap{6}{6cm}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
2 egreg Dec 21 2020 at 03:49

Eine einfache erweiterbare Schleife in expl3; Es ist einfach, die gewünschte Anzahl von Sonderzeilen anzugeben, anstatt eine einzige zu sein.

\input expl3-generic

\ExplSyntaxOn

\cs_new:Npn \wrap #1 #2
 {
  \parshape
    \int_to_arabic:n { #1 + 1 } \c_space_tl % number of special lines
    \prg_replicate:nn { #1 } { 0pt~#2~ } % parameters for the special lines
    0pt~\hsize % further lines
  \ignorespaces
 }

\ExplSyntaxOff

\wrap{6}{10cm} Here is the definitive guide to the use of TeX, written by 
the system's creator, Donald E. Knuth. TeX represents the state of the art 
in computer typesetting. It is particularly valuable where the document, 
article, or book to be produced contains a lot of mathematics, and where 
the user is concerned about typographic quality. TeX software offers both 
writers and publishers the opportunity to produce technical text of all 
kinds, in an attractive form, with the speed and efficiency of a computer 
system. Novice and expert users alike will gain from The TeXbook the level 
of information they seek. Knuth warns newcomers away from the more difficult 
areas, while he entices experienced users with new challenges. The novice 
need not learn much about TeX to prepare a simple manuscript with it. But 
for the preparation of more complex documents, The TeXbook contains all 
the detail required. Knuth's familiar wit, and illustrations specially 
drawn by Duane Bibby, add a light touch to an unusually readable software 
manual. The TeXbook is the first in a five-volume series on Computers and 
Typesetting, all authored by Knuth

\bye

Das Makro \wrapselbst ist erweiterbar, sodass Sie dies tun können

\edef\wrapsix{\wrap{6}{10cm}}

\wrapsix Here is the definitive guide to the use of TeX, written by
the system's creator, Donald E. Knuth. TeX represents the state of the art
in computer typesetting. It is particularly valuable where the document,
article, or book to be produced contains a lot of mathematics, and where
[...]

und definieren Sie zu Beginn verschiedene Formen dieser Art.

1 wipet Dec 21 2020 at 05:00

OpTeX unterstützt erweiterbare \fornumBefehle, daher verwendet ein anderer Ansatz diesen \fonrumBefehl innerhalb von \parshapeParametern. OpTeX ist jedoch kein reines einfaches TeX, sondern erweitertes einfaches TeX:

\def\wrap#1#2{\parshape \numexpr#1+1\relax\space \fornum 1..#1\do{0cm#2}0cm\hsize}

\wrap{6}{10cm}\lipsum[1]
\bye
1 wipet Dec 21 2020 at 04:53

Ein anderer Ansatz ist: Erstellen Sie eine Liste mit \parshapeParametern, bevor Sie \parshapeausgeführt werden. Eine solche Vorbereitung sollte durch einen klassischen (nicht erweiterbaren) Schleifenbefehl erfolgen.

\newcount\tmpnum
\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
\def\wrap#1#2{\tmpnum=0 \def\parshapelist{}
    \loop \addto\parshapelist{0cm#2}\advance\tmpnum by1
          \ifnum\tmpnum<#1 \repeat
    \advance\tmpnum by1
    \parshape \the\tmpnum\space \parshapelist 0cm\hsize
}

\wrap{6}{10cm} Here is the definitive guide to the use of TeX, written by the
system's creator, Donald E. Knuth. TeX represents the state of the art in
computer typesetting. It is particularly valuable where the document, article,
or book to be produced contains a lot of mathematics, and where the user is
concerned about typographic quality. TeX software offers both writers and
publishers the opportunity to produce technical text of all kinds, in an
attractive form, with the speed and efficiency of a computer system. Novice and
expert users alike will gain from The TeXbook the level of information they
seek. Knuth warns newcomers away from the more difficult areas, while he entices
experienced users with new challenges. The novice need not learn much about TeX
to prepare a simple manuscript with it. But for the preparation of more complex
documents, The TeXbook contains all the detail required. Knuth's familiar wit,
and illustrations specially drawn by Duane Bibby, add a light touch to an
unusually readable software manual. The TeXbook is the first in a five-volume
series on Computers and Typesetting, all authored by Knuth.
\bye

Natürlich könnte ein solches konkretes Beispiel gelöst werden, \hangafter=-6 \hangindent=-6cmwie von sgmoye erwähnt. Aber ich nehme an, Sie geben dieses Beispiel nur als Studium des \parshapeVerhaltensmaterials.

Weitere Erklärung, wie es funktioniert: Erstens: \parshapelistwird als leer definiert und der Text 0cm10cm (if #2=10cm) wird an das angehängt \parshapelist. Wir haben 0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm \parshapelistam Ende der Schleife. Nun wird das Grundelement \parshapeverarbeitet:

\parshape 7 0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm\hsize

und es macht die eigentliche Arbeit.

HenriMenke Dec 21 2020 at 02:22

Wie bereits in den Kommentaren erwähnt, \loop...\repeatist nicht erweiterbar und \parshapehört daher auf, die Spezifikation zu lesen. Sie können jedoch eine einfache, vollständig erweiterbare Version von \loopin Plain TeX mit definieren \romannumeral.

Im Wesentlichen läuft der Trick darauf hinaus, dass die größte römische Ziffer mder entspricht \romannumeral1000. Daher \romannumeral2000wird in mmund so weiter verwandelt . Wir können dies (ab) verwenden, um unsere Schleifenvariable \romannumeralin eine Folge von umzuwandeln mund in jeder Iteration eine zu entfernen, bis nichts mehr übrig ist.

Ich habe das Makro aufgerufen \replicate. Es ist nicht so leistungsfähig, \loopweil Sie nicht auf den Schleifenzähler zugreifen können, aber es ist vollständig erweiterbar.

\catcode`@=11

\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\long\def\@gobble#1{}
\def\@ifx#1#2{%
    \ifx#1#2%
      \expandafter\@firstoftwo
    \else
      \expandafter\@secondoftwo
    \fi
}

% replicate
\def\replicate#1{\expandafter\@replicate\romannumeral#1000\relax\relax}
\def\@replicate#1#2#{\@ifx{\relax}{#1}{\@gobble}{\@@replicate{#2}}}
\long\def\@@replicate#1#2{#2\@replicate#1{#2}}

\catcode`@=12

%%% begin document

\def\wrap#1#2{\parshape=#1\replicate{#1}{ 0cm #2}}

\input lorem\par

\wrap{6}{10cm} \input lorem\par

\input lorem\par

\bye