Skip to content

Commit b2b7951

Browse files
Fix tbl-column: margin for Typst output (#13929)
Apply scoped column classes (fig-column, tbl-column) directly to FloatRefTargets in columns-preprocess.lua, bypassing the Div propagation chain which silently failed for tables. Also fix copy-paste bug in base.ts where fig-caption- prefix was used instead of fig-column-/ tbl-column-.
1 parent 9e9160b commit b2b7951

4 files changed

Lines changed: 109 additions & 2 deletions

File tree

src/core/handlers/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,10 @@ export function getDivAttributes(
862862
classes.push(`tbl-cap-location-${options?.[kTblCapLoc]}`);
863863
}
864864
if (typeof options?.[kCellFigColumn] === "string") {
865-
classes.push(`fig-caption-${options?.[kCellFigColumn]}`);
865+
classes.push(`fig-column-${options?.[kCellFigColumn]}`);
866866
}
867867
if (typeof options?.[kCellTblColumn] === "string") {
868-
classes.push(`fig-caption-${options?.[kCellTblColumn]}`);
868+
classes.push(`tbl-column-${options?.[kCellTblColumn]}`);
869869
}
870870
return { attrs, classes };
871871
}

src/resources/filters/layout/columns-preprocess.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ function columns_preprocess()
77
if float.parent_id ~= nil then
88
return nil
99
end
10+
-- Apply scoped column classes from document-level options (e.g. fig-column, tbl-column)
11+
-- This ensures the column class reaches the float directly, rather than relying
12+
-- on the Div propagation chain which can fail for some float types
13+
local ref = ref_type_from_float(float)
14+
resolveElementForScopedColumns(float, ref)
1015
-- Check for margin figure placement (.column-margin or .aside class)
1116
if hasMarginColumn(float) then
1217
noteHasColumns()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "Fig-Column Margin Test"
3+
papersize: us-letter
4+
fig-column: margin
5+
format:
6+
html: default
7+
typst:
8+
keep-typ: true
9+
_quarto:
10+
tests:
11+
typst:
12+
ensureTypstFileRegexMatches:
13+
# Figure should use notefigure for margin placement
14+
- ['#notefigure\(', 'kind: "quarto-float-fig"']
15+
- []
16+
ensurePdfRegexMatches:
17+
- ['Table 1', 'TBL-BODY-CAP', 'TBL-BODY-MARKER']
18+
- []
19+
ensurePdfTextPositions:
20+
- # Table stays in body, not pushed to margin
21+
- subject: "TBL-BODY-MARKER"
22+
relation: below
23+
object: "BODY-TEXT-MARKER"
24+
- # Table should NOT be right of body text (not in margin)
25+
- subject: "TBL-BODY-MARKER"
26+
relation: rightOf
27+
object: "BODY-TEXT-MARKER"
28+
noErrors: default
29+
---
30+
31+
BODY-TEXT-MARKER: This tests the document-level `fig-column: margin` option. Figures should go to the margin; tables should stay in the body.
32+
33+
```{r}
34+
#| label: fig-fc-test
35+
#| fig-cap: "FIG-COL-MARGIN-CAP"
36+
#| echo: false
37+
library(ggplot2)
38+
ggplot(mtcars, aes(x = wt, y = mpg)) +
39+
geom_point() +
40+
theme_minimal()
41+
```
42+
43+
```{r}
44+
#| label: tbl-fc-test
45+
#| tbl-cap: "TBL-BODY-CAP"
46+
#| echo: false
47+
knitr::kable(
48+
data.frame(Item = c("TBL-BODY-MARKER", "Row2"), Value = c(10, 20))
49+
)
50+
```
51+
52+
The figure should be in the margin and the table in the body.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: "Tbl-Column Margin Test"
3+
papersize: us-letter
4+
tbl-column: margin
5+
format:
6+
html: default
7+
typst:
8+
keep-typ: true
9+
_quarto:
10+
tests:
11+
typst:
12+
ensureTypstFileRegexMatches:
13+
# Table should use notefigure for margin placement
14+
- ['#notefigure\(', 'kind: "quarto-float-tbl"']
15+
- []
16+
ensurePdfRegexMatches:
17+
# Typst drops hyphens in margin text, so use optional hyphens in patterns
18+
- ['Table 1', 'TBL.COL.MARGIN.?CAP', 'TBL.MARGIN.?MARKER']
19+
- []
20+
ensurePdfTextPositions:
21+
- # Table text should be in the margin, right of body text
22+
- subject: "Row2"
23+
relation: rightOf
24+
object: "BODY-TEXT-MARKER"
25+
- []
26+
noErrors: default
27+
---
28+
29+
BODY-TEXT-MARKER: This tests the document-level `tbl-column: margin` option. Tables should go to the margin; figures should stay in the body.
30+
31+
```{r}
32+
#| label: fig-tc-test
33+
#| fig-cap: "FIG-BODY-CAP"
34+
#| echo: false
35+
library(ggplot2)
36+
ggplot(mtcars, aes(x = wt, y = mpg)) +
37+
geom_point() +
38+
theme_minimal()
39+
```
40+
41+
```{r}
42+
#| label: tbl-tc-test
43+
#| tbl-cap: "TBL-COL-MARGIN-CAP"
44+
#| echo: false
45+
knitr::kable(
46+
data.frame(Item = c("TBL-MARGIN-MARKER", "Row2"), Value = c(10, 20))
47+
)
48+
```
49+
50+
The table should be in the margin and the figure in the body.

0 commit comments

Comments
 (0)