Class: RubyPost::File
Overview
metapost file A metapost file can contain many figures. Notes: Filenames cannot contain underscores for view to work!
compile_to_str has a dodgy backspace handler.
Constant Summary collapse
- @@start_of_file =
<<END_OF_STRING prologues := 2; filenametemplate "%j-%c.mps"; verbatimtex %&latex \\documentclass{minimal} \\begin{document} etex END_OF_STRING
Instance Attribute Summary collapse
-
#fname ⇒ Object
writeonly
Sets the attribute fname.
Instance Method Summary collapse
-
#add_figure(f) ⇒ Object
add a new figure to this mpost file.
-
#compile(fname = @fname) ⇒ Object
calls compile_to_file and writes the and copmiles the metapost commands if mpost is in the path.
-
#compile_to_file(fname = @fname) ⇒ Object
writes the string of metapost commands to a file named ‘fname.mp’.
-
#compile_to_string ⇒ Object
returns the mp file as a str.
-
#initialize(fname = nil) ⇒ File
constructor
input ‘sarith’ so that metapost can read exponential notation.
-
#startstring(str) ⇒ Object
set a string at the very start of the file.
-
#view ⇒ Object
default view command is view_dvi.
-
#view_dvi ⇒ Object
assumes that the file has already been compiled by metapost.
Constructor Details
#initialize(fname = nil) ⇒ File
input ‘sarith’ so that metapost can read exponential notation
88 89 90 91 |
# File 'lib/objects.rb', line 88 def initialize(fname = nil) @figures = Array.new @fname = fname end |
Instance Attribute Details
#fname=(value) ⇒ Object (writeonly)
Sets the attribute fname
75 76 77 |
# File 'lib/objects.rb', line 75 def fname=(value) @fname = value end |
Instance Method Details
#add_figure(f) ⇒ Object
add a new figure to this mpost file
107 108 109 |
# File 'lib/objects.rb', line 107 def add_figure(f) @figures.push(f) end |
#compile(fname = @fname) ⇒ Object
calls compile_to_file and writes the and copmiles the metapost commands if mpost is in the path
137 138 139 140 |
# File 'lib/objects.rb', line 137 def compile(fname=@fname) compile_to_file(fname) system('mpost ' + fname + '.mp') end |
#compile_to_file(fname = @fname) ⇒ Object
writes the string of metapost commands to a file named ‘fname.mp’
130 131 132 133 |
# File 'lib/objects.rb', line 130 def compile_to_file(fname=@fname) @fname = fname IO::File.open(fname + '.mp','w') { |f| f.puts self.compile_to_string } end |
#compile_to_string ⇒ Object
returns the mp file as a str
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/objects.rb', line 112 def compile_to_string str = @@start_of_file + @@Inputs.compile #save the original metapost picture str = str + @@picture_precompiler.compile @figures.each_index do |i| str = str + 'beginfig(' + (i+1).to_s + ");\n" + @figures[i].compile + "\n" end str = str + "end;\n" #remove the backspaces strback = str.gsub(/.[\b]/, '') if (strback==nil) return str else return strback end end |
#startstring(str) ⇒ Object
set a string at the very start of the file. For example, prologues latex setup etc. The default string is:
prologues := 2;
filenametemplate “%j-%c.mps”;
verbatimtex
%&latex
documentclassminimal
begindocument
etex
102 103 104 |
# File 'lib/objects.rb', line 102 def startstring(str) @@start_of_file = str end |
#view ⇒ Object
default view command is view_dvi
143 144 145 |
# File 'lib/objects.rb', line 143 def view view_dvi end |
#view_dvi ⇒ Object
assumes that the file has already been compiled by metapost. ie compile_to_ps has already been called. This assumes that the yap viewer and tex is in your path. Install miktex to get these by default. <p> Notes: Filenames cannot contain underscores for view_dvi to work. The “tex mproof” will not work with underscores
152 153 154 155 156 157 |
# File 'lib/objects.rb', line 152 def view_dvi str = 'tex mproof' @figures.each_index { |i| str = str + ' ' + @fname + '.' + (i+1).to_s } system(str) system('yap mproof.dvi') end |