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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -