r - Function to sanitize strings for LaTeX compilation? -
while xtable() has sanitize.text.function argument allows sanitize strings special charaters stop latex compilation breaking in sweave/knitr documents, package not export function userspace.
how can sanitize strings asdf_text outside of xtable context, have transformed asdf\_text? (if possible prefer small, self-contained solution.)
unless misunderstand question, think you've overlooked latextranslate, in hmisc package (and documented on same page ?latex):
‘latextranslate’ translates particular items in character strings latex format, e.g., makes ‘a^2 = a\$^2\$’ superscript within variable labels. latex names of greek letters (e.g., ‘"alpha"’) have backslashes added if ‘greek==true’. math mode inserted needed. ‘latextranslate’ assumes input text has matches, e.g. ‘[) [] (] ()’, , surrounding ‘\$\$’ ok.
library("hmisc") latextranslate("asdf_text") ## [1] "asdf\\_text" latextranslate("a^2") ## [1] "a$^{2}$"
Comments
Post a Comment