Escaping LaTeX control symbols in Hmisc::latex

你。 提交于 2020-03-03 05:08:19

问题


I have a data frame in R which unfortunately has strings in it containing dollar signs. When the function latex() from the package Hmisc converts this data frame to a LaTeX table, the dollar signs are not escaped. This renders the LaTeX uncompilable. Is there a way within Hmisc to escape dollar signs when formatting values from a data frame?

I can't run search and replace over all dollar signs afterwards either, because the Hmisc itself adds dollar signs for the empty cells.

Minimal example:

> latex("test$test",file="")
# returns:
\begin{table}[!tbp]
% [...]
test$test\tabularnewline
% [...]
\end{table}

# should return:
\begin{table}[!tbp]
% [...]
test\$test\tabularnewline
% [...]
\end{table}

回答1:


You can look at the latexTranslate function, from Hmisc :

R> latexTranslate("3%")
[1] "3\\%"


来源:https://stackoverflow.com/questions/14771714/escaping-latex-control-symbols-in-hmisclatex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!