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

Quarto LaTeX output removes Fixest table labels when output: asis is enabled #11878

Open
turbanisch opened this issue Jan 15, 2025 · 2 comments
Assignees
Labels
latex LaTeX engines related libraries and technologies support a request for support tables Issues with Tables including the gt integration

Comments

@turbanisch
Copy link

When I render the following document, Fixest's label of the table in the .tex file is gone – I assume it was removed by Quarto, perhaps because Fixest puts the \label{} within the \caption{}?

qmd file:

---
format:
  pdf: 
    keep-tex: true
---

LaTeX markup (shortened):

```latex
\begin{table}[htbp]
   \caption{ no title}
   \centering
   \begin{tabular}{lc}
      ...
\end{table}
```


```{r}
#| output: asis
library(fixest)

mod <- feols(disp ~ mpg, data = mtcars)

etable(mod, tex = TRUE, label = "blah")

```

Curiously, this only seems to be the case when I enable output: asis. Without this option, the LaTeX markup looks fine:

Image
@cderv cderv transferred this issue from quarto-dev/quarto Jan 16, 2025
@cderv
Copy link
Collaborator

cderv commented Jan 16, 2025

I don't think this is an issue, it is all about the output that etable() is producing.

For context, with R, knitr is ran. When a function is used to produced output in knitr, a custom knit_print() could be used so that the right thing is done. More on that at https://cran.r-project.org/web/packages/knitr/vignettes/knit_print.html

It seems fixest does not have one. This means the print method will be used. Let's look at etable() function. It seems that the developer choose to handle the formatting of the output of this function when used in knitr right inside the function. (instead of using a class and a custom knit_print.etable method for example.

It seems the etable() function has a lot of argument some of them control the output type. You selected tex = TRUE (and not markdown = TRUE). This will have impact on what is outputed. Then by setting output: asis, you are asking for raw output directly inserted inside the document as with raw markdown. (no cell output wrapping). This is used to produced raw content from cell (https://quarto.org/docs/computations/execution-options.html#raw-output)

etable() will output a raw tex. Without output: asis, it will be wrapped in code cell syntax so that it is show as code cell in your output. (like in your screenshot).

When output: asis is passed, the raw tex is inserted as raw content in the document, and then process by Quarto.

First, raw tex should be inserted using the raw block syntax

```{=latex}
...
```

This is the safest, and should be done by etable() directly.

Then Quarto will process table that cross reference can work. https://quarto.org/docs/authoring/cross-references.html#tables

For that Quarto will catch \caption() and \label to modify the table produced so cross ref would be used.

Though I see this warning here

WARNING (C:/Users/chris/DOCUME~1/DEV_R/QUARTO~1/src/resources/filters/./quarto-pre/parsefiguredivs.lua:730) Raw LaTeX table found with non-tbl label: blah
Won't be able to cross-reference this table using Quarto's native crossref system.

as no ID has been used, and crossref can't work, but maybe the table should then stay untouched in that case.

I'll try to understand what happens here, and how to prevent quarto do that, but just so you know fixest may need some adaptation.

This is how Quarto should be used for cross referencing a table (using tbl-* as label)

```{r}
#| output: asis
#| echo: false
library(fixest)

mod <- feols(disp ~ mpg, data = mtcars)

etable(mod, tex = TRUE, label = "tbl-mod")

```

See @tbl-mod

Though it seems we have a problem in our processing with newlines as results is

Image

So positioning is skipping out... 🤔

@cderv cderv self-assigned this Jan 16, 2025
@cderv cderv added the latex LaTeX engines related libraries and technologies label Jan 16, 2025
@cscheid
Copy link
Collaborator

cscheid commented Jan 16, 2025

I sound like a broken record, but libraries should not emit \begin{table} if they want to work with Quarto.

@mcanouil mcanouil added tables Issues with Tables including the gt integration support a request for support labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
latex LaTeX engines related libraries and technologies support a request for support tables Issues with Tables including the gt integration
Projects
None yet
Development

No branches or pull requests

4 participants