Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit length of captions in wrapfigures using CSS #2364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DominikPeters
Copy link

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
Copy link
Owner

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

@dginev
Copy link
Collaborator

dginev commented May 29, 2024

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants