diff --git a/crates/typst/src/layout/flow/compose.rs b/crates/typst/src/layout/flow/compose.rs index 4b991f2b2..a262d5c1f 100644 --- a/crates/typst/src/layout/flow/compose.rs +++ b/crates/typst/src/layout/flow/compose.rs @@ -634,6 +634,23 @@ impl<'a, 'b> Insertions<'a, 'b> { output.push_frame(Point::with_y(self.top_size), inner); + // We put floats first and then footnotes. This differs from what LaTeX + // does and is a little inconsistent w.r.t column vs page floats (page + // floats are below footnotes because footnotes are per column), but + // it's what most people (including myself) seem to intuitively expect. + // We experimented with the LaTeX ordering in 0.12.0-rc1, but folks were + // surprised and considered this strange. In LaTeX, it can be changed + // with `\usepackage[bottom]{footmisc}`. We could also consider adding + // configuration in the future. + for (placed, frame) in self.bottom_floats { + offset_bottom += placed.clearance; + let x = placed.align_x.position(size.x - frame.width()); + let y = offset_bottom; + let delta = placed.delta.zip_map(size, Rel::relative_to).to_point(); + offset_bottom += frame.height(); + output.push_frame(Point::new(x, y) + delta, frame); + } + if let Some(frame) = self.footnote_separator { offset_bottom += config.footnote.clearance; let y = offset_bottom; @@ -648,15 +665,6 @@ impl<'a, 'b> Insertions<'a, 'b> { output.push_frame(Point::with_y(y), frame); } - for (placed, frame) in self.bottom_floats { - offset_bottom += placed.clearance; - let x = placed.align_x.position(size.x - frame.width()); - let y = offset_bottom; - let delta = placed.delta.zip_map(size, Rel::relative_to).to_point(); - offset_bottom += frame.height(); - output.push_frame(Point::new(x, y) + delta, frame); - } - output } } diff --git a/tests/ref/footnote-break-across-pages-float.png b/tests/ref/footnote-break-across-pages-float.png index 94f8a587e..5d3ea1078 100644 Binary files a/tests/ref/footnote-break-across-pages-float.png and b/tests/ref/footnote-break-across-pages-float.png differ diff --git a/tests/ref/footnote-in-place.png b/tests/ref/footnote-in-place.png index fa5e1bd1e..b500ac80f 100644 Binary files a/tests/ref/footnote-in-place.png and b/tests/ref/footnote-in-place.png differ