3

Consider the following example:

% lualatex test.tex

\DocumentMetadata{}

\documentclass[a4paper]{article}

\usepackage{polyglossia} \usepackage{graphicx}

\begin{document}

\begin{figure} \centering \includegraphics[width = 0.99\textwidth]{example-image-a} \caption{Test caption.} \end{figure}

\begin{figure} \centering \includegraphics[width = \textwidth]{example-image-a} \caption{Test caption.} \end{figure}

\end{document}

output

As can be seen in the output, the space between the second picture and the corresponding caption is too wide. However, if I remove the polyglossia package, the spacing is correct.

What on Earth is going on and how do I fix it?

Note: I think that this is a somewhat new thing (but I'm not sure); I can't remember ever seeing this before.

Update

A version of the package with a bugfix has now been released; see here.

  • Not an explanation of the problem, but if you can, I would switch to babel. Babel is much more actively maintained while polyglossia seems to be crumbling to pieces... – samcarter_is_at_topanswers.xyz Dec 22 '22 at 20:25
  • @samcarter_is_at_topanswers.xyz Where can I check this statement about Polyglossia? Since Polyglossia's development resumed a few years ago, it seemed to run fine and I haven't run into any problem (within my use case of course). – Miyase Dec 22 '22 at 20:30
  • @Miyase See https://tex.stackexchange.com/q/482396/36296 – samcarter_is_at_topanswers.xyz Dec 22 '22 at 20:35
  • @samcarter_is_at_topanswers.xyz This link is a bit old, and one answer specifies that things have changed since then. Also, the link only points out some lack of features (none of which would impact my usecase anyway), but doesn't say anything about development problems. So I'm still wondering where I could see anything factual indicating that Polyglossia is "crumbling to pieces". – Miyase Dec 23 '22 at 00:14

1 Answers1

6

If you add \ShowHook{cmd/caption/before} you will see polyglossia has injected code into the start of \caption.

-> The generic hook 'cmd/caption/before':
> Code chunks:
>     polyglossia -> \addtocontents {lof}{\protect \setforeignlanguage {\langua
gename }}\addtocontents {lot}{\protect \setforeignlanguage {\languagename }}

Leaving a blank line before \caption would work around the bug, but it should be reported to polyglossia maintainers.

or patching via the hook:

\documentclass[a4paper]{article}

\AddToHook{cmd/caption/before}[polyglossia]{\par} \usepackage{polyglossia}

\usepackage{graphicx}

\begin{document}

%\ShowHook{cmd/caption/before}

\begin{figure} \centering \includegraphics[width = 0.99\textwidth]{example-image-a} \caption{Test caption.} \end{figure}

\begin{figure} \centering \includegraphics[width = \textwidth]{example-image-a} \caption{Test caption.} \end{figure}

\end{document}

David Carlisle
  • 757,742