From 76253baee408e77ac8e4b82dd9b2e6bf55ccc48e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Feb 2025 12:12:36 +0100 Subject: [PATCH 1/5] rawLaTeX with not tbl- label should be passed unmodified --- .../filters/quarto-pre/parsefiguredivs.lua | 31 +++++++------- .../latex-raw-table-env-no-tbl-label.qmd | 41 +++++++++++++++++++ 2 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd diff --git a/src/resources/filters/quarto-pre/parsefiguredivs.lua b/src/resources/filters/quarto-pre/parsefiguredivs.lua index f0f3b47788..a066abe76a 100644 --- a/src/resources/filters/quarto-pre/parsefiguredivs.lua +++ b/src/resources/filters/quarto-pre/parsefiguredivs.lua @@ -702,36 +702,39 @@ function parse_floatreftargets() return nil end + -- prevent raw mutation + local rawText = raw.text + -- first we check if all of the expected bits are present -- check for {#...} or \label{...} - if raw.text:find(patterns.latex_label) == nil and - raw.text:find(patterns.attr_identifier) == nil then + if rawText:find(patterns.latex_label) == nil and + rawText:find(patterns.attr_identifier) == nil then return nil end -- check for \caption{...} - if raw.text:find(patterns.latex_caption) == nil then + if rawText:find(patterns.latex_caption) == nil then return nil end -- check for tabular or longtable - if raw.text:find(patterns.latex_long_table) == nil and - raw.text:find(patterns.latex_tabular) == nil then + if rawText:find(patterns.latex_long_table) == nil and + rawText:find(patterns.latex_tabular) == nil then return nil end -- if we're here, then we're going to parse this as a FloatRefTarget -- and we need to remove the label and caption from the raw block local identifier = "" - local b, e, match1, label_identifier = raw.text:find(patterns.latex_label) + local b, e, _ , label_identifier = rawText:find(patterns.latex_label) if b ~= nil then - raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1) + rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1) identifier = label_identifier else - local b, e, match2, attr_identifier = raw.text:find(patterns.attr_identifier) + local b, e, _ , attr_identifier = rawText:find(patterns.attr_identifier) if b ~= nil then - raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1) + rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1) identifier = attr_identifier else internal_error() @@ -749,9 +752,9 @@ function parse_floatreftargets() end local caption - local b, e, match3, caption_content = raw.text:find(patterns.latex_caption) + local b, e, _, caption_content = rawText:find(patterns.latex_caption) if b ~= nil then - raw.text = raw.text:sub(1, b - 1) .. raw.text:sub(e + 1) + rawText = rawText:sub(1, b - 1) .. rawText:sub(e + 1) caption = pandoc.RawBlock("latex", caption_content) else internal_error() @@ -760,16 +763,16 @@ function parse_floatreftargets() -- finally, if the user passed a \\begin{table} float environment -- we just remove it because we'll re-emit later ourselves - local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(raw.text, _quarto.patterns.latexTableEnvPatterns) + local matched, _ = _quarto.modules.patterns.match_in_list_of_patterns(rawText, _quarto.patterns.latexTableEnvPatterns) if matched then -- table_body is second matched element. - raw.text = matched[2] + rawText = matched[2] end return construct({ attr = pandoc.Attr(identifier, {}, {}), type = "Table", - content = pandoc.Blocks({ raw }), + content = pandoc.Blocks({ pandoc.RawBlock(raw.format, rawText) }), caption_long = quarto.utils.as_blocks(caption) }), false end diff --git a/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd b/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd new file mode 100644 index 0000000000..28ac12b504 --- /dev/null +++ b/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd @@ -0,0 +1,41 @@ +--- +title: Raw LaTeX table with not `tbl` in label id +format: pdf +keep-tex: true +_quarto: + tests: + pdf: + ensureLatexFileRegexMatches: + - ['[\s\S]+\\begin\{table\}\[htbp\][\s\S]+', '[\s\S]+\\caption\{\\label\{mod\}'] + - [] +--- + +This document has a raw LaTeX table with no intent to use quarto crossref. It uses a label with `tbl-` id. + +Table will be identified by floatreftarget processing but raw TeX should be left untouched in the output, while a warning still is emitted. + +```{=latex} +\begin{table}[htbp] + \caption{\label{mod} no title} + \centering + \begin{tabular}{lc} + \tabularnewline \midrule \midrule + Dependent Variable: & disp\\ + Model: & (1)\\ + \midrule + \emph{Variables}\\ + Constant & 580.9$^{***}$\\ + & (41.74)\\ + mpg & -17.43$^{***}$\\ + & (1.993)\\ + \midrule + \emph{Fit statistics}\\ + Observations & 32\\ + R$^2$ & 0.71834\\ + Adjusted R$^2$ & 0.70895\\ + \midrule \midrule + \multicolumn{2}{l}{\emph{IID standard-errors in parentheses}}\\ + \multicolumn{2}{l}{\emph{Signif. Codes: ***: 0.01, **: 0.05, *: 0.1}}\\ + \end{tabular} +\end{table} +``` \ No newline at end of file From 009315289fb6874e11ae08790ffc25221246c697 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Feb 2025 13:23:10 +0100 Subject: [PATCH 2/5] don't print `_quarto.tests` in console logging when running pandoc This prevents `printsMessage` test to work correctly --- src/command/render/pandoc.ts | 25 ++++++++++++++----- .../latex-raw-table-env-no-tbl-label.qmd | 3 +++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/command/render/pandoc.ts b/src/command/render/pandoc.ts index a6b6abd3e2..dce30f245c 100644 --- a/src/command/render/pandoc.ts +++ b/src/command/render/pandoc.ts @@ -398,6 +398,16 @@ export async function runPandoc( ...options.flags?.metadata, } as Metadata; + const cleanQuartoTestsMetadata = (metadata: Metadata) => { + // remove any metadata that is only used for testing + if (metadata["_quarto"] && typeof metadata["_quarto"] === "object") { + delete (metadata._quarto as { [key: string]: unknown })?.tests; + if (Object.keys(metadata._quarto).length === 0) { + delete metadata._quarto; + } + } + }; + // remove some metadata that are used as parameters to our lua filters const cleanMetadataForPrinting = (metadata: Metadata) => { delete metadata.params; @@ -417,7 +427,12 @@ export async function runPandoc( ) { delete metadata[kRevealJSPlugins]; } + + // Don't print _quarto.tests + // This can cause issue on regex test for printed output + cleanQuartoTestsMetadata(metadata); }; + cleanMetadataForPrinting(printMetadata); // Forward flags metadata into the format @@ -1270,11 +1285,9 @@ export async function runPandoc( delete pandocPassedMetadata.project; delete pandocPassedMetadata.website; delete pandocPassedMetadata.about; - if (pandocPassedMetadata._quarto) { - // these shouldn't be visible because they are emitted on markdown output - // and it breaks ensureFileRegexMatches - delete pandocPassedMetadata._quarto.tests; - } + // these shouldn't be visible because they are emitted on markdown output + // and it breaks ensureFileRegexMatches + cleanQuartoTestsMetadata(pandocPassedMetadata); Deno.writeTextFileSync( metadataTemp, @@ -1377,7 +1390,7 @@ export async function runPandoc( // this mutates metadata[kClassOption] function cleanupPandocMetadata(metadata: Metadata) { - // pdf classoption can end up with duplicaed options + // pdf classoption can end up with duplicated options const classoption = metadata[kClassOption]; if (Array.isArray(classoption)) { metadata[kClassOption] = ld.uniqBy( diff --git a/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd b/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd index 28ac12b504..6e24b9adbe 100644 --- a/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd +++ b/tests/docs/smoke-all/crossrefs/float/latex/latex-raw-table-env-no-tbl-label.qmd @@ -8,6 +8,9 @@ _quarto: ensureLatexFileRegexMatches: - ['[\s\S]+\\begin\{table\}\[htbp\][\s\S]+', '[\s\S]+\\caption\{\\label\{mod\}'] - [] + printsMessage: + - INFO + - 'WARNING(.*)Raw LaTeX table found with non-tbl label:' --- This document has a raw LaTeX table with no intent to use quarto crossref. It uses a label with `tbl-` id. From daf9119903568d666ece727ce2b18b388ee17d94 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Feb 2025 13:32:09 +0100 Subject: [PATCH 3/5] move filter params cleaning from print metadata with other cleaning step --- src/command/render/pandoc.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/command/render/pandoc.ts b/src/command/render/pandoc.ts index dce30f245c..8cb237ab6e 100644 --- a/src/command/render/pandoc.ts +++ b/src/command/render/pandoc.ts @@ -419,6 +419,7 @@ export async function runPandoc( delete metadata[kRevealJsScripts]; deleteProjectMetadata(metadata); deleteCrossrefMetadata(metadata); + removeFilterParams(metadata); // Don't print empty reveal-js plugins if ( @@ -1681,8 +1682,6 @@ function runPandocMessage( const printMetadata = ld.cloneDeep(metadata) as Metadata; delete printMetadata.format; - // remove filter params - removeFilterParams(printMetadata); // print message if (Object.keys(printMetadata).length > 0) { info("metadata", { bold: true }); From 26f7a2f244c7ff3527126fc36685ed5678388db6 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Feb 2025 14:40:47 +0100 Subject: [PATCH 4/5] empty _quarto field is not shouwn anymore in markdown output It can be empty after _quarto.tests field has been removed --- tests/docs/smoke-all/2024/01/22/8389.md.snapshot | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/docs/smoke-all/2024/01/22/8389.md.snapshot b/tests/docs/smoke-all/2024/01/22/8389.md.snapshot index b88a52b9ee..8a74bb81ce 100644 --- a/tests/docs/smoke-all/2024/01/22/8389.md.snapshot +++ b/tests/docs/smoke-all/2024/01/22/8389.md.snapshot @@ -1,5 +1,4 @@ --- -_quarto: {} foo: bar toc-title: Table of contents --- From d1c573e310a95dc19a3e32c5cb1d453e5b83342c Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 17 Feb 2025 11:42:12 +0100 Subject: [PATCH 5/5] Add to changelog [skip ci] --- news/changelog-1.7.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index d3240d0d7f..9f8b82e0db 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -76,3 +76,4 @@ All changes included in 1.7: - ([fb38eb5](https://github.com/quarto-dev/quarto-cli/commit/fb38eb56c11e09f44cef58fd3b697ff24bb5a3f3)) Use the `latest` parser for Acorn when analyzing JS code imported from OJS blocks. - ([#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. - ([#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. +- ([#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.