Slashes in YAML

Discussion in 'Ruby' started by Lee Smith, Jun 1, 2008.

  1. Lee Smith

    Lee Smith Guest

    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!
    --
    Posted via http://www.ruby-forum.com/.
     
    Lee Smith, Jun 1, 2008
    #1
    1. Advertising

  2. On 01.06.2008 14:47, Lee Smith wrote:
    > 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
     
    Robert Klemme, Jun 1, 2008
    #2
    1. Advertising

  3. Lee Smith

    Lee Smith Guest

    Robert Klemme wrote:
    > On 01.06.2008 14:47, Lee Smith wrote:
    >> 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


    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
    --
    Posted via http://www.ruby-forum.com/.
     
    Lee Smith, Jun 1, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    5
    Views:
    718
    Michael Dunn
    Apr 7, 2004
  2. RubyQuestions
    Replies:
    0
    Views:
    242
    RubyQuestions
    Dec 3, 2003
  3. Paul Battley

    YAML.dump/YAML.load bug

    Paul Battley, Aug 3, 2005, in forum: Ruby
    Replies:
    0
    Views:
    208
    Paul Battley
    Aug 3, 2005
  4. Eric Promislow
    Replies:
    4
    Views:
    235
    Eric Promislow
    Oct 31, 2006
  5. Dan Wilkin
    Replies:
    1
    Views:
    277
    robic0
    Jul 17, 2006
Loading...

Share This Page