Skip to content

Commit 0a50aa5

Browse files
Fix tbl-column: margin for Typst output (closes #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 1512e8e commit 0a50aa5

4 files changed

Lines changed: 108 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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
- ['Table 1', 'TblColMarginCap', 'Alpha']
18+
- []
19+
ensurePdfTextPositions:
20+
- # Table text should be in the margin, right of body text
21+
- subject: "Alpha"
22+
relation: rightOf
23+
object: "BODYTEXT"
24+
- []
25+
noErrors: default
26+
---
27+
28+
BODYTEXT: This tests the document-level `tbl-column: margin` option. Tables should go to the margin; figures should stay in the body.
29+
30+
```{r}
31+
#| label: fig-tc-test
32+
#| fig-cap: "FigBodyCap"
33+
#| echo: false
34+
library(ggplot2)
35+
ggplot(mtcars, aes(x = wt, y = mpg)) +
36+
geom_point() +
37+
theme_minimal()
38+
```
39+
40+
```{r}
41+
#| label: tbl-tc-test
42+
#| tbl-cap: "TblColMarginCap"
43+
#| echo: false
44+
knitr::kable(
45+
data.frame(Item = c("Alpha", "Beta"), Value = c(10, 20))
46+
)
47+
```
48+
49+
The table should be in the margin and the figure in the body.

0 commit comments

Comments
 (0)