Module: ReVIEW::LaTeXUtils
- Included in:
- LATEXBuilder
- Defined in:
- lib/review/latexutils.rb
Constant Summary collapse
- MATACHARS =
{ '#' => '\#', "$" => '\textdollar{}', '%' => '\%', '&' => '\&', '{' => '\{', '}' => '\}', '_' => '\textunderscore{}', '^' => '\textasciicircum{}', '~' => '\textasciitilde{}', '|' => '\textbar{}', '<' => '\textless{}', '>' => '\textgreater{}', "\\" => '\reviewbackslash{}', "-" => '{-}', '⓪' => '\UTF{24EA}', '①' => '\UTF{2460}', '②' => '\UTF{2461}', '③' => '\UTF{2462}', '④' => '\UTF{2463}', '⑤' => '\UTF{2464}', '⑥' => '\UTF{2465}', '⑦' => '\UTF{2466}', '⑧' => '\UTF{2467}', '⑨' => '\UTF{2468}', '⑩' => '\UTF{2469}', }
- METACHARS_RE =
/[#{Regexp.escape(MATACHARS.keys.join(''))}]/
- MATACHARS_INVERT =
MATACHARS.invert
Instance Method Summary collapse
- #escape_index(str) ⇒ Object
- #escape_latex(str) ⇒ Object (also: #escape)
- #escape_url(str) ⇒ Object
- #macro(name, *args) ⇒ Object
- #unescape_latex(str) ⇒ Object
Instance Method Details
#escape_index(str) ⇒ Object
65 66 67 |
# File 'lib/review/latexutils.rb', line 65 def escape_index(str) str.gsub(/[@!|"]/) {|s| '"' + s } end |
#escape_latex(str) ⇒ Object Also known as: escape
50 51 52 53 54 |
# File 'lib/review/latexutils.rb', line 50 def escape_latex(str) str.gsub(METACHARS_RE) {|s| MATACHARS[s] or raise "unknown trans char: #{s}" } end |
#escape_url(str) ⇒ Object
69 70 71 |
# File 'lib/review/latexutils.rb', line 69 def escape_url(str) str.gsub(/[\#%]/) {|s| '\\'+s } end |
#macro(name, *args) ⇒ Object
73 74 75 |
# File 'lib/review/latexutils.rb', line 73 def macro(name, *args) "\\#{name}" + args.map {|a| "{#{a}}" }.join('') end |
#unescape_latex(str) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/review/latexutils.rb', line 58 def unescape_latex(str) = Regexp.new(MATACHARS_INVERT.keys.collect{|key| Regexp.escape(key)}.join('|')) str.gsub() {|s| MATACHARS_INVERT[s] or raise "unknown trans char: #{s}" } end |