Как можно использовать оператор оправдания `\everypar`?

Как можно использовать оператор оправдания `\everypar`?

@David Purtonпрокомментировал вКак автоматически заставить latex не выравнивать текст, когда это неразумно?

В TeX по теме (eijkhout.net/texbytopic/texbytopic.html) есть пример того, как сделать строки в абзаце raggedright, если они слишком неполные. Смотрите раздел 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}

И при этом получить преимущества интеллектуальной латексной выравнивания текста, предлагаемой для строк, где выравнивание текста было бы неприятным?


Обновлять

После@барбара-битонкомментарий, я думаю, что это можно сделать автоматически с помощью операторов \everyparи \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 capacity".

Возможно, вам нужно что-то вроде этого:

\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

In удаляет пустую строку из основного вертикального списка ( использует поле отступа и завершает пустой абзац: ничего не добавляется в основной вертикальный список). Следующий материал in открывается и локально переопределяется для обработки вашего И устанавливается здесь локально по причине, описанной выше \setbox0=\lastbox \par.\everypar\lastbox\par\everypar\vbox\par\eatlines\everypar={}

Связанный контент