[R] Question on sub(stitute) X_1 -> X\_1

Christian Hoffmann christian.hoffmann at wsl.ch
Fri Dec 1 09:03:33 CET 2006


Hi,

Searching the archives has brought no clue:

For a tex chunk in an Sweave text

"Oracle query results: differences \Sexpr{varname},..."

I need to change the string varname from "X_1" to "X\_1",

sub("_",??,"X_+")  -> "X\_1"

so that subsequent Latex will generate "X_1" (i.e. show the underscore) 
instead of "X subscript 1" (subscripting the "1")

Various trials with sub("_","\\_",varname) and the like have not helped.

sub("_","\\_","X_1")             -> "X_1"
sub("_","\\_","X_1",fixed=TRUE)  -> "X\\_1"
sub("_","\_","X_1",fixed=TRUE)   -> "X_1"

Latex will translate  "X\\_1" to X  (linefeed) 1  !!

Thanks for help

Christian
-- 
Dr. Christian W. Hoffmann,
Swiss Federal Research Institute WSL
Zuercherstrasse 111, CH-8903 Birmensdorf, Switzerland
Tel +41-44-7392-277 (office), -111(exchange), -215  (fax)
christian.hoffmann at wsl.ch,  www.wsl.ch/staff/christian.hoffmann




More information about the R-help mailing list