Module: ReVIEW::LaTeXUtils
- Included in:
- LATEXBuilder, PDFMaker
- Defined in:
- lib/review/latexutils.rb
Instance Method Summary collapse
- #escape_index(str) ⇒ Object
- #escape_latex(str) ⇒ Object (also: #escape)
- #escape_url(str) ⇒ Object
- #initialize_metachars(texcommand) ⇒ Object
- #macro(name, *args) ⇒ Object
- #unescape_latex(str) ⇒ Object (also: #unescape)
Instance Method Details
#escape_index(str) ⇒ Object
88 89 90 |
# File 'lib/review/latexutils.rb', line 88 def escape_index(str) str.gsub(/[@!|"]/) {|s| '"' + s } end |
#escape_latex(str) ⇒ Object Also known as: escape
71 72 73 74 75 |
# File 'lib/review/latexutils.rb', line 71 def escape_latex(str) str.gsub(@metachars_re) {|s| @metachars[s] or raise "unknown trans char: #{s}" } end |
#escape_url(str) ⇒ Object
92 93 94 |
# File 'lib/review/latexutils.rb', line 92 def escape_url(str) str.gsub(/[\#%]/) {|s| '\\'+s } end |
#initialize_metachars(texcommand) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/review/latexutils.rb', line 18 def (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(''))}]/u @metachars_invert = @metachars.invert end |
#macro(name, *args) ⇒ Object
96 97 98 |
# File 'lib/review/latexutils.rb', line 96 def macro(name, *args) "\\#{name}" + args.map {|a| "{#{a}}" }.join('') end |
#unescape_latex(str) ⇒ Object Also known as: unescape
79 80 81 82 83 84 |
# File 'lib/review/latexutils.rb', line 79 def unescape_latex(str) = Regexp.new(@metachars_invert.keys.collect{|key| Regexp.escape(key)}.join('|')) str.gsub() {|s| @metachars_invert[s] or raise "unknown trans char: #{s}" } end |