LaTeXML icon indicating copy to clipboard operation
LaTeXML copied to clipboard

Limit length of captions in wrapfigures using CSS

Open DominikPeters opened this issue 1 year ago • 3 comments
trafficstars

The current bindings for the wrapfig package ignore the author-specified width. Together with the standard css, this leads to a bad presentation of wrapfigures with long captions. This pull request adds CSS (setting width: min-content on the <figure> element) to limit the length of the caption of a wrapfigure to the length of the image. (Probably the more elegant solution is to take into account the width parameter of the wrapfigure environment, but this is a simple fix for the moment.)

Example:

\documentclass{article}
\usepackage{wrapfig,tikz}
\begin{document}
    \begin{wrapfigure}{r}{0.4\textwidth}
        \centering
        \tikz{\fill[purple] (0,0) rectangle (4,2);}
        \caption{A red rectangle deserving a long caption.}
    \end{wrapfigure}
    This is a\foreach \wordnum in {0,...,300} { test}.
\end{document}

PDF: image

LaTeXML (note that if the caption gets longer, the figure can take up up to 100% of the width of the page): image

LaTeXML with this pull request: image

DominikPeters avatar May 02 '24 17:05 DominikPeters

Seems reasonable on the surface. @dginev how does this interact with your work?

brucemiller avatar May 29 '24 18:05 brucemiller

Well, it is hard to say for certain without adding a few more tests. The one test I had checked in (t/complex/figure_mixed_content.tex) has a {wrapfigure} that contains an {algorithm} in a minipage, which is already a nice counter-example:

Using the mainline latexml, and ar5iv.css, that figure renders as:

with the PR, because the figure contains textual content, the min-content directive compresses down to what is essentially the length of the longest word:

So we may want to make such CSS enhancement a little more precise, applying only to the image and table cases. And check in tests for those respectively.

dginev avatar May 29 '24 18:05 dginev

So, it seems that the wrapfigures request of width is probably a relevant constraint.

brucemiller avatar May 29 '24 21:05 brucemiller

Let's close here since width: min-content; really isn't the right approach.

I have opened a issue where we can discuss further at #2578

dginev avatar Jun 09 '25 00:06 dginev