Technical Implementation
HTML
Little logic is needed for the HTML implementation. Fortunately, if an image has both a #fig- ID and a .class class, Quarto copies that class from the image to the figure div.
Therefore, the only logic needed for the HTML is: - Implementing the margin via config rather than CSS - Implementing autowrap - Adding the .wrap class to things with the .wrap-XXX class, which is an implementation detail so that the layout logic isn’t duplicated
LaTeX
In LaTeX, nothing is so simple. There is nothing like CSS, so instead we have to patch the figure environment into a wrapfigure, passing the appropriate options to it.
The reason why a width must be provided is because none of the other approaches work well. I have tried the following:
- Using a
0ptwidth forwrapfigure. In this case LaTeX is supposed to work out the width of the float. However, this seems to be completely inaccurate, and results in text overlapping the image. - Measuring the width of the figure using
calcorsavebox. These can’t handle a floating environment such as afigure, and you getMissing \endgroup inserted. - Measuring the width of the image alone using
calc. Unfortunately this doesn’t work either, because it measures the full width of the original image, not the image as it would be displayed. This is because we miss out on all the Quarto magic that is applied to the figure environment.