Class: CosSinCalc::Triangle::Formatter::Latex
- Inherits:
-
Object
- Object
- CosSinCalc::Triangle::Formatter::Latex
- Defined in:
- lib/cossincalc/triangle/formatter/latex.rb
Instance Method Summary collapse
-
#document_content(image_filename = nil) ⇒ Object
Returns the content of the LaTeX document.
-
#initialize(formatter) ⇒ Latex
constructor
Initializes the LaTeX renderer.
-
#save_pdf(filename) ⇒ Object
Saves the generated LaTeX to a TeX file and then converts it using pdflatex.
-
#save_tex(filename) ⇒ Object
Saves the generated LaTeX to a TeX file.
-
#to_tex(filename = nil) ⇒ Object
Returns the generated LaTeX code.
Constructor Details
#initialize(formatter) ⇒ Latex
Initializes the LaTeX renderer.
6 7 8 9 |
# File 'lib/cossincalc/triangle/formatter/latex.rb', line 6 def initialize(formatter) @formatter = formatter @triangle = formatter.triangle end |
Instance Method Details
#document_content(image_filename = nil) ⇒ Object
Returns the content of the LaTeX document.
38 39 40 |
# File 'lib/cossincalc/triangle/formatter/latex.rb', line 38 def document_content(image_filename = nil) variable_table + "\\\\[0.2 cm]\n\n" + equations + "\n\n" + drawing(image_filename) end |
#save_pdf(filename) ⇒ Object
Saves the generated LaTeX to a TeX file and then converts it using pdflatex. The filename should be provided without the .pdf extension.
32 33 34 35 |
# File 'lib/cossincalc/triangle/formatter/latex.rb', line 32 def save_pdf(filename) save_tex(filename) Dir.cd_to(filename) { |basename| `pdflatex "#{basename}.tex"` } end |
#save_tex(filename) ⇒ Object
Saves the generated LaTeX to a TeX file. The filename should be provided without the .tex extension.
26 27 28 |
# File 'lib/cossincalc/triangle/formatter/latex.rb', line 26 def save_tex(filename) File.open("#{filename}.tex", 'w') { |f| f.write(to_tex(filename)) } end |
#to_tex(filename = nil) ⇒ Object
Returns the generated LaTeX code.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cossincalc/triangle/formatter/latex.rb', line 12 def to_tex(filename = nil) document(@triangle.alt ? (<<-EOT) : document_content(filename)) #{document_content(filename ? filename + '-1' : nil)} \\newpage \\section*{Alternative triangle} Another triangle can be constructed based on the variables given.\\\\[0.2 cm] #{Latex.new(@triangle.alt.humanize(f.precision)).document_content(filename ? filename + '-2' : nil)} EOT end |