Skip to content

Commit e894cbf

Browse files
authored
Merge pull request #12090 from quarto-dev/crossref/raw_latex
2 parents a21b6fc + d1c573e commit e894cbf

File tree

5 files changed

+82
-23
lines changed

5 files changed

+82
-23
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ All changes included in 1.7:
8080
- ([fb38eb5](https://github.com/quarto-dev/quarto-cli/commit/fb38eb56c11e09f44cef58fd3b697ff24bb5a3f3)) Use the `latest` parser for Acorn when analyzing JS code imported from OJS blocks.
8181
- ([#10532](https://github.com/quarto-dev/quarto-cli/issues/10532)): Quarto changed default of `--headless=old` to `--headless` as [Chrome 132 has removed old headless mode](https://developer.chrome.com/blog/removing-headless-old-from-chrome) and only support new mode. For using old mode, `QUARTO_CHROMIUM` could be set to a [new `chrome-headless-shell` binary](https://developer.chrome.com/blog/chrome-headless-shell) or too an older chrome version (between 128 and 132) and `QUARTO_CHROMIUM_HEADLESS_MODE` set to `old` for using old headless mode with that compatabitle version.
8282
- ([#10961](https://github.com/quarto-dev/quarto-cli/issues/10961)): Add more information on which Chrome Headless will be used in `quarto check install`. This is helpful to help debug mermaid issues.
83+
- ([#11951](https://github.com/quarto-dev/quarto-cli/issues/11951)): Raw LaTeX table without `tbl-` prefix label for using Quarto crossref are now correctly passed through unmodified.

src/command/render/pandoc.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,16 @@ export async function runPandoc(
398398
...options.flags?.metadata,
399399
} as Metadata;
400400

401+
const cleanQuartoTestsMetadata = (metadata: Metadata) => {
402+
// remove any metadata that is only used for testing
403+
if (metadata["_quarto"] && typeof metadata["_quarto"] === "object") {
404+
delete (metadata._quarto as { [key: string]: unknown })?.tests;
405+
if (Object.keys(metadata._quarto).length === 0) {
406+
delete metadata._quarto;
407+
}
408+
}
409+
};
410+
401411
// remove some metadata that are used as parameters to our lua filters
402412
const cleanMetadataForPrinting = (metadata: Metadata) => {
403413
delete metadata.params;
@@ -409,6 +419,7 @@ export async function runPandoc(
409419
delete metadata[kRevealJsScripts];
410420
deleteProjectMetadata(metadata);
411421
deleteCrossrefMetadata(metadata);
422+
removeFilterParams(metadata);
412423

413424
// Don't print empty reveal-js plugins
414425
if (
@@ -417,7 +428,12 @@ export async function runPandoc(
417428
) {
418429
delete metadata[kRevealJSPlugins];
419430
}
431+
432+
// Don't print _quarto.tests
433+
// This can cause issue on regex test for printed output
434+
cleanQuartoTestsMetadata(metadata);
420435
};
436+
421437
cleanMetadataForPrinting(printMetadata);
422438

423439
// Forward flags metadata into the format
@@ -1270,11 +1286,9 @@ export async function runPandoc(
12701286
delete pandocPassedMetadata.project;
12711287
delete pandocPassedMetadata.website;
12721288
delete pandocPassedMetadata.about;
1273-
if (pandocPassedMetadata._quarto) {
1274-
// these shouldn't be visible because they are emitted on markdown output
1275-
// and it breaks ensureFileRegexMatches
1276-
delete pandocPassedMetadata._quarto.tests;
1277-
}
1289+
// these shouldn't be visible because they are emitted on markdown output
1290+
// and it breaks ensureFileRegexMatches
1291+
cleanQuartoTestsMetadata(pandocPassedMetadata);
12781292

12791293
Deno.writeTextFileSync(
12801294
metadataTemp,
@@ -1377,7 +1391,7 @@ export async function runPandoc(
13771391

13781392
// this mutates metadata[kClassOption]
13791393
function cleanupPandocMetadata(metadata: Metadata) {
1380-
// pdf classoption can end up with duplicaed options
1394+
// pdf classoption can end up with duplicated options
13811395
const classoption = metadata[kClassOption];
13821396
if (Array.isArray(classoption)) {
13831397
metadata[kClassOption] = ld.uniqBy(
@@ -1668,8 +1682,6 @@ function runPandocMessage(
16681682
const printMetadata = ld.cloneDeep(metadata) as Metadata;
16691683
delete printMetadata.format;
16701684

1671-
// remove filter params
1672-
removeFilterParams(printMetadata);
16731685
// print message
16741686
if (Object.keys(printMetadata).length > 0) {
16751687
info("metadata", { bold: true });

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -702,36 +702,39 @@ function parse_floatreftargets()
702702
return nil
703703
end
704704

705+
-- prevent raw mutation
706+
local rawText = raw.text
707+
705708
-- first we check if all of the expected bits are present
706709

707710
-- check for {#...} or \label{...}
708-
if raw.text:find(patterns.latex_label) == nil and
709-
raw.text:find(patterns.attr_identifier) == nil then
711+
if rawText:find(patterns.latex_label) == nil and
712+
rawText:find(patterns.attr_identifier) == nil then
710713
return nil
711714
end
712715

713716
-- check for \caption{...}
714-
if raw.text:find(patterns.latex_caption) == nil then
717+
if rawText:find(patterns.latex_caption) == nil then
715718
return nil
716719
end
717720

718721
-- check for tabular or longtable
719-
if raw.text:find(patterns.latex_long_table) == nil and
720-
raw.text:find(patterns.latex_tabular) == nil then
722+
if rawText:find(patterns.latex_long_table) == nil and
723+
rawText:find(patterns.latex_tabular) == nil then
721724
return nil
722725
end
723726

724727
-- if we're here, then we're going to parse this as a FloatRefTarget
725728
-- and we need to remove the label and caption from the raw block
726729
local identifier = ""
727-
local b, e, match1, label_identifier = raw.text:find(patterns.latex_label)
730+
local b, e, _ , label_identifier = rawText:find(patterns.latex_label)
728731
if b ~= nil then
729-
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
732+
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
730733
identifier = label_identifier
731734
else
732-
local b, e, match2, attr_identifier = raw.text:find(patterns.attr_identifier)
735+
local b, e, _ , attr_identifier = rawText:find(patterns.attr_identifier)
733736
if b ~= nil then
734-
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
737+
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
735738
identifier = attr_identifier
736739
else
737740
internal_error()
@@ -749,9 +752,9 @@ function parse_floatreftargets()
749752
end
750753

751754
local caption
752-
local b, e, match3, caption_content = raw.text:find(patterns.latex_caption)
755+
local b, e, _, caption_content = rawText:find(patterns.latex_caption)
753756
if b ~= nil then
754-
raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1)
757+
rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1)
755758
caption = pandoc.RawBlock("latex", caption_content)
756759
else
757760
internal_error()
@@ -760,16 +763,16 @@ function parse_floatreftargets()
760763

761764
-- finally, if the user passed a \\begin{table} float environment
762765
-- we just remove it because we'll re-emit later ourselves
763-
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(raw.text, _quarto.patterns.latexTableEnvPatterns)
766+
local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(rawText, _quarto.patterns.latexTableEnvPatterns)
764767
if matched then
765768
-- table_body is second matched element.
766-
raw.text = matched[2]
769+
rawText = matched[2]
767770
end
768771

769772
return construct({
770773
attr = pandoc.Attr(identifier, {}, {}),
771774
type = "Table",
772-
content = pandoc.Blocks({ raw }),
775+
content = pandoc.Blocks({ pandoc.RawBlock(raw.format, rawText) }),
773776
caption_long = quarto.utils.as_blocks(caption)
774777
}), false
775778
end

tests/docs/smoke-all/2024/01/22/8389.md.snapshot

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
---
2-
_quarto: {}
32
foo: bar
43
toc-title: Table of contents
54
---
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Raw LaTeX table with not `tbl` in label id
3+
format: pdf
4+
keep-tex: true
5+
_quarto:
6+
tests:
7+
pdf:
8+
ensureLatexFileRegexMatches:
9+
- ['[\s\S]+\\begin\{table\}\[htbp\][\s\S]+', '[\s\S]+\\caption\{\\label\{mod\}']
10+
- []
11+
printsMessage:
12+
- INFO
13+
- 'WARNING(.*)Raw LaTeX table found with non-tbl label:'
14+
---
15+
16+
This document has a raw LaTeX table with no intent to use quarto crossref. It uses a label with `tbl-` id.
17+
18+
Table will be identified by floatreftarget processing but raw TeX should be left untouched in the output, while a warning still is emitted.
19+
20+
```{=latex}
21+
\begin{table}[htbp]
22+
\caption{\label{mod} no title}
23+
\centering
24+
\begin{tabular}{lc}
25+
\tabularnewline \midrule \midrule
26+
Dependent Variable: & disp\\
27+
Model: & (1)\\
28+
\midrule
29+
\emph{Variables}\\
30+
Constant & 580.9$^{***}$\\
31+
& (41.74)\\
32+
mpg & -17.43$^{***}$\\
33+
& (1.993)\\
34+
\midrule
35+
\emph{Fit statistics}\\
36+
Observations & 32\\
37+
R$^2$ & 0.71834\\
38+
Adjusted R$^2$ & 0.70895\\
39+
\midrule \midrule
40+
\multicolumn{2}{l}{\emph{IID standard-errors in parentheses}}\\
41+
\multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\
42+
\end{tabular}
43+
\end{table}
44+
```

0 commit comments

Comments
 (0)