Geek Lair

Replace normal double quote with Latex double quote

with 3 comments

By default Latex formats " as an end quote. If you have a  document with sentences which start with ", the formatted document can look awkward with sentences starting with end quotes.

To replace them with `` so that Latex formats them as opening quotes, you can use sed. Save the following code in a text file:

# This is for lines which start with double quotes, but do not end with them
s/^"\([^"][^"]*$\)/``\1/g

# This is for sentences which both start and end with double quotes
s/"\([^"]*"\)/``\1/g

 
Save the file as dblQtReplacer. Now run your Latex file through sed:

sed -f dblQtReplacer latex_file.tex > new_latex_file.tex

Written by anonir

December 15, 2008 at 12:46

Posted in Linux

Tagged with ,

3 Responses

Subscribe to comments with RSS.

  1. WoW…. Really Superb…
    Thanks a lot..

    This helped me a lot and saved my time too 🙂

    Arulalan.T

    June 10, 2010 at 00:00

  2. Sweet! Just what I needed… I didn’t want to have to figure out those regular expressions for myself 😛

    Steve

    June 12, 2010 at 07:22

    • # Formats Quotes in LaTeX
      # ‘quote’ -> `quote’
      # “quote” -> “quote”
      s/\(\s\)’/\1`/g
      s/\(\s\)”/\1“/g
      s/\([^“]*\)”/\1”/g

      Dustin Dorroh

      March 2, 2011 at 09:36


Leave a reply to Arulalan.T Cancel reply