brucemiller / LaTeXML

LaTeXML: a TeX and LaTeX to XML/HTML/ePub/MathML translator.
http://dlmf.nist.gov/LaTeXML/
Other
863 stars 93 forks source link

Limit length of captions in wrapfigures using CSS #2364

Open DominikPeters opened 1 month ago

DominikPeters commented 1 month ago

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
brucemiller commented 2 weeks ago

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

dginev commented 2 weeks ago

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.

brucemiller commented 2 weeks ago

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