parse-latex icon indicating copy to clipboard operation
parse-latex copied to clipboard

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

Open friendly opened this issue 1 year ago • 7 comments

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}

friendly avatar Jul 26 '24 18:07 friendly

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.

tarleb avatar Jul 27 '24 09:07 tarleb

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
 ...
```

friendly avatar Jul 27 '24 16:07 friendly

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

tarleb avatar Jul 28 '24 15:07 tarleb

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.

tarleb avatar Jul 28 '24 17:07 tarleb

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 avatar Jul 30 '24 22:07 friendly

I started this quarto-dev discussion: https://github.com/quarto-dev/quarto-cli/discussions/10432

friendly avatar Jul 31 '24 14:07 friendly

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.
:::

friendly avatar Aug 01 '24 14:08 friendly