Skip to content
New issue

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

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

Already on GitHub? # to your account

Example, using table caption, table number & cross-ref? #6

Open
friendly opened this issue Jul 26, 2024 · 7 comments
Open

Example, using table caption, table number & cross-ref? #6

friendly opened this issue Jul 26, 2024 · 7 comments

Comments

@friendly
Copy link

This is a great filter!

It would be very helpful if you included in the README or elsewhere a complete quarto example, including a table caption, table number, and ability to cross-reference that works with quarto.

For example, a LaTeX table I'd like to include in a Quarto doc originally (in .Rnw) looked like below. I'm not sure how to use your extension for this in .qmd.

\begin{table}[htb]
\renewcommand{\arraystretch}{1.6}
\caption{Multivariate test statistics as functions of the eigenvalues $\lambda_i$ solving $\det{\mat{H} - \lambda \mat{E}}=0$
or eigenvalues $\rho_i$ solving  $\detbracket{\mat{H} - \rho (\mat{H}+\mat{E})}=0$.
}\label{tab:criteria}
\begin{center}
\begin{tabular}{|l|l|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Criterion & Formula &  Partial $\eta^2$   \\
  \hline
  Wilks's $\Lambda$ & $\Lambda = \prod^s_i \frac{1}{1+\lambda_i}$ &  $\eta^2 = 1-\Lambda^{1/s}$   \\
  Pillai trace & $V = \sum^s_i \frac{\lambda_i}{1+\lambda_i}$ &  $\eta^2 = \frac{V}{s} $   \\
  Hotelling-Lawley trace & $H = \sum^s_i \lambda_i$ & $\eta^2 = \frac{H}{H+s}$   \\
  Roy maximum root & $R = \lambda_1$  &  $ \eta^2 = \frac{\lambda_1}{1+\lambda_1}  \\
  \hline
\end{tabular}
\end{center}
\end{table}
@tarleb
Copy link
Owner

tarleb commented Jul 27, 2024

The table must be valid LaTeX and must be parsable by pandoc. To check the latter you can use quarto pandoc --from=latex and pass the table as input. If you add --mathml to that command, then you'll also receive warnings about equations that pandoc had trouble parsing.

To fix the given case above, just add the missing $ after the last formula in the table. The \mat and \detbracket commands are not standard LaTeX, the definitions of those macros must be part of the table.

@friendly
Copy link
Author

I tried to use this in my Quarto book document, but I get no output for the table.
I'm building an HTML version

  1. Installed taleb/parse-latex using quarto
  2. Put in my _quarto.ylm: a top-level global filter (as your example suggests)
filters:
  - parse-latex
  1. Put the following in one chapter .qmd file
Does the `parse-latex` filter work?

```{=latex}
\begin{center}
\begin{tabular}{|l|l|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Criterion & Formula &  Partial $\eta^2$   \\
  \hline
  Wilks's $\Lambda$ & $\Lambda = \prod^s_i \frac{1}{1+\lambda_i}$ &  $\eta^2 = 1-\Lambda^{1/s}$   \\
  Pillai trace & $V = \sum^s_i \frac{\lambda_i}{1+\lambda_i}$ &  $\eta^2 = \frac{V}{s} $   \\
  Hotelling-Lawley trace & $H = \sum^s_i \lambda_i$ & $\eta^2 = \frac{H}{H+s}$   \\
  Roy maximum root & $R = \lambda_1$  &  $ \eta^2 = \frac{\lambda_1}{1+\lambda_1}  \\
  \hline
\end{tabular}
\end{center}
```

What I get in the HTML output is shown below. There is now output from parse-latex

image

Caption / label
Even if I can get this to work, it leaves me with the question of how to provide a table caption, label, and make it so I can refer to @tbl-stats in the text.

In quarto, I would just use a chunk like

```{r}
#| label: tbl-stats
#| tbl-cap: Multivariate tests statistics
 ...
```

@tarleb
Copy link
Owner

tarleb commented Jul 28, 2024

I understand. The table must be fixed, as described in my previous comment. Most important is to add the missing $.

@tarleb
Copy link
Owner

tarleb commented Jul 28, 2024

As for the remaining issues: I don't know, honestly. It would be a good addition for the docs, and I'd be most happy to merge a PR that adds this info.

@friendly
Copy link
Author

that pesky $! This now works:

Does the `parse-latex` filter work?

```{=latex}
\begin{center}
\begin{tabular}{|l|l|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Criterion & Formula &  Partial $\eta^2$   \\
  \hline
  Wilks's $\Lambda$ & $\Lambda = \prod^s_i \frac{1}{1+\lambda_i}$ &  $\eta^2 = 1-\Lambda^{1/s}$   \\
  Pillai trace & $V = \sum^s_i \frac{\lambda_i}{1+\lambda_i}$ &  $\eta^2 = \frac{V}{s} $   \\
  Hotelling-Lawley trace & $H = \sum^s_i \lambda_i$ & $\eta^2 = \frac{H}{H+s}$   \\
  Roy maximum root & $R = \lambda_1$  &  $ \eta^2 = \frac{\lambda_1}{1+\lambda_1}$  \\
  \hline
\end{tabular}
\end{center}
```

And produces what I want:

image

** Caption / label**
However, I still can't figure out how to do this because it is a Latex, not an R chunk, so I can't use the Quarto comments like

#' label: tab-stats
#' tbl-caption: Test statistics for multivariate tests
#' ...

It's your extension, so I thought you would have an idea how to do that.

@friendly
Copy link
Author

I started this quarto-dev discussion:
quarto-dev/quarto-cli#10432

@friendly
Copy link
Author

friendly commented Aug 1, 2024

OK: Here's the answer. I hope you will use it in your README or other examples.

To use parse-latex in a Quarto document embed the {=latex} chunk in a ::: div

::: {#tbl-mstats}

```{=latex}
\begin{center}
\begin{tabular}{|l|l|l|l|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  Criterion & Formula &  Partial $\eta^2$   \\
  \hline
  Wilks's $\Lambda$ & $\Lambda = \prod^s_i \frac{1}{1+\lambda_i}$ &  $\eta^2 = 1-\Lambda^{1/s}$   \\
  Pillai trace & $V = \sum^s_i \frac{\lambda_i}{1+\lambda_i}$ &  $\eta^2 = \frac{V}{s} $   \\
  Hotelling-Lawley trace & $H = \sum^s_i \lambda_i$ & $\eta^2 = \frac{H}{H+s}$   \\
  Roy maximum root & $R = \lambda_1$  &  $ \eta^2 = \frac{\lambda_1}{1+\lambda_1}$  \\
  \hline
\end{tabular}
\end{center}
```
Test statistics for multivariate tests combine the size of dimensions of $\mathbf{H}\mathbf{E}^{-1}$ into a single measure.
:::

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants