如何使用 `\everypar` 论证声明?

如何使用 `\everypar` 论证声明?

@David Purton评论于当不明智的时候,如何自动强制乳胶不对齐文本?

在 TeX 按主题分类 (eijkhout.net/texbytopic/texbytopic.html)有一个示例,如果段落中的行太少,则将其对齐。请参阅第 5.9.6 节。也许这种方法合适?

在那本书上我找到了以下页面:

在此处输入图片描述

它确实引用了宏:

\newbox\linebox \newbox\snapbox
\def\eatlines{
\setbox\linebox\lastbox % check the last line
\ifvoid\linebox
\else % if it’s not empty
\unskip\unpenalty % take whatever is
{\eatlines} % above it;
% collapse the line
\setbox\snapbox\hbox{\unhcopy\linebox}
% depending on the difference
\ifdim\wd\snapbox<.90\wd\linebox
\box\snapbox % take the one or the other,
\else \box\linebox \fi
\fi}

其中我们可能会注意到.98数字,它指的98%是填充了文本的行,以及2%由于LaTeX文本对齐而产生的空白空间。

目前我可以将其用作:

% proposal.tex
% Based on http://www.latextemplates.com/template/simple-sectioned-essay
\documentclass[12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper, margin=2cm]{geometry}
\usepackage[brazil]{babel}

\usepackage{hyphsubst}
\usepackage{mathptmx}

\newbox\linebox \newbox\snapbox
\def\eatlines{
\setbox\linebox\lastbox % check the last line
\ifvoid\linebox
\else % if it’s not empty
\unskip\unpenalty % take whatever is
{\eatlines} % above it;
% collapse the line
\setbox\snapbox\hbox{\unhcopy\linebox}
% depending on the difference
\ifdim\wd\snapbox<.90\wd\linebox
\box\snapbox % take the one or the other,
\else \box\linebox \fi
\fi}

\begin{document}

\section{Riscos}

\indent
\vbox{

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedright setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

\par\eatlines}

\end{document}

此外,在文本中,他确实提到了it can be inserted automatically with \everypar。不过,我不明白如何使用 自动完成\everypar。到目前为止,我尝试过这个:

\begin{document}

\section{Riscos}

\indent
\everypar{

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedright setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

}

\end{document}

但是图片是空的。该\everypar语句如何使用?

接下来,是否有一种可靠/简单的方法将这种文本对齐转换应用于所有文本,而不是将每个段落都包含在某个内容中\everypar{ My paragraph 1 text } \n\n \everypar{ My paragraph 2 text }


例如,不要这样写:

\begin{document}

\section{Riscos}

\indent
\everypar{

    My paragraph 1, In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
}

\medskip
\indent
\everypar{

    My paragraph 2, and raggedright setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.
}

\end{document}

只需做一些更直接的事情:

\begin{document}

\section{Riscos}

My paragraph 1, In typesetting advertisement copy, a way of justifying paragraphs has
become popular in recent years that is somewhere between flushright

\medskip
My paragraph 2, and raggedright setting. Lines that would stretch beyond certain limits
are set with their glue at natural width. This single paragraph is but an
example of this procedure; the macros are given next.

\end{document}

并且仍然可以获得智能乳胶文本对齐的好处,它适用于对齐文本不愉快的行?


更新

@barbara-beeton评论,我认为可以使用\everyparand\par语句自动完成。然后我尝试写:

\begin{document}

\section{Riscos}

\everypar={\indent\vbox\{}
\par={\par\eatlines\}}

% \indent
% \vbox{

    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedright setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

% \par\eatlines}

\end{document}

希望插入每个段落的开始/结束处的语句\vbox{\par\eatlines\}但是 latex 似乎不接受它,因为它抛出了错误:

main2.tex:38: TeX capacity exceeded, sorry [input stack size=5000]. [    I]

main2.tex:33: Missing { inserted. [\par=]
main2.tex:33: Missing { inserted. [\par=]
main2.tex:33: Missing { inserted. [\par=]
main2.tex:33: Missing { inserted. [\par=]
main2.tex:33: Missing { inserted. [\par=]
...
Too many errors. TeX stopped.

答案1

您必须在本地设置\everypar={}\vbox因为 中的第一个字母\vbox开始下一个段落,因此下一个将\everypar被处理。它会打开一个新的\vbox,然后处理新的\everypar,等等……这里是永无止境的循环。这会导致“TeX 容量”错误。

也许,你需要这样的东西:

\newbox\linebox \newbox\snapbox
\def\eatlines{
  \setbox\linebox\lastbox % check the last line
  \ifvoid\linebox
  \else % if it’s not empty
    \unskip\unpenalty % take whatever is
    {\eatlines} % above it;
    \setbox\snapbox\hbox{\unhcopy\linebox}
    \ifdim\wd\snapbox<.98\wd\linebox
       \box\snapbox % take the one or the other,
    \else \box\linebox \fi
  \fi}

\everypar={\setbox0=\lastbox \par 
   \vbox\bgroup \everypar={}\def\par{\endgraf\eatlines\egroup}}


    In typesetting advertisement copy, a way of justifying paragraphs has
    become popular in recent years that is somewhere between flushright
    and raggedright setting. Lines that would stretch beyond certain limits
    are set with their glue at natural width. This single paragraph is but an
    example of this procedure; the macros are given next.

    Second paragraph.

\bye

\setbox0=\lastbox \par\everypar空行从主垂直列表中移除(\lastbox使用缩进框并\par完成空段落:主垂直列表中未添加任何内容)。 中的下一个材料\everypar打开\vbox并在本地重新定义\par以处理您的\eatlines并且\everypar={}由于上述原因在此处本地设置。

相关内容