Düz TeX: \ parshape için parametreleri ayarlamak için \ döngüsünde karşılaşılan sorunlar
Bir şeklin etrafına metin sarmak için bir makro yazmaya çalışıyordum. Lateks olarak mevcut olduğunu ve başka bir paket olduğunu biliyorum, PlainTex için figflow. Ben sadece kendim yazmayı öğreniyorum. İlk adımım, şekil için boş bir alan oluşturmak için \ parshape kullanmaktı. Burada sıkışıp kaldım. Makroyu şu şekilde tanımlıyorum:
\newcount\ln
\def\wrap#1#2{\parshape=#1 \loop\relax\ifnum\ln<#1 0cm #2 \advance\ln by 1\repeat}
İşe yaramıyor. Ben de denedim \edef
, bu da işe yaramadı. Lütfen biri yardım edebilir mi? Teşekkürler!
\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
Yanıtlar
İle oldukça basit bir döngü gösteren bir cevap \numexpr
.
Kullandığınız olduğunuzda \parshape
ve çizgilerin sadece belirli sayıda etkilenecek istiyorum, birlikte bir satır daha eklemek zorunda 0cm \hsize
sonra normal hatlara geri almadan etmek \parshape
çünkü yapılır \parshape
paragrafın her kalan çizginin son şartname tekrar edecektir.
\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

Bunun gibi nispeten basit bir uygulama için (girinti yalnızca bir paragrafa uzanır), düz TeX \hangafter
(girintilenecek satır sayısı, soldan ise pozitif, burada olduğu gibi sağdan negatif) ve \hangindent
(girinti ise pozitif ise pozitif ) sayı ile verilen sayıdan sonra başlar \hangafter
, 1. satırdan başlıyorsa negatif) - Knuth'un TeXbook'u , sayfa 102'ye bakın.
\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

Tam olması için, basit bir makro \wrap
tanımlanabilir (çıktı aynıdır):
\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.
Basit bir genişletilebilir döngü girişi expl3
; İstenilen sayıda özel satırı belirtmek bir defaya mahsus olmak yerine kolaydır.
\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

Makronun \wrap
kendisi genişletilebilir, böylece şunları yapabilirsiniz:
\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
[...]
ve başlangıçta bu türden çeşitli şekilleri tanımlayın.
OpTeX genişletilebilir \fornum
komutu destekler , bu nedenle başka bir yaklaşım bu \fonrum
komutu \parshape
parametreler içinde kullanmaktır . Ancak OpTeX, saf düz TeX değildir, düz TeX ile genişletilmiştir:
\def\wrap#1#2{\parshape \numexpr#1+1\relax\space \fornum 1..#1\do{0cm#2}0cm\hsize}
\wrap{6}{10cm}\lipsum[1]
\bye
Diğer bir yaklaşım ise çalıştırılmadan \parshape
önce bir parametre listesi hazırlamaktır \parshape
. Bu tür bir hazırlık, klasik (genişletilemez) döngü komutu ile yapılmalıdır.
\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
Elbette böyle somut bir örnek, \hangafter=-6 \hangindent=-6cm
sgmoye'nin bahsettiği gibi çözülebilir . Ama sanırım bu örneği sadece \parshape
davranış materyali incelemek için veriyorsunuz .
Nasıl çalıştığı hakkında daha fazla açıklama: ilk olarak: \parshapelist
boş olarak tanımlanır ve 0cm10cm (eğer #2=10cm
) metni \parshapelist
. Döngünün \parshapelist
sonunda 0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm var . Şimdi ilkel \parshape
işlenir:
\parshape 7 0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm10cm0cm\hsize
ve gerçek işi yapıyor.
Yorumlarda daha önce belirtildiği gibi \loop...\repeat
genişletilemez ve bu nedenle \parshape
spesifikasyonu okumayı durdurur. Bununla birlikte, \loop
Düz TeX'in basit ve tamamen genişletilebilir bir sürümünü kullanarak tanımlayabilirsiniz \romannumeral
.
Esasen hile, en büyük Roma rakamının m
karşılık gelen olduğu gerçeğine dayanıyor \romannumeral1000
. Dolayısıyla \romannumeral2000
dönüştürülür mm
ve benzeri. Bunu (ab) kullanarak döngü değişkenimizi \romannumeral
bir dizi haline dönüştürmek için kullanabiliriz m
ve hiçbir şey kalmayana kadar her yinelemede birini çıkarabiliriz.
Makroyu aradım \replicate
. \loop
Döngü sayacına erişemediğiniz için o kadar güçlü değildir, ancak tamamen genişletilebilir.
\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