Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw LaTeX tables with cross-references no longer render #7236

Closed
andrewheiss opened this issue Oct 16, 2023 · 16 comments · Fixed by #7240
Closed

Raw LaTeX tables with cross-references no longer render #7236

andrewheiss opened this issue Oct 16, 2023 · 16 comments · Fixed by #7240
Assignees
Labels
bug Something isn't working regression Functionality that used to work but now is broken.
Milestone

Comments

@andrewheiss
Copy link

Bug description

In Quarto 1.3, it was possible to use Quarto's cross references with raw LaTeX tables by including {#tbl-id} in the table caption (see here). In Quarto 1.4.x, this doesn't work anymore.

Steps to reproduce

This document would render fine in 1.3:

---
title: "Raw TeX cross referencing"
format: 
  pdf: default
---

See @tbl-tex.

\begin{table}[]
\caption{Some letters with LaTeX {#tbl-tex}}
\begin{tabular}{@{}lll@{}}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
\end{table}

Expected behavior

That document would render into this (lol horribly placed table)

image

Actual behavior

Quarto 1.4 produces this warning before invoking xelatex:

WARNING (/Applications/quarto/share/filters/main.lua:10047) Unable to resolve crossref @tbl-tex

And then after starting xelatex and showing the dreaded updating tlmgr message, it produces this error:

ERROR: 
compilation failed- error
Illegal parameter number in definition of \GetTitleStringResult.
<to be read again> 
                   t
l.147 \caption{Some letters with LaTeX {#tbl-tex}}

Your environment

  • IDE: Version 2023.09.0+463
  • OS: macOS Sonoma 14.0

Quarto check output

Quarto 1.4.424
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.8: OK
      Dart Sass version 1.55.0: OK
      Deno version 1.33.4: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.424
      Path: /Applications/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2022.08
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/andrew/Library/TinyTeX/bin/universal-darwin
      Version: 2022

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.5
      Path: /opt/homebrew/opt/python@3.11/bin/python3.11
      Jupyter: 5.3.0
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library
      knitr: 1.44
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK
@andrewheiss andrewheiss added the bug Something isn't working label Oct 16, 2023
@cscheid cscheid self-assigned this Oct 16, 2023
@cscheid cscheid added the regression Functionality that used to work but now is broken. label Oct 16, 2023
@cscheid
Copy link
Collaborator

cscheid commented Oct 16, 2023

Thanks for the report. There's a bit of a regression that we will fix right away, but that's not the entire situation. Some of this LaTeX code will unfortunately have to change a bit.

Specifically, the problem here is that table is a float environment, and Quarto needs to take control of those, and emit that code itself.

@cscheid
Copy link
Collaborator

cscheid commented Oct 16, 2023

Quick workaround first. If you need this to work right away, the following will get you back on track:

---
title: "Raw TeX cross referencing"
format: 
  pdf: default
---

See @tbl-tex.

::: {#tbl-tex}

```{=latex}
\begin{tabular}{@{}lll@{}}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
```

Some letters with LaTeX
:::

Note, for future reference, that we expect latex raw blocks to be surrounded by ```{=latex} and ```, so that the entire block is recognized as a single node in the Pandoc AST.

I'm going to fix the regression so that the following syntax works:

---
title: "Raw TeX cross referencing"
format: 
  pdf: default
---

See @tbl-tex.

```{=latex}
\begin{tabular}{@{}lll@{}}
\caption{Some letters with LaTeX {#tbl-tex}}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
```

Note the rawblock syntax, and note the lack of \begin{table} and \end{table}). I'll take a shot at restoring the previous syntax, but unfortunately I cannot make promises there.

@andrewheiss
Copy link
Author

Ah cool, this workaround is great. I'm actually fine with this syntax:

::: {#tbl-tex}

```{=latex}
% LaTeX stuff here
```

Caption
:::

since it feels more Quarto-y and less hacky than using the #tbl-id inside the LaTeX caption environment. It also fits with other examples of targeting floats with cross-referenceable IDs (like #7017 (comment))

I personally don't use raw LaTeX like this, though, but @cbgoodman does

@cscheid
Copy link
Collaborator

cscheid commented Oct 16, 2023

All the following raw block syntaxes should be respected once the PR lands:

---
title: "Raw TeX cross referencing"
format: 
  pdf: default
---

See @tbl-tex, @tbl-2, @tbl-3.

```{=latex}
\begin{tabular}{@{}lll@{}}
\label{tbl-tex}
\caption{Some letters with LaTeX}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
```

```{=latex}
\begin{tabular}{@{}lll@{}}
\caption{Some letters with LaTeX {#tbl-2}}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
```

As best effort, we try to remove `\begin{table}` as well:

```{=latex}
\begin{table}
\begin{tabular}{@{}lll@{}}
\caption{Some letters with LaTeX {#tbl-3}}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
\end{table}
```

@andrewheiss
Copy link
Author

This may have re-regressed? This doesn't work with 1.4.504:

---
title: "Raw TeX cross referencing"
format: 
  pdf: default
---

See @tbl-tex:

```{=latex}
\begin{tabular}{@{}lll@{}}
\label{tbl-tex}
\caption{Some letters with LaTeX}
\toprule
Column 1 & Column 2 & Column 3 \\ \midrule
A        & B        & C        \\
D        & E        & F        \\
G        & H        & I        \\ \bottomrule
\end{tabular}
```

It causes this error:

Error running filter /Applications/quarto/share/filters/main.lua:
Inline, list of Inlines, or string expected, got nil
	while retrieving function argument inlines
	while retrieving arguments for function Inlines
stack traceback:
	/Applications/quarto/share/filters/main.lua:10697: in upvalue 'index_caption'
	/Applications/quarto/share/filters/main.lua:10784: in function 'writeFullIndex'
	/Applications/quarto/share/filters/main.lua:10685: in field 'Pandoc'
	/Applications/quarto/share/filters/main.lua:216: in function 'run_emulated_filter'
	/Applications/quarto/share/filters/main.lua:917: in local 'callback'
	/Applications/quarto/share/filters/main.lua:932: in upvalue 'run_emulated_filter_chain'
	/Applications/quarto/share/filters/main.lua:968: in function </Applications/quarto/share/filters/main.lua:965>

@andrewheiss
Copy link
Author

In 1.4.504, I actually can't seem to run anything in this test https://github.com/quarto-dev/quarto-cli/blob/cfebb28fedb4ddd530bdcd7f4d7ffd782a5a6509/tests/docs/smoke-all/2023/10/16/7236.qmd —it leads to the same error:

Error running filter /Applications/quarto/share/filters/main.lua:
Inline, list of Inlines, or string expected, got nil
	while retrieving function argument inlines
	while retrieving arguments for function Inlines
stack traceback:
	/Applications/quarto/share/filters/main.lua:10697: in upvalue 'index_caption'
	/Applications/quarto/share/filters/main.lua:10784: in function 'writeFullIndex'
	/Applications/quarto/share/filters/main.lua:10685: in field 'Pandoc'
	/Applications/quarto/share/filters/main.lua:216: in function 'run_emulated_filter'
	/Applications/quarto/share/filters/main.lua:917: in local 'callback'
	/Applications/quarto/share/filters/main.lua:932: in upvalue 'run_emulated_filter_chain'
	/Applications/quarto/share/filters/main.lua:968: in function </Applications/quarto/share/filters/main.lua:965>

@cderv
Copy link
Collaborator

cderv commented Nov 17, 2023

In 1.4.504, I actually can't seem to run anything in this test cfebb28/tests/docs/smoke-all/2023/10/16/7236.qmd —it leads to the same error:

Our test passes though... 😓 🤔
https://github.com/quarto-dev/quarto-cli/actions/runs/6906144301/job/18790515928#step:26:155

@cscheid
Copy link
Collaborator

cscheid commented Nov 17, 2023

That error makes me suspect a stale .quarto directory somewhere.

@cderv
Copy link
Collaborator

cderv commented Nov 17, 2023

Yes I can verify that this happens only when the document is inside a quarto project, even of type: default

If I remove _quarto.yml then I don't get the error, like in our test suite

@cscheid should we open a new issue maybe ? I don't know well this .quarto folder - so not sure what happens here exactly

@cscheid
Copy link
Collaborator

cscheid commented Nov 17, 2023

I actually can repro this myself outside of a project, so it's something else.

And now I can't repro anymore :(

We should never crash. With that said, I'll reiterate my previous "using raw latex for \label{}s etc is fraught, and you should really really consider if that's what you need to do" stance.

@cderv
Copy link
Collaborator

cderv commented Nov 17, 2023

We should never crash.

Agree with that - especially I don't expect a rendering for a same .qmd working when outside a project context and not working inside a project context, especially with default type project.

@andrewheiss
Copy link
Author

This error does indeed happen inside a quarto project


haha I'm all for avoiding using raw latex :)

This was just one of my attempts to try sticking a longtable (#7604 (comment)) in the document, but then I ran into this weird issue 🤷‍♂️

@cscheid
Copy link
Collaborator

cscheid commented Nov 17, 2023

This was just one of my attempts to try sticking a longtable (#7604 (comment)) in the document, but then I ran into this weird issue 🤷‍♂️

Andrew can you please not use our software in a completely reasonable manner? :lolsob:

@cscheid
Copy link
Collaborator

cscheid commented Nov 17, 2023

This is a "fun" one that happens more broadly than we might expect. What's going on is that since we now have the ability to catch and treat raw latex blocks as real cross-referenceable elements inside Quarto, the caption content can itself be entirely a raw block. That confuses index_caption in src/resources/filters/crossref/index.lua, and that file only comes up in a project setting.

In 1.5 we're probably going to do away with the distinction between project and non-project renders entirely, which should make this class of bugs go away.

(PR incoming.)

@likanzhan
Copy link

Is this problem being resolve in 1.5.57 ?
It seems I still experience the same thing.

@mcanouil
Copy link
Collaborator

@likanzhan please open a GutHub Discussion if you are not sure there is still a bug. You can reference this issue.
Also note, that we need a fully reproducible example to work with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Functionality that used to work but now is broken.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants