gt icon indicating copy to clipboard operation
gt copied to clipboard

problems exporting math symbols to latex

Open prtc opened this issue 2 years ago • 1 comments

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

prtc avatar Jan 27 '23 20:01 prtc