Module: Asciidoctor::LaTeX::TeXPostProcess

Defined in:
lib/asciidoctor/latex/node_processors.rb

Overview

TeXPostProcess cleans up undesired transformations inside the TeX enveronment. Strings &ampp;, &gt;, &lt; are mapped back to &, >, < and \ is conserved.

Class Method Summary (collapse)

Class Method Details

+ (Object) make_substitutions(str)

(1) & (2) are needed together to protect \ inside of matrices, etc.



689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/asciidoctor/latex/node_processors.rb', line 689

def self.make_substitutions str
  str = str.gsub('\\\\', '@@')   # (1)
  matches = match_inline str
  if matches.count > 0
    str = make_substitutions_in_matches matches, str
  end
  matches = match_block str
  if matches.count > 0
    str = make_substitutions_in_matches matches, str
  end
  str = str.tr('@','\\')         # (2)
  str
end

+ (Object) make_substitutions1(str)



672
673
674
675
676
# File 'lib/asciidoctor/latex/node_processors.rb', line 672

def self.make_substitutions1 str
  str = str.gsub("&amp;", "&")
  str = str.gsub("&gt;", ">")
  str = str.gsub("&lt;", "<")
end

+ (Object) make_substitutions_in_matches(matches, str)



678
679
680
681
682
683
684
685
# File 'lib/asciidoctor/latex/node_processors.rb', line 678

def self.make_substitutions_in_matches matches, str
  matches.each do |m|
    m_str = m[0]
    m_transformed = make_substitutions1 m_str
    str = str.gsub(m_str,m_transformed)
  end
  str
end

+ (Object) match_block(str)



667
668
669
670
# File 'lib/asciidoctor/latex/node_processors.rb', line 667

def self.match_block str
  rx_tex_block = /\\\[(.*?)\\\]/m
  str.scan rx_tex_block
end

+ (Object) match_inline(str)



662
663
664
665
# File 'lib/asciidoctor/latex/node_processors.rb', line 662

def self.match_inline str
  rx_tex_inline = /\$(.*?)\$/
  str.scan rx_tex_inline
end

+ (Object) stem_substitutions(str)



703
704
705
706
707
708
# File 'lib/asciidoctor/latex/node_processors.rb', line 703

def self.stem_substitutions str
  str = str.gsub('\\\\', '@@')   # (1)
  str = make_substitutions1 str
  str = str.tr('@','\\')         # (2)
  str
end