2

Consider the file mwe1.tex containing

\documentclass{article}
\usepackage{microtype}
\newcommand{\myStretch}{1.02em}%%% try out .99em to see the difference in the first item.
\hyphenation{longlong}
\begin{document}%
\begin{enumerate}
\item A longlong longlong longlong longlong longlong longlong longlong longlong longlong longlong longlong multi-line item that needs a positive \texttt{\textbackslash emergencystretch}.\begingroup\setlength{\emergencystretch}{\myStretch}\par\endgroup
\item There are many \ldots
\end{enumerate}
\end{document}

and a very similar file mwe2.tex containing

\documentclass{article}
\usepackage{microtype}
\newcommand{\myStretch}{1.02em}%%% try out .99em to see the difference in the first item.
\hyphenation{longlong}
\begin{document}%
\begin{enumerate}
\item\setlength{\emergencystretch}{\myStretch}A longlong longlong longlong longlong longlong longlong longlong longlong longlong longlong longlong multi-line item that needs a positive \texttt{\textbackslash emergencystretch}.%
\item\setlength{\emergencystretch}{0sp}There are many \ldots
\end{enumerate}
\end{document}

The bare texts are the same; the only difference are the formatting commands to avoid the first item running into the right margin.

Running pdflatex on each file and comparing the results via diffpdf visually yields a discrepancy, here viewed at 8-fold magnification:

\emergencystretch=1.02em and diffpdf at 8x

As we see, both the “A” in the first item and the “T” in the second item in mwe2.pdf start more to the right than in mwe1.pdf (the leftmost serifs are more visible in mwe2.pdf than in mwe1.pdf). Though the visual difference is small in this particular minimal working example, it raises the question, which of the two ways to avoid list items running into the margin is correct™ in general, i.e., how it is supposed to be? And why? Where do these “A” and “T” have to start?

Further, if we change \myStretch from 1.02em to .99em in both input files and rerun pdflatex on each of the two files, the first item gets typeset with an overfull \hbox in mwe1.pdf but not in mwe2.pdf:

\emergencystretch=.99em and diffpdf at 2x

Why?

4
  • That's the effect of protrusion.
    – egreg
    Commented Nov 22, 2023 at 23:26
  • @egreg Thank you! I've just repaired the order of the input sources (the inputs were swapped previously and didn't match the screenshots); now everything should match. Assuming that we wish to keep microtype, which of the two ways would we use to set \emergencystretch or perhaps use a third, new way?
    – user292998
    Commented Nov 23, 2023 at 14:34
  • 1
    I like to use the {\setlength{\emergencystretch}{...}\par} way, probably hidden in a macro with a very distinctive name, such as \FIXPAR or similar.
    – egreg
    Commented Nov 23, 2023 at 14:38
  • @egreg Thank you!
    – user292998
    Commented Nov 23, 2023 at 20:06

1 Answer 1

2

microtype patches the item command to enable protrusion there, this patch has to look ahead. If you put a command directly behind the \item you are interupting the patch.

In the following example I'm using a quote as this makes the effect more visible, but you get a small difference with A too.

\documentclass{article}
\usepackage{microtype,tikz}
\newcommand{\myStretch}{1.02em}%%% try out .99em to see the difference in the first item.
\hyphenation{longlong}
\begin{document}%
\begin{enumerate} %patch missing
\item\setlength{\emergencystretch}{\myStretch}``A 
\end{enumerate}

\begin{enumerate} %patch working
\item ``A\setlength{\emergencystretch}{\myStretch} 
\end{enumerate}

\microtypesetup{nopatch=all} %disable patch
\begin{enumerate}
\item ``A 
\end{enumerate}

\begin{enumerate}
\item \tikz[overlay]{\draw[red](0,0)--++(0,10cm)}
\end{enumerate}

\end{document}

enter image description here

1
  • Thank you! I've just repaired the order of the input sources (the inputs were swapped previously and didn't match the screenshots); now everything should match. Assuming we wish to keep the protrusion of microtype, is it correct™ to put setlength{\emergencystretch}{…} anywhere except directly after \item? One option could be what we have in the current mwe1.tex, another could be at the very end of both items (cf. pastebin.com/raw/sh1hWmcD ) .
    – user292998
    Commented Nov 23, 2023 at 14:45

You must log in to answer this question.