jgm / pandoc

Universal markup converter
https://pandoc.org
Other
33.96k stars 3.35k forks source link

Can we not put all LaTeX subfigures into a single line? #8570

Open lierdakil opened 1 year ago

lierdakil commented 1 year ago

Describe your proposed improvement and the problem it solves.

Pandoc 3.0 introduced subfigures support in LaTeX. The problem is LaTeX writer always puts all subfigures into one line, and it's pretty common to align figures in a grid instead. This is a pretty bad experience, frankly.

Additional context: pandoc-crossref.

I don't have good ideas what could be done here, considering Figure is a flat list of Blocks. But I have a "bad" idea -- group rows with Divs, otherwise plop subfigures vertically.

Describe alternatives you've considered.

:shrug: use blockquotes to group rows? That sounds even more hacky.

jgm commented 1 year ago

I can think of a few other possibilities here:

  1. Automatic in a grid of width 2
  2. Let an attribute on the outer figure specify the layout, e.g. layout="2x3"
  3. Let a HorizontalRule indicate that subsequent subfigures should go on a new line (similar to the way it causes slides to be sliced)
lierdakil commented 1 year ago

Okay, good alternatives. Some thoughts:

  1. Automatic in a grid of width 2

This would be annoying if you want to stack, e.g., 2 images per portrait A4 page: while not very common, also not unheard of. There are plenty of other examples where this would be insufficient.

  1. attribute on the outer figure specify the layout

We only really need to specify either columns or rows. Columns are simpler. But this precludes uneven grids, e.g. 2-3 and 3-2 are used sometimes.

  1. HorizontalRule indicate [...] a new line

Syntax-wise, this seems the most convenient option and without the flexibility drawbacks of the two previous ones. Feels rather hacky though, I mean more so than using Divs for the same purpose.

If I had to choose one of three, I'd go with the third. In fact, convenience-wise, it's certainly preferable to divs. Divs have precedent for something similar, though, since we have the columns thingamajig.

jgm commented 1 year ago

@tarleb any thoughts on this?

tarleb commented 1 year ago

For docx, output pandoc use tables to place subfigures, and we basically need a friendly way to define a 2d table that contains images. Divs would give us the necessary flexibility and would encode weird layouts with rowspans and colspans. The downside is that this could be a little too flexible, as I don't think there is an easy way to build those complex figures with ConTeXt.

A figure attribute with the grid dimensions would be the easy and safe choice. Not sure which I like better.

tarleb commented 1 year ago

Docs on how Quarto handles figures: https://quarto.org/docs/authoring/figures.html#subfigures

jgm commented 1 year ago

I guess that approach would preclude uneven grids (e.g. 2 in a row, then a big image in one row, then 2 more). EDIT: Oh, I see quarto has this: {layout="[[1,1], [1]]"}

Another possibility, perhaps, would be to have the writer determine an ideal layout based on width information on the figures/images. So, for example, if you have 3 images in your figure, and the first has width 100% and the second and third 50%, then you get one row with the first image and then a second row with the next two. (This would rule out having very narrow images in rows by themselves; I don't know if that's something people would want to do.)

jgm commented 1 year ago

Note: we should also think about how it would work in other writers. In HTML, I'd want the layout to be responsive, so that when the article is read on a phone the figures stack vertically but on a browser they are laid out in tabular form. This could be achieved using flex-wrap and assigning widths to the subfigures. If that's how it would be best to work in HTML, then it might not be ideal to expect layout to be hard-coded in the source document.

changlichun commented 5 months ago

When I convert the latex to docx, the subfigure is also placed on a single line. Is there any plan to improve this issue.