latex3 / latex2e

The LaTeX2e kernel
https://www.latex-project.org/
LaTeX Project Public License v1.3c
1.88k stars 261 forks source link

improper prevdepth with list, \paragraph and \newpage #553

Open u-fischer opened 3 years ago

u-fischer commented 3 years ago

Brief outline of the bug

The following errors with a improper prevdepth. The quote environment stands for an arbitrary list, the original document used the addmargin environment from the KOMA class, which is based on a list too.

! Improper \prevdepth.
\newpage ...everypar {}\fi \par \ifdim \prevdepth 

Removing the prevdepth test from newpage doesn't help, then one gets a missing item error.

Minimal example showing the bug

\RequirePackage{latexbug} 
\documentclass{article}

\begin{document}

a

\begin{quote}

\paragraph{Übersicht}
abc

\newpage 

blb
\end{quote}

\end{document}

Log file (required) and possibly PDF file

prevdepthbug.log

u-fischer commented 3 years ago

The problem is that the \everypar from \paragraph overwrites the \everypar from the internal item, and so \@newlistfalse is never executed. If one adds this, it compiles:

\RequirePackage{latexbug}
\documentclass{article}

\begin{document}

a

\begin{quote}

\paragraph{Übersicht}
abc\makeatletter \global\@newlistfalse \makeatother

\newpage

blb
\end{quote}

\end{document}

A similar question (with a \paragraph in an abstract) came up here https://tex.stackexchange.com/q/594782/2388

FrankMittelbach commented 3 years ago

It complies, yes but it doesn't compile correctly. Just try

\documentclass{article}

\begin{document}

a

\begin{itemize}
\item
\paragraph{Übersicht}
abc\makeatletter \global\@newlistfalse \makeatother

\newpage

blb
\end{itemize}

\end{document}

and you will see that the itemize bullet got lost. It is not just the newlist boolean that is not executed but the whole everypar code for the list that gets overwritten. I know that \paragraph is often used for its visual effect but it is still questionable if that is valid input or not in the first place. If you want to make it valid input then you have to combine both usages of \everypar so that they know about each other rather than overwriting itself. That mean coordination beyond setting the boolean to false.

u-fischer commented 3 years ago

But I wouldn't use \paragraph in a itemize ;-). I mean itemize is a semantically meaningfull environment and I quite agree that to use a heading there is dubious at the best and if a bullet gets lost I would call it wrong usage.

But abstract, quote, center, flushright, addmargin are not lists in this semantical sense. They only use list code to produce a certain visual effect and the label of their one \item is invisible. So why should a quote not start with heading? Imho it would make sense if headings don't fall over if used in such environments.

FrankMittelbach commented 3 years ago

right, given that list environments are kind of misused for visiual effects it makes sense to support that, all I'm saying it takes much more than setting newlist --- it needs full coordination between the different usages of \everypar. For example, the the inminipage boolean setting is also lost. I only used the itemize example because it shows a clear effect without the need to construct a complicated MWE.

car222222 commented 3 years ago

The question is more: do we have any concept of 'validity'? Without that there is no point in using the word or asking what is valid input.

"but it is still questionable if that is valid input or not in the first place."

FrankMittelbach commented 3 years ago

But I wouldn't use \paragraph in a itemize ;-). I mean itemize is a semantically meaningfull environment

but so is abstract and using a standard heading inside is wrong here imho even if Chris is challenging that this is not formally defined and LaTeX classes do not have formal DTDs. But if you turn on heading numbering \paragraph out of sequence will give you strange numbering as they are expected to be nested in each other.

Anyhow, that doesn't resolve the issue that LaTex istelf uses trivlist just for changing the measure and so that part should preferably supported (but as mentioned that is not trivial and any change in that area would need to be propgated to a lot of packages that are currently based on the exact code and will undo it again unless altered as well.

u-fischer commented 3 years ago

but so is abstract and using a standard heading inside is wrong here

Hm. But abstract does itself use a standard heading: \section*{\abstractname}. Using \paragraph is a bit jumping the levels, and using \paragraph* would be a bit better, but beside this, I don't see why headings should be out of bounds.

Anyhow, that doesn't resolve the issue that LaTex istelf uses trivlist just for changing the measure and so that part should preferably supported (but as mentioned that is not trivial

Yes a full solution is not trivial, but perhaps one could at least add the switch to the heading commands.

car222222 commented 3 years ago

'abstract' is a rather illusive! In the standard classes it becomes a section* only with the ‘twocolumn’ option’s setup, otherwise it uses the direct (and strange) formatting of center.

Out on the streets, it is no doubt formatted in many different ways: some direct and others via 'role mapping' to some other logical structure type.

All very messy!

car222222 commented 3 years ago

Oh yes, the 'trivlist' problem is highly non-trivial.

It is a very bad solution to making some ( or all) aspects of paragraph formatting 'work with' actual 'block lists'.

We are about to have to revolutionise the whole area of (all meanings of) paragraph: structural, semantic, logical, visual (many aspects thereof), etc.

Thus it is now therefore also a good time to deal sensibly with trivlist-related problems, together with other problematic areas such as justification.

Big compatibility problems are looming! I do not think that it is very useful right now to just 'patch common usages' (or misuses, 'valid' and invalid:-).

car222222 commented 3 years ago

Gong back to the original example.

What could/should be the result of the following (not unreasonable) usage (where quote is used just for the narrower text width)?

\begin{quote}
\paragraph{Etwas anderes}

Error?

FrankMittelbach commented 3 years ago

Depends on how you look at it. There could be a real "quote" that contains headings, but then the headings should not be formatted in the heading sequence of the document (if you are quoting something), so for that use case LaTeX is missing ways to encode it.

But more likely it is a real misuse making use of "quote" to mean "get me a certain visual result", i.e., all text here should be made narrower. Again LaTeX is missing formatting possibilities for that, ie \begin{narrower}.

Another question you can ask: should headings inside (real) lists be allowed at all? or is that invalid usage?, e.g. if you replace quote by \begin{itemize} \item \paragraph{... That works if the \paragraphcomes a little later, but imho it is wrong throughout.