プレーンTeX:\ loopが\ parshapeのパラメータを設定するときの問題
図形の周りにテキストを折り返すためのマクロを作成しようとしていました。私はそれがLaTeXで利用可能であり、plainTex用のfigflowという別のパッケージがあることを知っています。私は自分で書くことを学んでいます。私の最初のステップは、\ parshapeを使用して図の空白領域を作成することでした。ここで立ち往生しました。マクロを次のように定義します。
\newcount\ln
\def\wrap#1#2{\parshape=#1 \loop\relax\ifnum\ln<#1 0cm #2 \advance\ln by 1\repeat}
それは動作しません。試しましたが\edef
、どちらも機能しませんでした。誰か助けてもらえますか?ありがとう!
\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
回答
でかなり基本的なループを示す答え\numexpr
。
を使用\parshape
していて、特定の行数だけに影響を与えたい場合は、段落の残りの行ごとに最後の指定を繰り返すため、完了0cm \hsize
後に通常の行に戻すために追加の行を追加する必要があります。\parshape
\parshape
\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

このような比較的単純なアプリケーション(インデントが1段落のみに及ぶ)の場合、プレーンTeXは\hangafter
(インデントする行数、左からの場合は正、右からの場合は負)および\hangindent
(インデントの場合は正)を提供しますで指定された番号の後に開始し、\hangafter
1行目から開始する場合は負になります)—KnuthのTheTeXbook、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

完全を期すために、単純なマクロを\wrap
定義できます(出力は同じです)。
\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.
expl3
;の単純な拡張可能なループ。1回限りではなく、必要な数の特別な行を指定するのは簡単です。
\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

マクロ\wrap
自体は拡張可能であるため、次のことができます。
\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
[...]
最初にこの種のさまざまな形状を定義します。
OpTeXは拡張可能な\fornum
コマンドをサポートしているため、別のアプローチはパラメーター\fonrum
内でこのコマンドを\parshape
使用することです。しかし、OpTeXは純粋なプレーンTeXではなく、拡張されたプレーン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
別のアプローチは、実行\parshape
する前にパラメーターのリストを準備\parshape
することです。このような準備は、従来の(拡張不可能な)ループコマンドで実行する必要があります。
\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
もちろん、そのような具体的な例は\hangafter=-6 \hangindent=-6cm
、sgmoyeが述べたように解決できます。しかし、あなたはこの例を\parshape
行動の材料を研究するためだけに与えていると思います。
詳細な説明、仕組み:first:\parshapelist
は空として定義され、テキスト0cm10cm(if #2=10cm
)がに追加されます\parshapelist
。\parshapelist
ループの終わりに0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cmがあります。これで、プリミティブ\parshape
が処理されます。
\parshape 7 0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm\hsize
そしてそれは実際の仕事をします。
コメントですでに述べたように、\loop...\repeat
拡張可能ではないため\parshape
、仕様の読み取りを停止します。ただし、単純な、完全に拡張可能なバージョンを定義することができます\loop
使用して平野TeXのでは\romannumeral
。
基本的に、トリックは、最大のローマ数字がm
に対応するという事実に要約され\romannumeral1000
ます。したがって\romannumeral2000
になっているmm
とになります。これを(ab)使用して、を使用するループ変数を\romannumeral
のシーケンスに変換し、m
何も残らなくなるまで反復ごとに1つを取り除くことができます。
私はマクロと呼んでい\replicate
ます。\loop
ループカウンターにアクセスできないため、それほど強力ではありませんが、完全に拡張可能です。
\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