public
Rubygem
Description: A lightweight and flexible website management system.
Homepage: http://webby.rubyforge.org/
Clone URL: git://github.com/TwP/webby.git
reworked how TeX is handled
TwP (author)
Sat Mar 01 10:46:32 -0800 2008
commit  9979613fd583554ac0ded2f898e96d09f1d4ff15
tree    4b976dee749219d3d3b6ca0213731f4bfd272815
parent  16bd4074d2e5b1c70b2ba416a04185a675231b56
...
86
87
88
89
90
91
92
93
94
95
96
97
...
86
87
88
 
 
 
 
 
 
89
90
91
0
@@ -86,12 +86,6 @@ module GraphvizHelper
0
       return
0
     end
0
 
0
- # ensure the requested graphviz command actually exists
0
- %x[#{cmd} -V 2>&1]
0
- unless 0 == $?.exitstatus
0
- raise NameError, "'#{cmd}' not found on the path"
0
- end
0
-
0
     # pull the name of the graph|digraph out of the DOT script
0
     name = text.match(%r/\A\s*(?:strict\s+)?(?:di)?graph\s+([A-Za-z_][A-Za-z0-9_]*)\s+\{/o)[1]
0
 
...
2
3
4
5
6
7
8
...
36
37
38
39
40
41
42
43
...
60
61
62
63
64
65
66
 
 
 
 
 
67
68
69
70
71
72
73
74
75
76
77
 
 
 
78
79
80
...
88
89
90
91
92
93
 
 
 
 
 
94
95
96
97
 
 
 
 
 
98
99
 
 
100
101
102
...
109
110
111
112
113
114
 
 
 
 
 
 
 
 
115
116
117
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
 
172
173
174
...
2
3
4
 
5
6
7
...
35
36
37
 
 
38
39
40
...
57
58
59
 
 
 
 
60
61
62
63
64
65
 
 
 
 
 
 
 
 
 
 
66
67
68
69
70
71
...
79
80
81
 
 
 
82
83
84
85
86
87
 
88
 
89
90
91
92
93
94
 
95
96
97
98
99
...
106
107
108
 
 
 
109
110
111
112
113
114
115
116
117
118
119
...
135
136
137
 
138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
140
 
141
142
143
144
0
@@ -2,7 +2,6 @@
0
 
0
 require Webby.libpath(*%w[webby stelan mktemp])
0
 require 'fileutils'
0
-require 'tempfile'
0
 
0
 module Webby::Helpers
0
 module TexImgHelper
0
@@ -36,8 +35,6 @@ module TexImgHelper
0
   # TeX color spec, or #aabbcc) [default is black]
0
   # :resolution : the desired resolution in dpi (HxV)
0
   # [default is 150x150]
0
- # :antialias : if false, disables anti-aliasing in the resulting image
0
- # [default is true]
0
   #
0
   # the following options are passed as-is to the generated <img /> tag
0
   # :style : CSS styles to apply to the <img />
0
@@ -60,21 +57,15 @@ module TexImgHelper
0
       return
0
     end
0
 
0
- # create a temporary file for holding any error messages
0
- # from the graphviz program
0
- err = Tempfile.new('graphviz_err')
0
- err.close
0
+ path = opts.getopt(:path)
0
+ type = opts.getopt(:type, 'png')
0
+ bg = opts.getopt(:bg, 'white')
0
+ fg = opts.getopt(:fg, 'black')
0
+ res = opts.getopt(:resolution, '150x150')
0
 
0
- path = opts.getopt(:path)
0
- type = opts.getopt(:type, 'png')
0
- bg = opts.getopt(:bg, 'white')
0
- fg = opts.getopt(:fg, 'black')
0
- res = opts.getopt(:resolution, '150x150')
0
- aa = opts.getopt(:antialias, true)
0
-
0
- # fix the color escaping
0
- fg = TexImgHelper.tex_color(fg)
0
- bg = TexImgHelper.tex_color(bg)
0
+ # fix color escaping
0
+ fg = fg =~ %r/^[a-zA-Z]+$/ ? fg : "\"#{fg}\""
0
+ bg = bg =~ %r/^[a-zA-Z]+$/ ? bg : "\"#{bg}\""
0
 
0
     # generate the image filename based on the path, graph name, and type
0
     # of image to generate
0
@@ -88,15 +79,21 @@ module TexImgHelper
0
     FileUtils.mkpath(::File.join(out_dir, path)) unless path.nil?
0
 
0
     tex = <<-TEX
0
- \\documentclass[12pt]{article}
0
- \\usepackage[usenames,dvipsnames]{color}
0
- \\usepackage[dvips]{graphicx}
0
+ \\nonstopmode
0
+ \\documentclass{article}
0
+ \\usepackage[T1]{fontenc}
0
+ \\usepackage{amsmath,amsfonts,amssymb,wasysym,latexsym,marvosym,txfonts}
0
+ \\usepackage[pdftex]{color}
0
       \\pagestyle{empty}
0
- \\pagecolor#{bg}
0
       \\begin{document}
0
- {\\color#{fg}
0
+ \\fontsize{12}{24}
0
+ \\selectfont
0
+ \\color{white}
0
+ \\pagecolor{black}
0
+ \\[
0
       #{text}
0
- }\\end{document}
0
+ \\]
0
+ \\end{document}
0
     TEX
0
     tex.gsub!(%r/\n\s+/, "\n").strip!
0
 
0
@@ -109,9 +106,14 @@ module TexImgHelper
0
       File.open('out.tex', 'w') {|fd| fd.puts tex}
0
       dev_null = test(?e, "/dev/null") ? "/dev/null" : "NUL:"
0
 
0
- %x[latex -interaction=batchmode out.tex &> #{dev_null}]
0
- %x[dvips -o out.eps -E out.dvi &> #{dev_null}]
0
- %x[convert +adjoin #{aa ? '-antialias' : '+antialias'} -density #{res} out.eps #{out_file} &> #{dev_null}]
0
+ %x[pdflatex -interaction=batchmode out.tex &> #{dev_null}]
0
+
0
+ convert = "\\( -density #{res} out.pdf -trim +repage \\) "
0
+ convert << "\\( +clone -fuzz 100% -fill #{fg} -opaque black \\) "
0
+ convert << "+swap -compose copy-opacity -composite "
0
+ convert << "\\( +clone -fuzz 100% -fill #{bg} -opaque white +matte \\) "
0
+ convert << "+swap -compose over -composite #{out_file}"
0
+ %x[convert #{convert} &> #{dev_null}]
0
     ensure
0
       Dir.chdir(pwd)
0
       FileUtils.rm_rf(tmpdir) if test(?e, tmpdir)
0
@@ -133,42 +135,10 @@ module TexImgHelper
0
 
0
     buffer[pos..-1] = out
0
     return
0
- ensure
0
   end
0
-
0
- # call-seq:
0
- # TexImgHelper.tex_color( string ) => string
0
- #
0
- # Taken the given color _string_ and convert it to a TeX color spec. The
0
- # input string can be either a RGB Hex value, a TeX color spec, or a color
0
- # name.
0
- #
0
- # tex_color( '#666666' ) #=> [rgb]{0.4,0.4,0.4}
0
- # tex_color( 'Tan' ) #=> {Tan}
0
- # tex_color( '[rgb]{1,0,0}' ) #=> [rgb]{1,0,0}
0
- #
0
- # This is an example of an invalid Hex RGB color -- they must contain six
0
- # hexidecimal characters to be valid.
0
- #
0
- # tex_color( '#333' ) #=> {#333}
0
- #
0
- def self.tex_color( color )
0
- case color
0
- when %r/^#([A-Fa-f0-9]{6})/o
0
- hex = $1
0
- rgb = []
0
- hex.scan(%r/../) {|n| rgb << Float(n.to_i(16))/255.0}
0
- "[rgb]{#{rgb.join(',')}}"
0
- when %r/^[\{\[]/o
0
- "{#{color}}"
0
- else
0
- color
0
- end
0
- end
0
-
0
 end # module TexImgHelper
0
 
0
-%x[latex --version 2>&1]
0
+%x[pdflatex --version 2>&1]
0
 if 0 == $?.exitstatus
0
   %x[convert --version 2>&1]
0
   if 0 == $?.exitstatus

Comments

    No one has commented yet.