Slashes in YAML

L

Lee Smith

Hello all...

I wish to store several LaTex constants in YAML file and process them in
ruby. LaTex uses single slashes ('\') as a markup specifier. If I
specify a yaml string containing a single slash (e.g., "^{\circ}" which
is the LaTex markup for 'degrees Celsius') ruby will helpfully escape
the slash for me yielding "^{\\circ}"

I've tried all sorts of quoting and other tricks to tell ruby to "leave
my string alone" but it insists on escaping my slash!

Thanks!
 
R

Robert Klemme

I wish to store several LaTex constants in YAML file and process them in
ruby. LaTex uses single slashes ('\') as a markup specifier. If I
specify a yaml string containing a single slash (e.g., "^{\circ}" which
is the LaTex markup for 'degrees Celsius') ruby will helpfully escape
the slash for me yielding "^{\\circ}"

I've tried all sorts of quoting and other tricks to tell ruby to "leave
my string alone" but it insists on escaping my slash!

I'm not sure what you're after. Do you want to use YAML strings
directly for LaTex? Or did you trap into the usual inspect issue:

irb(main):002:0> puts "a\\b"
a\b
=> nil
irb(main):003:0> puts "a\\b".inspect
"a\\b"
=> nil

Cheers

robert
 
L

Lee Smith

Robert said:
I'm not sure what you're after. Do you want to use YAML strings
directly for LaTex? Or did you trap into the usual inspect issue:

irb(main):002:0> puts "a\\b"
a\b
=> nil
irb(main):003:0> puts "a\\b".inspect
"a\\b"
=> nil

Cheers

robert

Robert,

Thanks for the quick response:

Here's the snippet of my YAML file

--- snip ---
C:
- ^{\circ}
- degree Celsius
- degrees Celsius
--- snip ---

After loading the file via YAML::load into a "myVar" object, when I
pretty print (pp) the hash myVar["C"][0], the output is:

"^{\\circ}"

REAL TIME UPDATE... Your comment on "inspect" reminded me to verify that
pretty printing was doing just that!

puts myVar["C"][0] produces exactly what I wanted... "^{\circ}" (with
one slash!)

Thanks for your help!

Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top