Class: LatexUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/texstylist/latex_util.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLatexUtil

Returns a new instance of LatexUtil.



10
11
12
# File 'lib/texstylist/latex_util.rb', line 10

def initialize
  @verb_store = {}
end

Class Attribute Details

.citation_regexObject

Returns the value of attribute citation_regex.



7
8
9
# File 'lib/texstylist/latex_util.rb', line 7

def citation_regex
  @citation_regex
end

Instance Method Details

#postprocess_verb(text) ⇒ Object



44
45
46
47
48
49
# File 'lib/texstylist/latex_util.rb', line 44

def postprocess_verb(text)
  return text if @verb_store.empty?
  text.gsub(/aureplacedverb(\w+)/) do |match|
    "\\verb|"+@verb_store[$1]+"|"
  end
end

#preprocess_verb(text) ⇒ 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
# File 'lib/texstylist/latex_util.rb', line 14

def preprocess_verb(text)
  @verb_store = {}
  verb_index = 'a'
  # 1. Escape source \verb
  text = text.gsub(/\\verb(.)((?:(?!\1).)*)\1/m) do |match|
    verb_index << 'a'
    key = "aureplacedverb#{verb_index} "
    @verb_store[verb_index] = $2
    key
  end

  # 2. Escape source \begin{verbatim}
  text = text.gsub(/\\begin\{verbatim\}(.*?)\\end\{verbatim\}/m) do |match|
    verb_index << 'a'
    key = "aureplacedverb#{verb_index} "
    @verb_store[verb_index] = $1
    key
  end

  # 3. Escape rendered \verb (as <code> elements)
  text = text.gsub(/\<code\>(.*?)\<\/code\>/m) do |match|
    verb_index << 'a'
    key = "aureplacedverb#{verb_index} "
    @verb_store[verb_index] = $1
    key
  end

  return text
end