diff --git a/src/format/pdf/format-pdf.ts b/src/format/pdf/format-pdf.ts index 3de6b6738bc..03d8910394b 100644 --- a/src/format/pdf/format-pdf.ts +++ b/src/format/pdf/format-pdf.ts @@ -981,6 +981,10 @@ const longtableBottomCaptionProcessor = () => { caption = line; capturing = true; return undefined; + } else if (line.match(/^\\endlastfoot/) && caption) { + line = `\\tabularnewline\n${caption}\n${line}`; + caption = undefined; + return line; } else if (line.match(/^\\end{longtable}$/)) { scanning = false; if (caption) { diff --git a/tests/docs/latex-output/table-captions.qmd b/tests/docs/latex-output/table-captions.qmd deleted file mode 100644 index d55d1031fac..00000000000 --- a/tests/docs/latex-output/table-captions.qmd +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: Document With a Variety of Table Captions -subtitle: Designed to exercise any special logic or processing of table captions -tbl-cap-location: bottom -format: latex ---- - - -## Markdown tables - - -| Default | Left | Right | Center | -|---------|:-----|------:|:------:| -| 12 | 12 | 12 | 12 | -| 123 | 123 | 123 | 123 | -| 1 | 1 | 1 | 1 | - -: Demonstration of pipe table syntax - - -| Default | Left | Right | Center | -|---------|:-----|------:|:------:| -| 12 | 12 | 12 | 12 | -| 123 | 123 | 123 | 123 | -| 1 | 1 | 1 | 1 | - -: Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. - -| Default | Left | Right | Center | -|---------|:-----|------:|:------:| -| 12 | 12 | 12 | 12 | -| 123 | 123 | 123 | 123 | -| 1 | 1 | 1 | 1 | - -: Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption. - - -| Col1 | Col2 | Col3 | -|------|------|------| -| A | B | C | -| E | F | G | -| A | G | G | - -: Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption. {#tbl-letters} - -See @tbl-letters. - - -```{r} -#| tbl-cap: "Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output." -#| tbl-colwidths: [60,40] -library(knitr) -kable(head(cars)) -``` - - -```{r} -#| tbl-cap: "Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption." -#| tbl-colwidths: [60,40] - -kable(head(cars)) -``` - -```{r} -kable(head(cars), format = "latex", longtable = TRUE, caption = "HELLO CARS") -``` - diff --git a/tests/docs/smoke-all/latex/table-captions-bottom.qmd b/tests/docs/smoke-all/latex/table-captions-bottom.qmd new file mode 100644 index 00000000000..fca9767a02e --- /dev/null +++ b/tests/docs/smoke-all/latex/table-captions-bottom.qmd @@ -0,0 +1,104 @@ +--- +title: Document With a Variety of Table Captions +subtitle: Designed to exercise any special logic or processing of table captions +tbl-cap-location: bottom +format: pdf +keep-tex: true +_quarto: + tests: + pdf: + noErrors: default + ensureLatexFileRegexMatches: + - + # Document should not be broken + - '\\end\{document\}' + # Any table with T1 - T6 caption + - '\\begin\{longtable\}[\s\S]+\\caption\{T([1-6]|8)[\s\S]+\\endlastfoot' + # Special table with endlastfoot + - '\\begin\{longtable\}[\s\S]+\\caption\{.*T7[^}]+\}[\s\S]+\\tabularnewline\s+\\end\{longtable\}' + - + # checking caption is moved + - '\\begin\{longtable\}.*\s+\\caption\{.*T7[^}]+\}' + # checking that all caption are correctly not place after endlastfoot (using +? is important in regex) + - '\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T1' + - '\\caption\{T1[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T2' + - '\\caption\{T2[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T3' + - '\\caption\{T3[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T4' + - '\\caption\{T4[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T5' + - '\\caption\{T5[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T6' + - '\\caption\{T7[\s\S]+?\\begin\{longtable\}[\s\S]+?\\endlastfoot[\s\S]+?\\caption\{T8' +--- + + +## Markdown tables + + +| Default | Left | Right | Center | +|---------|:-----|------:|:------:| +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | + +: T1 Demonstration of pipe table syntax + + +| Default | Left | Right | Center | +|---------|:-----|------:|:------:| +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | + +: T2 Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. + +| Default | Left | Right | Center | +|---------|:-----|------:|:------:| +| 12 | 12 | 12 | 12 | +| 123 | 123 | 123 | 123 | +| 1 | 1 | 1 | 1 | + +: T3 Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption. + + +| Col1 | Col2 | Col3 | +|------|------|------| +| A | B | C | +| E | F | G | +| A | G | G | + +: T4 Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption. {#tbl-letters} + +See @tbl-letters. + + +```{r} +#| tbl-cap: "T5 Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output." +#| tbl-colwidths: [60,40] +library(knitr) +kable(head(cars)) +``` + + +```{r} +#| tbl-cap: "T6 Demonstration of pipe table syntax that is very long and will probably wrap in the LaTeX output. As a result this could cause issues when we try to read the caption." +#| tbl-colwidths: [60,40] + +kable(head(cars)) +``` + +```{r} +#| label: tbl-cars +kable(head(cars), format = "latex", longtable = TRUE, caption = "T7 HELLO CARS") +``` + +::: {#tbl-1} + +| X | Y | +|---------|:-----| +| 12 | 12 | +| 123 | 123 | +| 1 | 1 | + +T8 Table caption +::: + +See @tbl-1 \ No newline at end of file diff --git a/tests/new-smoke-all-test.ps1 b/tests/new-smoke-all-test.ps1 index 638a95bd6ff..493b9c8fb07 100644 --- a/tests/new-smoke-all-test.ps1 +++ b/tests/new-smoke-all-test.ps1 @@ -41,6 +41,9 @@ _quarto: noErrors: default fileExists: supportPath: mediabag/lter_penguins.png + ensureLatexFileRegexMatches: + - [] + - [] typst: ensureFileRegexMatches: - [] diff --git a/tests/new-smoke-all-test.sh b/tests/new-smoke-all-test.sh index fa6f2f4cdcf..cb00edb2506 100755 --- a/tests/new-smoke-all-test.sh +++ b/tests/new-smoke-all-test.sh @@ -39,6 +39,9 @@ _quarto: noErrors: default fileExists: supportPath: mediabag/lter_penguins.png + ensureLatexFileRegexMatches: + - [] + - [] typst: ensureFileRegexMatches: - [] diff --git a/tests/smoke/render/render-latex-output.test.ts b/tests/smoke/render/render-latex-output.test.ts index 4fc7d4ac760..03123f48258 100644 --- a/tests/smoke/render/render-latex-output.test.ts +++ b/tests/smoke/render/render-latex-output.test.ts @@ -16,18 +16,3 @@ renderVerifyLatexOutput(docs("latex-output/figure-div.qmd"), [ /\\caption{\\label{fig-foo}This is the figure}/, /See Figure~\\ref{fig-foo} for more\./, ]); - -// FIXME before merging: -// -// I don't understand how this test works even in 1.3 -// -// All captions should be placed at the bottom -// Note that the 'D' or '\\' are present after the caption command because one of the -// test tables purposely msisses the caption handling to be sure that we don't -// completely destory the document. Be sure that any test document captions that must be -// moved started with D or have a label. -renderVerifyLatexOutput(docs("latex-output/table-captions.qmd"), [ - /\\end{document}/, -], [ - /\\begin{longtable}.*\s\\caption{[D\\]/, -]); diff --git a/tests/verify.ts b/tests/verify.ts index 9e303fe9396..407b4af36aa 100644 --- a/tests/verify.ts +++ b/tests/verify.ts @@ -456,7 +456,7 @@ export const ensureTypstFileRegexMatches = ( return(verifyKeepFileRegexMatches("pdf", "typ")(file, matchesUntyped, noMatchesUntyped)); }; -// FIXME: do this properly without resorting on file having keep-typ +// FIXME: do this properly without resorting on file having keep-tex export const ensureLatexFileRegexMatches = ( file: string, matchesUntyped: (string | RegExp)[],