Module: ReVIEW::LaTeXUtils
- Included in:
- LATEXBuilder, PDFMaker
- Defined in:
- lib/review/latexutils.rb
Instance Method Summary collapse
- #escape(str) ⇒ Object (also: #escape_latex)
- #escape_index(str) ⇒ Object
- #escape_mendex_display(str) ⇒ Object
- #escape_mendex_key(str) ⇒ Object
- #escape_url(str) ⇒ Object
- #initialize_metachars(texcommand) ⇒ Object
- #macro(name, *args) ⇒ Object
- #unescape(str) ⇒ Object (also: #unescape_latex)
Instance Method Details
#escape(str) ⇒ Object Also known as: escape_latex
67 68 69 |
# File 'lib/review/latexutils.rb', line 67 def escape(str) str.gsub(@metachars_re) { |s| @metachars[s] or raise "unknown trans char: #{s}" } end |
#escape_index(str) ⇒ Object
80 81 82 |
# File 'lib/review/latexutils.rb', line 80 def escape_index(str) str.gsub(/[@!|"]/) { |s| '"' + s } end |
#escape_mendex_display(str) ⇒ Object
88 89 90 |
# File 'lib/review/latexutils.rb', line 88 def escape_mendex_display(str) str.gsub('\{', '\reviewleftcurlybrace{}').gsub('\}', '\reviewrightcurlybrace{}') end |
#escape_mendex_key(str) ⇒ Object
84 85 86 |
# File 'lib/review/latexutils.rb', line 84 def escape_mendex_key(str) str.gsub('"|', '|').tr('{', '{').tr('}', '}') 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
14 15 16 17 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 |
# File 'lib/review/latexutils.rb', line 14 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 # rubocop:disable Style/RedundantArgument @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(str) ⇒ Object Also known as: unescape_latex
73 74 75 76 |
# File 'lib/review/latexutils.rb', line 73 def unescape(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 |