module ReVIEW::LaTeXUtils

Public Instance Methods

escape(str)
Alias for: escape_latex
escape_index(str) click to toggle source
# File lib/review/latexutils.rb, line 87
def escape_index(str)
  str.gsub(/[@!|"]/) {|s| '"' + s }
end
escape_latex(str) click to toggle source
# File lib/review/latexutils.rb, line 70
def escape_latex(str)
  str.gsub(@metachars_re) {|s|
    @metachars[s] or raise "unknown trans char: #{s}"
  }
end
Also aliased as: escape
escape_url(str) click to toggle source
# File lib/review/latexutils.rb, line 91
def escape_url(str)
  str.gsub(/[\#%]/) {|s| '\'+s }
end
initialize_metachars(texcommand) click to toggle source
# File lib/review/latexutils.rb, line 17
def initialize_metachars(texcommand)
  @metachars = {
    '#' => '\#',
    "$" => '\textdollar{}',
    '%' => '\%',
    '&' => '\&',
    '{' => '\{',
    '}' => '\}',
    '_' => '\textunderscore{}',
    '^' => '\textasciicircum{}',
    '~' => '\textasciitilde{}',
    '|' => '\textbar{}',
    '<' => '\textless{}',
    '>' => '\textgreater{}',
    "\\" => '\reviewbackslash{}',
    "-" => '{-}'
  }

  if File.basename(texcommand, ".*") == "platex"
    @metachars.merge!({
                       '⓪' => '\UTF{24EA}',
                       '①' => '\UTF{2460}',
                       '②' => '\UTF{2461}',
                       '③' => '\UTF{2462}',
                       '④' => '\UTF{2463}',
                       '⑤' => '\UTF{2464}',
                       '⑥' => '\UTF{2465}',
                       '⑦' => '\UTF{2466}',
                       '⑧' => '\UTF{2467}',
                       '⑨' => '\UTF{2468}',
                       '⑩' => '\UTF{2469}',
                       '⑪' => '\UTF{246A}',
                       '⑫' => '\UTF{246B}',
                       '⑬' => '\UTF{246C}',
                       '⑭' => '\UTF{246D}',
                       '⑮' => '\UTF{246E}',
                       '⑯' => '\UTF{246F}'
                     })

    kanalist = %w{。 「 」 、 ・ ヲ ァ ィ ゥ ェ ォ ャ ュ ョ ッ ー ア イ ウ エ
                  オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ
                  ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ン ゙ ゚}
    kanalist.each do |char|
      char_jisx0208 = NKF::nkf('-WwX',char)
      @metachars[char] = "\\aj半角{#{char_jisx0208}}"
    end
  end

  @metachars_re = /[#{Regexp.escape(@metachars.keys.join(''))}]/

  @metachars_invert = @metachars.invert
end
macro(name, *args) click to toggle source
# File lib/review/latexutils.rb, line 95
def macro(name, *args)
  "\\#{name}" + args.map {|a| "{#{a}}" }.join('')
end
unescape(str)
Alias for: unescape_latex
unescape_latex(str) click to toggle source
# File lib/review/latexutils.rb, line 78
def unescape_latex(str)
  metachars_invert_re = Regexp.new(@metachars_invert.keys.collect{|key| Regexp.escape(key)}.join('|'))
  str.gsub(metachars_invert_re) {|s|
    @metachars_invert[s] or raise "unknown trans char: #{s}"
  }
end
Also aliased as: unescape