Skip to content

Commit

Permalink
LaTeX writer: better fix for lists in definition lists.
Browse files Browse the repository at this point in the history
In commit a26ec96 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.
  • Loading branch information
jgm committed Sep 30, 2024
1 parent 4b38cbb commit b4df43b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/Text/Pandoc/Writers/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/command/lists-inside-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Definition
\begin{description}
\tightlist
\item[Definition]
\hfill
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item[]
\item
list
\item
Expand Down Expand Up @@ -56,9 +56,9 @@ Definition
\begin{description}
\tightlist
\item[Definition]
\hfill
\begin{itemize}
\tightlist
\item[]
\item
list
\item
Expand Down

0 comments on commit b4df43b

Please sign in to comment.