code_junkie

How can one turn regular quotes (i.e. ', ") into LaTeX/TeX quotes (i.e. `', ``'')

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Ben said "buttons, dear sir".
  2. I replied "Did you say 'buttons'?" to him.
  3.  
  4. Ben said ``buttons, dear sir''.
  5. I replied ``Did you say `buttons'?'' to him.
  6.  
  7. Ben said “buttons, dear sir”.
  8. I replied “Did you say ‘buttons’?”
  9.  
  10. input: text+
  11. text: uquote|squote|dquote
  12. squote "'" text "'"
  13. dquote """ text """
  14. uquote: [contraction|.]+
  15. contraction: [A-Za-z]+ "'" [A-Za-z]+
  16.  
  17. s/"(w)/``$1/g;
  18. s/'(w)/`$1/g;
  19. s/([w.?!])"/$1''/g;
  20.  
  21. # A single or double quote before a word character, preceded
  22. # by start of line, whitespace or punctuation gets converted
  23. # to "`" or "``" respectively.
  24.  
  25. $text =~ s{ ( ^ | [sp{IsPunct}] )( ['"] ) (?= w ) }
  26. { $2 eq '"' ? "$1``" : "$1`" }mgxe;
  27.  
  28. # A double quote preceded by a word or punctuation character
  29. # and followed by whitespace or end of line gets converted to
  30. # "''". (Final single quotes are represented by themselves so
  31. # we don't need to worry about those.)
  32.  
  33. $text =~ s{ (?<= [wp{IsPunct}] ) " (?= s | $ ) }
  34. { "''" }mgxe
  35.  
  36. '([ w-]+)'", " `\1'
Add Comment
Please, Sign In to add comment