lib/review/latexutils.rb in review-0.6.0 vs lib/review/latexutils.rb in review-0.9.0
- old
+ new
@@ -12,33 +12,42 @@
module ReVIEW
module LaTeXUtils
MATACHARS = {
- '#' => '\symbol{"23}',
- "$" => '\symbol{"24}',
+ '#' => '\#',
+ "$" => '\textdollar{}',
'%' => '\%',
'&' => '\&',
'{' => '\{',
'}' => '\}',
- '_' => '\symbol{"5F}',
+ '_' => '\textunderscore{}',
'^' => '\textasciicircum{}',
'~' => '\textasciitilde{}',
'|' => '\textbar{}',
- '<' => '\symbol{"3C}',
- '>' => '\symbol{"3E}',
- "\\" => '\symbol{"5C}'
+ '<' => '\textless{}',
+ '>' => '\textgreater{}',
+ "\\" => '\reviewbackslash{}'
}
METACHARS_RE = /[#{Regexp.escape(MATACHARS.keys.join(''))}]/
+ MATACHARS_INVERT = MATACHARS.invert
+
def escape_latex(str)
str.gsub(METACHARS_RE) {|s|
MATACHARS[s] or raise "unknown trans char: #{s}"
}
end
alias escape escape_latex
+
+ def unescape_latex(str)
+ metachars_invert_re = Regexp.new(MATACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|'))
+ str.gsub(metachars_invert_re) {|s|
+ MATACHARS_INVERT[s] or raise "unknown trans char: #{s}"
+ }
+ end
def escape_index(str)
str.gsub(/[@!|"]/) {|s| '"' + s }
end