Skip to content

Commit b019905

Browse files
committed
crossref, latex - correctly table env for raw table produced by computations
This is a follow up of previous adaptation to take into account table options in environment done in #11921
1 parent d9319b8 commit b019905

File tree

3 files changed

+142
-3
lines changed

3 files changed

+142
-3
lines changed

src/resources/filters/quarto-pre/parsefiguredivs.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ local function remove_latex_crossref_envs(content, name)
6666
if not _quarto.format.isRawLatex(raw) then
6767
return nil
6868
end
69-
local b, e, begin_table, table_body, end_table = raw.text:find(patterns.latex_table)
70-
if b ~= nil then
71-
raw.text = table_body
69+
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(raw.text, _quarto.patterns.latexTableEnvPatterns)
70+
if matched then
71+
-- table_body is second matched element.
72+
raw.text = matched[2]
7273
return raw
7374
else
7475
return nil
@@ -548,6 +549,8 @@ function parse_floatreftargets()
548549
})
549550
return parse_float_div(div)
550551
elseif isTableDiv(div) then
552+
-- FIXUP: We don't go here for a `#tbl-` id as it is matched as a FigureDiv above
553+
-- TO REMOVE ?
551554
return parse_float_div(div)
552555
end
553556

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Crossref Raw LaTeX table with table env and position when produced by cell computation
3+
format: pdf
4+
keep-tex: true
5+
_quarto:
6+
tests:
7+
pdf:
8+
ensureLatexFileRegexMatches:
9+
- ['\n\\begin\{table\}\n', 'See Table~\\ref\{tbl-test\}']
10+
- []
11+
---
12+
13+
`\begin{table}` should be catched and remove as Quarto does add its own, when this produced from a cell
14+
15+
## Example with Julia Cell
16+
17+
Derived https://github.com/quarto-dev/quarto-cli/issues/12085
18+
19+
::: {#tbl-test .cell execution_count=1}
20+
```` { .cell-code}
21+
```{{julia}}
22+
#| label: tbl-test
23+
#| output: asis
24+
struct Latex
25+
s::String
26+
end
27+
28+
Base.show(io::IO, m::MIME"text/latex", l::Latex) = print(io, l.s)
29+
30+
Latex(raw"""
31+
\begin{table}
32+
\setlength\tabcolsep{0pt}
33+
\centering
34+
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
35+
\toprule
36+
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
37+
\midrule
38+
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
39+
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
40+
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
41+
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
42+
\bottomrule
43+
\end{tabular}
44+
\end{table}
45+
""")
46+
```
47+
48+
````
49+
```{=tex}
50+
\begin{table}
51+
\setlength\tabcolsep{0pt}
52+
\centering
53+
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
54+
\toprule
55+
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
56+
\midrule
57+
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
58+
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
59+
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
60+
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
61+
\bottomrule
62+
\end{tabular}
63+
\end{table}
64+
```
65+
:::
66+
67+
68+
See @tbl-test
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Crossref Raw LaTeX table with table env and position when produced by cell computation
3+
format: pdf
4+
keep-tex: true
5+
_quarto:
6+
tests:
7+
pdf:
8+
ensureLatexFileRegexMatches:
9+
- ['\n\\begin\{table\}\n', 'See Table~\\ref\{tbl-test\}']
10+
- ['\\begin\{table\}[\!ht]']
11+
---
12+
13+
`\begin{table}` should be catched and remove as Quarto does add its own, including when option position are used and when this produced from a cell
14+
15+
## Example with Julia Cell
16+
17+
From https://github.com/quarto-dev/quarto-cli/issues/12085
18+
19+
::: {#tbl-test .cell execution_count=1}
20+
```` { .cell-code}
21+
```{{julia}}
22+
#| label: tbl-test
23+
#| output: asis
24+
struct Latex
25+
s::String
26+
end
27+
28+
Base.show(io::IO, m::MIME"text/latex", l::Latex) = print(io, l.s)
29+
30+
Latex(raw"""
31+
\begin{table}[!ht]
32+
\setlength\tabcolsep{0pt}
33+
\centering
34+
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
35+
\toprule
36+
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
37+
\midrule
38+
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
39+
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
40+
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
41+
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
42+
\bottomrule
43+
\end{tabular}
44+
\end{table}
45+
""")
46+
```
47+
48+
````
49+
```{=tex}
50+
\begin{table}[!ht]
51+
\setlength\tabcolsep{0pt}
52+
\centering
53+
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
54+
\toprule
55+
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
56+
\midrule
57+
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
58+
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
59+
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
60+
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
61+
\bottomrule
62+
\end{tabular}
63+
\end{table}
64+
```
65+
:::
66+
67+
68+
See @tbl-test

0 commit comments

Comments
 (0)