Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion news/changelog-1.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ All changes included in 1.7:

- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.
- ([#11903](https://github.com/quarto-dev/quarto-cli/issues/11903)): `crossref` configuration like `fig-title` or `tbl-title` now correctly supports multi word values, e.g. `fig-title: 'Supplementary Figure'`.
- ([#11878](https://github.com/quarto-dev/quarto-cli/issues/11878)): Correctly fixup raw LaTeX table having an unexpected table env with options (e.g `\begin{table}[c]`) to be handled as crossref table.
- ([#11878](https://github.com/quarto-dev/quarto-cli/issues/11878), [#12085](https://github.com/quarto-dev/quarto-cli/issues/12085)): Correctly fixup raw LaTeX table having an unexpected table env with options (e.g `\begin{table}[!ht]`) to be handled as crossref table.

## `typst` format

Expand Down
9 changes: 6 additions & 3 deletions src/resources/filters/quarto-pre/parsefiguredivs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ local function remove_latex_crossref_envs(content, name)
if not _quarto.format.isRawLatex(raw) then
return nil
end
local b, e, begin_table, table_body, end_table = raw.text:find(patterns.latex_table)
if b ~= nil then
raw.text = table_body
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(raw.text, _quarto.patterns.latexTableEnvPatterns)
if matched then
-- table_body is second matched element.
raw.text = matched[2]
return raw
else
return nil
Expand Down Expand Up @@ -548,6 +549,8 @@ function parse_floatreftargets()
})
return parse_float_div(div)
elseif isTableDiv(div) then
-- FIXUP: We don't go here for a `#tbl-` id as it is matched as a FigureDiv above
-- TO REMOVE ?
Comment on lines +552 to +553
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cscheid unrelated to this PR but I added this note because while debugging, I found that we don't go there as tbl- prefixed id will always be matched by isFigureDiv()

So I figured we should remove this part, but for now at least mark it as stale to avoid spending much time wondering if we go there at next debugging.

Hopefully the fact that isTableDiv() is now no more useful when isFigureDiv() is used before is expected.

Though, it may not as the isFigureDiv() is used to do a fixup on nested Image - maybe we don't want do that on all type of crossref ?

For reference isFigureDiv() is

-- is this a Div containing a figure
function isFigureDiv(el, captionRequired)
if is_regular_node(el, "Div") and hasFigureRef(el) then
if captionRequired == nil then
captionRequired = true
end
if not captionRequired then
return true
end
return el.attributes[kFigCap] ~= nil or refCaptionFromDiv(el) ~= nil
else
return discoverLinkedFigureDiv(el) ~= nil
end
end

and uses hasFigureRef() using isFigureRef()
-- does this element have a figure label?
function hasFigureRef(el)
return isFigureRef(el.identifier)
end
function isFigureRef(identifier)
if identifier == nil then
return nil
end
local ref = refType(identifier)
return crossref.categories.by_ref_type[ref] ~= nil
end

where isFigureRef() matches all known crossref type.

Sharing in case this is raising question to you too. I added as topic for next Thursday meeting as not urgent. I can merge current PR with the note, and remove it later if necessary

return parse_float_div(div)
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Crossref Raw LaTeX table with table env and position when produced by cell computation
format: pdf
keep-tex: true
_quarto:
tests:
pdf:
ensureLatexFileRegexMatches:
- ['\n\\begin\{table\}\n', 'See Table~\\ref\{tbl-test\}']
- []
---

`\begin{table}` should be catched and remove as Quarto does add its own, when this produced from a cell

## Example with Julia Cell

Derived https://github.com/quarto-dev/quarto-cli/issues/12085

::: {#tbl-test .cell execution_count=1}
```` { .cell-code}
```{{julia}}
#| label: tbl-test
#| output: asis
struct Latex
s::String
end

Base.show(io::IO, m::MIME"text/latex", l::Latex) = print(io, l.s)

Latex(raw"""
\begin{table}
\setlength\tabcolsep{0pt}
\centering
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{table}
""")
```

````
```{=tex}
\begin{table}
\setlength\tabcolsep{0pt}
\centering
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{table}
```
:::


See @tbl-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: Crossref Raw LaTeX table with table env and position when produced by cell computation
format: pdf
keep-tex: true
_quarto:
tests:
pdf:
ensureLatexFileRegexMatches:
- ['\n\\begin\{table\}\n', 'See Table~\\ref\{tbl-test\}']
- ['\\begin\{table\}[\!ht]']
---

`\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

## Example with Julia Cell

From https://github.com/quarto-dev/quarto-cli/issues/12085

::: {#tbl-test .cell execution_count=1}
```` { .cell-code}
```{{julia}}
#| label: tbl-test
#| output: asis
struct Latex
s::String
end

Base.show(io::IO, m::MIME"text/latex", l::Latex) = print(io, l.s)

Latex(raw"""
\begin{table}[!ht]
\setlength\tabcolsep{0pt}
\centering
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{table}
""")
```

````
```{=tex}
\begin{table}[!ht]
\setlength\tabcolsep{0pt}
\centering
\begin{tabular}{@{\extracolsep{2ex}}*{5}{ccccc}}
\toprule
$\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ & $\theta 1$ \\
\midrule
$\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ & $\theta 2$ \\
$\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ & $\theta 3$ \\
$\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ & $\theta 4$ \\
$\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ & $\theta 5$ \\
\bottomrule
\end{tabular}
\end{table}
```
:::


See @tbl-test
Loading