From b4df43b01f87525a054a54e5799fb7d0c57f6b7e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 30 Sep 2024 14:38:36 -0700 Subject: [PATCH] LaTeX writer: better fix for lists in definition lists. In commit a26ec96d89ccf532f7bca7591c96ba30d8544e4a we added an empty `\item[]` to the beginning of a list that occurs first in a definition list, to avoid having one item on the line with the label. This gave bad results in some cases (#10241) and there is a more idiomatic solution anyway: using `\hfill`. Closes #10241. --- src/Text/Pandoc/Writers/LaTeX.hs | 11 ++++++----- test/command/lists-inside-definition.md | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index edbc40aafc64..69917b3d9973 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -526,10 +526,11 @@ blockToLaTeX (BulletList lst) = do let spacing = if isTightList lst then text "\\tightlist" else empty - return $ text ("\\begin{itemize}" <> inc) $$ + return $ -- force list to start on new line if in a defn list + (if isFirstInDefinition then "\\hfill" else mempty) $$ + text ("\\begin{itemize}" <> inc) $$ spacing $$ -- force list at beginning of definition to start on new line - (if isFirstInDefinition then "\\item[]" else mempty) $$ vcat items $$ "\\end{itemize}" blockToLaTeX (OrderedList _ []) = return empty -- otherwise latex error @@ -577,12 +578,12 @@ blockToLaTeX (OrderedList (start, numstyle, numdelim) lst) = do let spacing = if isTightList lst then text "\\tightlist" else empty - return $ text ("\\begin{enumerate}" <> inc) + return $ -- force list at beginning of definition to start on new line + (if isFirstInDefinition then "\\hfill" else mempty) + $$ text ("\\begin{enumerate}" <> inc) $$ stylecommand $$ resetcounter $$ spacing - -- force list at beginning of definition to start on new line - $$ (if isFirstInDefinition then "\\item[]" else mempty) $$ vcat items $$ "\\end{enumerate}" blockToLaTeX (DefinitionList []) = return empty diff --git a/test/command/lists-inside-definition.md b/test/command/lists-inside-definition.md index e5c6e83c6554..731cd10d3d7b 100644 --- a/test/command/lists-inside-definition.md +++ b/test/command/lists-inside-definition.md @@ -12,10 +12,10 @@ Definition \begin{description} \tightlist \item[Definition] +\hfill \begin{enumerate} \def\labelenumi{\arabic{enumi}.} \tightlist -\item[] \item list \item @@ -56,9 +56,9 @@ Definition \begin{description} \tightlist \item[Definition] +\hfill \begin{itemize} \tightlist -\item[] \item list \item