Open blumens opened 1 year ago
Basically \hangindent
is a low-level primitive which is a simplified version of another low-level primitive \parshape
, ie only one of them can be active at a given time. Neither of them is supported LaTeX syntax at the document level, that is they should not be used by users.
LaTeX uses \parshape
together with a redefinition of \par
to build all of its display environments and ther left and right margin indentation, ie all lists, theorems, center quote, etc. If you set up \hangindent
or \parshape
on the document level the way you did and this is directly followed by any display environment (without a \par
before that display) then LaTeX interprets the special shape as something that was set up on the outside and should be restored after the display --- this is how nested lists or quote set up nested indentations.
This is why you see a repeat of your setting after the display. (inside the display you don't see it because there LaTeX's \parshape
setting overwrites it.)
Resolution:
Does this mean there is no supported way to change the parshape at all? Which means that all packages like lettrine or wrapfig are a priory buggy?
no it means that they know what they are doing and account for LaTeX's handling of parshape (or if they don't know then yes they end up being buggy ... but not those two)
correction ... lettrine has the same issue it seems, perhaps we have to take a closer look at this after all
Your answer suggests that there is a supported way to change the parshape. I suppose the only documentation is in source2e?
lettrine explicitly mentions the issue in its documentation
If a list has to be included in a paragraph starting with \lettrine, it is necessary to add the command \parshape=0 just after the end of the list (starting a new paragraph just before or just after the list works too). Remember that ‘quote’, ‘quotation’, ‘abstract’ environments are implemented as lists in LaTeX.
I took a quick look at source2e and \parshape is mentioned only three times. I could not find any explanation of its use in list environments (only the raw tex code). So if you decide that the behaviour is as intended, could you please add some explanation to the documentation?
page 712 has pseudo code for lists (in which parshape is used). This usage dates back to LaTeX 2.09 ie before 1990.
The problem is basically this: if you use your own parshape or hangindent and your current paragraph ends inside a group (which is the case if you go \begin{theorem}
or \begin{itemize}
because \begin
starts a group and only then the environment issues a \par
in its code) then the parshape gets reset at this \par
but given that happens in a group it is restored after the group, which explains why you see your hangindent after the theorem ended again.
Your answer suggests that there is a supported way to change the parshape. I suppose the only documentation is in source2e?
not for authors on document level or at least nothing other than using the generic list environment, but not with respect to something like hangindent. lettrine for example builds a special parshape taking into account it is is already inside some display like quote or itemize. But the basic problem outlined above remains (which is why lettrine documents it). This is as I said very old code and I must confess I had forgotten about this low-level TeX dependency, ie the way it restores these parshapes.
Done a bit more analysis: wrapfig handles the situation gracefully, by canceling the cutout even if the next \par
happens in a group, but Donald's approach is rather complicated. lettrine
uses the simpler solution of documenting it as a limitation as Ulrike mentioned.
Providing a general interface for this from the LaTeX kernel side, is not impossible but rather heavy on resources and it wouldn't resolve the general issue that something like \hangindent
doesn't work in other situations either, e.g., try your setting inside of a list environment or inside quote
. So my guess is that we aren't going to spend time on this, at least not anytime soon. But I'll keep it open because it is a somewhat interesting challenge (not to directly support the low-level \hangindent
but perhaps to provide a more LaTeX like interface one day).
However, for now use the advice given in lettrine
if you want to cut holes the way you did and add \parshape=0
after a following list to prevent the cutout from reappearing there.
Brief outline of the bug
When putting a theorem in a paragraph that uses \hangindent, the indent is also applied to the part of the paragraph after the theorem. This happens both with plain latex and with the amsthm package.
I'm not sure this is intended behaviour: either the text after the theorem is considered to be part of the same paragraph, in which case it should be indented in accordance to its line number in the whole paragraph, or it is considered to be a new paragraph, in which case \hangindent and \hangafter should be reset.
Of course backwards compatibility might make it impossible to change the current behaviour.
Minimal example showing the bug
Log file (required) and possibly PDF file