Plain 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
답변
.NET과 함께 매우 기본적인 루프를 보여주는 대답 \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

이와 같은 비교적 간단한 응용 프로그램 (들여 쓰기가 한 단락에만 확장 됨)의 경우 일반 TeX는 \hangafter
(들여 쓰기 할 줄 수, 왼쪽에서 양수, 오른쪽에서 음수, 여기와 같이 \hangindent
양수 ) 및 (들여 쓰기의 경우 양수)를 제공합니다. 에 의해 주어진 숫자 뒤에 \hangafter
시작, 1 행에서 시작하면 음수) — Knuth의 The TeXbook , page 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
; 일회성 대신 원하는 특수 줄 수를 지정하는 것은 쉽습니다.
\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
사용하여 Plain TeX에서 의 단순하고 완전히 확장 가능한 버전을 정의 할 수 있습니다 \romannumeral
.
본질적으로 트릭은 가장 큰 로마 숫자가 m
에 해당 한다는 사실로 귀결 됩니다 \romannumeral1000
. 따라서 \romannumeral2000
로 바뀌 었습니다 mm
. 우리는 이것을 사용하여 루프 변수를 \romannumeral
시퀀스로 변환하고 m
아무것도 남지 않을 때까지 매 반복마다 하나를 제거 할 수 있습니다.
나는 매크로라고 불렀습니다 \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