From 2d244c7180a18801ebdf82ae3c8dcee078d9f4e4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 2 Oct 2026 09:44:02 -0700 Subject: [PATCH] LaTeX writer: allow alt text in figure to wrap. Closes #11924. --- src/Text/Pandoc/Writers/LaTeX.hs | 3 ++- test/Tests/Writers/LaTeX.hs | 4 ++-- test/command/5116.md | 9 ++++++--- test/command/6821.md | 3 ++- test/command/7181.md | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 5a06c6e2e..e02b96565 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -1205,7 +1205,8 @@ inlineToLaTeX (Image attr@(_,_,kvs) description (source, _)) = do _ -> ["keepaspectratio"]) <> maybe [] (\x -> ["page=" <> literal x]) (lookup "page" kvs) <> maybe [] (\x -> ["trim=" <> literal x]) (lookup "trim" kvs) <> - maybe [] (\x -> ["alt=" <> braces (literal x)]) mbalt <> + maybe [] (\x -> ["alt=" <> + braces (hsep $ map literal $ T.words x)]) mbalt <> maybe [] (const ["clip"]) (lookup "clip" kvs) options = if null optList then empty diff --git a/test/Tests/Writers/LaTeX.hs b/test/Tests/Writers/LaTeX.hs index e2157e604..801e1afcb 100644 --- a/test/Tests/Writers/LaTeX.hs +++ b/test/Tests/Writers/LaTeX.hs @@ -70,7 +70,7 @@ tests = [ testGroup "code blocks" "\\begin{description}\n\\item[foo] ~ \n\\subsection{bar}\n\nbaz\n\\end{description}" , "containing image" =: header 1 (image "imgs/foo.jpg" "" (text "Alt text")) =?> - "\\section{\\texorpdfstring{\\protect\\pandocbounded{\\includegraphics[keepaspectratio,alt={Alt text}]{imgs/foo.jpg}}}{Alt text}}" + "\\section{\\texorpdfstring{\\protect\\pandocbounded{\\includegraphics[keepaspectratio,alt={Alt\ntext}]{imgs/foo.jpg}}}{Alt text}}" ] , testGroup "inline code" [ "struck out and highlighted" =: @@ -249,7 +249,7 @@ tests = [ testGroup "code blocks" (plain $ image (pack "img.jpg") (pack "") (text "alt text")) =?> "\\begin{figure}[htbp]\n\\centering\n" - <> "\\pandocbounded{\\includegraphics[keepaspectratio,alt={alt text}]{img.jpg}}\n" + <> "\\pandocbounded{\\includegraphics[keepaspectratio,alt={alt\ntext}]{img.jpg}}\n" <> "\\caption{caption}\n\\end{figure}" ] ] diff --git a/test/command/5116.md b/test/command/5116.md index 5a57f0716..a66178f5d 100644 --- a/test/command/5116.md +++ b/test/command/5116.md @@ -12,7 +12,8 @@ ^D \begin{figure} \centering -\pandocbounded{\includegraphics[keepaspectratio,alt={This is a figure.}]{img.jpg}} +\pandocbounded{\includegraphics[keepaspectratio,alt={This is a +figure.}]{img.jpg}} \caption{This is a figure.} \end{figure} @@ -50,7 +51,8 @@ Right & Left & Center & Default \\ \begin{figure} \centering \caption{This is a figure.} -\pandocbounded{\includegraphics[keepaspectratio,alt={This is a figure.}]{img.jpg}} +\pandocbounded{\includegraphics[keepaspectratio,alt={This is a +figure.}]{img.jpg}} \end{figure} \begin{longtable}[]{@{}rlcl@{}} @@ -86,7 +88,8 @@ Right & Left & Center & Default \\ ^D \begin{figure} \centering -\pandocbounded{\includegraphics[keepaspectratio,alt={This is a figure.}]{img.jpg}} +\pandocbounded{\includegraphics[keepaspectratio,alt={This is a +figure.}]{img.jpg}} \caption{This is a figure.} \end{figure} diff --git a/test/command/6821.md b/test/command/6821.md index c38953248..61224dd5d 100644 --- a/test/command/6821.md +++ b/test/command/6821.md @@ -60,7 +60,8 @@ \begin{figure} \centering -\pandocbounded{\includegraphics[keepaspectratio,alt={This is a test x = 5}]{test.png}} +\pandocbounded{\includegraphics[keepaspectratio,alt={This is a test x = +5}]{test.png}} \caption{This is a test \protect\VERB|\NormalTok{x }\OperatorTok{=} \DecValTok{5}|} \end{figure} diff --git a/test/command/7181.md b/test/command/7181.md index 6915e9991..74857dbc5 100644 --- a/test/command/7181.md +++ b/test/command/7181.md @@ -4,7 +4,8 @@ ^D \begin{figure} \centering -\pandocbounded{\includegraphics[keepaspectratio,page=13,trim=1cm,clip,width=4cm,alt={Global frog population.}]{slides.pdf}} +\pandocbounded{\includegraphics[keepaspectratio,page=13,trim=1cm,clip,width=4cm,alt={Global +frog population.}]{slides.pdf}} \caption{Global frog population.} \end{figure}