Como a declaração de justificativa `\everypar` poderia ser usada?

Como a declaração de justificativa `\everypar` poderia ser usada?

@David Purtoncomentou emComo forçar automaticamente o látex a não justificar o texto quando não é sensato?

Em TeX por tópico (eijkhout.net/texbytopic/texbytopic.html) há um exemplo de como fazer com que as linhas de um parágrafo fiquem irregulares se estiverem muito insuficientes. Consulte a seção 5.9.6. Talvez este método seja adequado?

Nesse livro encontrei a página:

insira a descrição da imagem aqui

Refere-se à macro:

\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}

Dentro dele podemos notar o .98número, que deve se referir 98%à linha sendo preenchida com texto e 2%como espaçamento vazio devido à LaTeXjustificação do texto.

Atualmente consegui usá-lo como:

% 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}

Além disso, no texto, ele menciona sobre it can be inserted automatically with \everypar. Porém, não entendo como isso poderia ser feito automaticamente com o \everypar. Até agora eu tentei isso:

\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}

Porém a imagem está saindo vazia. Como a \everypardeclaração poderia ser usada?

Seguindo isso, existe uma maneira confiável/simples de aplicar essa transformação de justificação de texto a todo o texto, em vez de agrupar cada parágrafo em algo como \everypar{ My paragraph 1 text } \n\n \everypar{ My paragraph 2 text }?


Por exemplo, em vez de escrever:

\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}

Basta fazer algo mais direto como:

\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}

E ainda obter os benefícios da justificação inteligente de texto em látex, oferecida para linhas onde justificar o texto não seria agradável?


Atualizar

Depois@barbara-beetoncomentário, acho que isso pode ser feito automaticamente usando as instruções \everypare \par. Então tentei escrever:

\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}

Na esperança de que as declarações \vbox{sejam \par\eatlines\}inseridas no início/fim de cada parágrafo. Porém o latex parece não estar aceitando, pois está gerando o erro:

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.

Responder1

Você deve definir localmente \everypar={}porque \vboxa primeira letra \vboxcomeça no próximo parágrafo, então next \everyparé processado. Ele abre um novo \vboxe novo \everyparé processado, etc... O loop sem fim está aqui. Isso gera um erro de "capacidade do TeX".

Pode ser que você precise de algo assim:

\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

O \setbox0=\lastbox \parin \everyparremove a linha vazia da lista vertical principal ( \lastboxconsome a caixa de recuo e \parfinaliza o parágrafo vazio: nada é adicionado à lista vertical principal). O próximo material é \everyparaberto \vboxe redefinido localmente \parpara processamento \eatlinese \everypar={}é definido aqui localmente devido ao motivo explicado acima.

informação relacionada