rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
1.94k stars 197 forks source link

problems exporting math symbols to latex #1201

Open prtc opened 1 year ago

prtc commented 1 year ago

hello. firstly, thank you for the package, when I first learned about it was one of those "I love R"'s days.

I am having problems exporting to latex, specifically when I have math symbols in the column header. The backslashes and dollar signs are being parsed but that breaks the latex.

MWE:

tibble(
  filter = c("a", "b", "c"), 
  lambda_pivot = c(637.4, 879.0, 912.8)
  ) |> 
  gt() |> 
  cols_label(
    filter = "Filter",
    lambda_pivot = r"($\lambda_{pivot}$)",
  ) |> 
  gtsave(filename = "output/table_test.tex")

produces the output:

\begin{longtable}{lr}
\toprule
Filter & \$\textbackslash{}lambda\_\{pivot\}\$ \\ 
\midrule
a & 637.4 \\ 
b & 879.0 \\ 
c & 912.8 \\ 
\bottomrule
\end{longtable}

The problem is in the line: Filter & \$\textbackslash{}lambda\_\{pivot\}\$ \\

when I expect it to be: Filter & $\lambda_{pivot}$ \\ which will be correctly parsed by latex.

I also tried doubling the $ and \ or using espace_latex() but the output is the same.

I tried to look into the other issues here related to latex but all of them seemed more complicated than mine.

Am I missing something? How can I get a raw $\lambda_{pivot}$ in the output file? thx

snhansen commented 5 days ago

I'm looking for a solution to this problem as well. Did you ever find a way around this, @prtc?