Module: Polytexnic::Preprocessor::Latex
- Included in:
- Polytexnic::Preprocessor
- Defined in:
- lib/polytexnic/preprocessors/latex.rb
Instance Method Summary collapse
-
#clean_latex_document ⇒ Object
Returns LaTeX with hashed versions of literal environments.
-
#convert_gifs(text) ⇒ Object
Convert GIFs to PNGs.
- #polish_tables(text) ⇒ Object
-
#process_asides(text) ⇒ Object
Processes aside environments.
- #to_processed_latex ⇒ Object
Instance Method Details
#clean_latex_document ⇒ Object
Returns LaTeX with hashed versions of literal environments. Literal environments are hashed and passed through the pipeline so that we can process things like refs and hyperrefs using gsubs.
14 15 16 17 18 19 20 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 14 def clean_latex_document cache_literal(@polytex, :latex).tap do |doc| (doc, Proc.new { |source| cache_literal(source, :latex) }, 'tex') end end |
#convert_gifs(text) ⇒ Object
Convert GIFs to PNGs. Unfortunately, xelatex doesn’t support GIFs. This converts the included filenames to use ‘.png’ in place of ‘.gif’. When used with the Softcover system, the correct PNG files are automatically created on the fly.
26 27 28 29 30 31 32 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 26 def convert_gifs(text) text.tap do text.gsub!(/\\(includegraphics|image|imagebox)\{(.*)\.gif\}/) do "\\#{$1}{#{$2}.png}" end end end |
#polish_tables(text) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 34 def polish_tables(text) text.tap do text.gsub!(/^\s*(\\begin\{table\})/) do "#{$1}\n\\begin{center}\n\\small\n" end text.gsub!(/^\s*(\\end\{table\})/) { "\\end{center}\n#{$1}" } end end |
#process_asides(text) ⇒ Object
Processes aside environments. In order to get nice framed & shaded aside boxes, we need to transform the default aside into a new environment.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 46 def process_asides(text) # Transform asides with labels and headings. aside_regex = /\\begin{aside}\n\s* \\label{(.*?)}\s* \\heading{(.*?)}\n (.*?) \\end{aside}/mx text.tap do text.gsub!(aside_regex) do %(\\begin{shaded_aside}{#{$2}}{#{$1}}\n#{$3}\n\\end{shaded_aside}) end end end |
#to_processed_latex ⇒ Object
5 6 7 8 9 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 5 def to_processed_latex @polytex = convert_gifs( polish_tables( process_asides(clean_latex_document))) end |