2

I'm trying to use \everypar{\hang\setbox0=\lastbox} to set a glossary (instead of prepending every entry with \hang\noindent). It works fine if everything is in the same font, but if I try to set the headword in a different font the hang paragraphing breaks:

{\everypar{\hang\setbox0=\lastbox}
H\&J: Hyphenation and Justification. H\&J rules control how text is typeset into lines of type, how words are broken at line ends and whether the column edges are ragged or straight (justified).

Hairline: Thin printed line, usually 0.25 or 0.5 points thick.

{\it Half-title:} Normally in a hardback book, the first printed page, containing only the title of the book. Can also be used for a similar page appearing later in the prelims. Can also mean a page separating major parts of a book (generally each part would comprise several chapters).

Half-title verso: The page following the half-title. It often contains a list of other books by the same author.

}

I've noticed a similar problem with this \vp macro that I found here: https://www.ctan.org/tex-archive/macros/plain/contrib/misc/paragraphs.tex. I use it in heading macros to suppress the first paragraph indent after a heading.

\def\unindent {%
  \setbox0=\lastbox}     

\def\vp {%
  \everypar{\unindent\everypar{}}}

\vp

{\it First} paragraph. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Second Paragraph. 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.

Third Paragraph. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Because the first word of the first paragraph is in a different font, both the first and the second paragraphs lose their indents. This macro also uses \everypar and \setbox0=\lastbox.

Does anyone know how to fix this?

3

The \everypar tokens are inserted when something triggers the start of a paragraph. In the case of {\it First} it is F. Hence \hang is issued in a group and the ending of the group nullifies its effect. Do

\leavevmode{\it First}

enter image description here

0

egreg already described what is causing this, so there is an easy way to make your \everypar immune to this: Make the \hang \global:

\everypar{\global\hang\setbox0=\lastbox}
  • This consumes two cells of the save stack per call of \everypar, so it can make TeX to run out of memory. Well, on my current distribution this happens after 39979 paragraphs, but… – egreg Mar 16 '18 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.