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.
- #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 to hyperrefs using gsubs.
12 13 14 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 12 def clean_latex_document cache_literal(@polytex, :latex) end |
#polish_tables(text) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 16 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 28 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 |
# File 'lib/polytexnic/preprocessors/latex.rb', line 5 def to_processed_latex @polytex = polish_tables(process_asides(clean_latex_document)) end |