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 =
"prologues := 2;\n"
Instance Attribute Summary collapse
-
#dvi_viewer ⇒ Object
writeonly
Sets the attribute dvi_viewer.
-
#fname ⇒ Object
writeonly
Sets the attribute fname.
-
#metapost_options ⇒ Object
writeonly
Sets the attribute metapost_options.
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.
-
#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
85 86 87 88 89 90 |
# File 'lib/objects.rb', line 85 def initialize(fname = nil) @figures = Array.new @fname = fname @dvi_viewer = 'yap' = '-interaction=nonstopmode' end |
Instance Attribute Details
#dvi_viewer=(value) ⇒ Object (writeonly)
Sets the attribute dvi_viewer
74 75 76 |
# File 'lib/objects.rb', line 74 def dvi_viewer=(value) @dvi_viewer = value end |
#fname=(value) ⇒ Object (writeonly)
Sets the attribute fname
74 75 76 |
# File 'lib/objects.rb', line 74 def fname=(value) @fname = value end |
#metapost_options=(value) ⇒ Object (writeonly)
Sets the attribute metapost_options
74 75 76 |
# File 'lib/objects.rb', line 74 def (value) = value end |
Instance Method Details
#add_figure(f) ⇒ Object
add a new figure to this mpost file
93 94 95 |
# File 'lib/objects.rb', line 93 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
123 124 125 126 |
# File 'lib/objects.rb', line 123 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’
116 117 118 119 |
# File 'lib/objects.rb', line 116 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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/objects.rb', line 98 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 |
#view ⇒ Object
default view command is view_dvi
129 130 131 |
# File 'lib/objects.rb', line 129 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
138 139 140 141 142 143 |
# File 'lib/objects.rb', line 138 def view_dvi str = 'tex mproof' @figures.each_index { |i| str = str + ' ' + @fname + '.' + (i+1).to_s } system(str) system(@dvi_viewer + ' mproof.dvi') end |