Skip to content
This repository
Browse code

checks if pdflatex is installed or not. automatically runs pdflatex

  • Loading branch information...
commit 7459e92eb25690d8aeefe5ba5e1b8b0746c0c76a 1 parent 0a1dfe8
authored April 12, 2012
6  README.md
Source Rendered
@@ -25,7 +25,7 @@ In case your system doesn't have `pdflatex`, you should install a [LaTeX](http:/
25 25
 
26 26
 ### List all available themes (84 and counting!)
27 27
 
28  
-Many of the themes found in CodeRippa can be found [here](http://wiki.macromates.com/Themes/UserSubmittedThemes)	
  28
+Many of the themes found in CodeRippa can be found [here](http://textmatetheme.com/)	
29 29
 		
30 30
 	$ code_rippa -l
31 31
 	
@@ -88,10 +88,8 @@ Currently this gem is in its infancy. Any bug reports and feature requests are v
88 88
 - Themes! Glorious themes! 84 themes to choose from! Props to [filmgirl](https://github.com/filmgirl/TextMate-Themes), and the rest of the wonderful TM users who submitted their themes.
89 89
 - Wrap lines of troublesome files such as minified javascript and parser generator outputs.
90 90
 - Sensible defaults, removed the need for specifying the syntax 
  91
+- Detects if pdflatex is installed, and automatically runs pdflatex if so
91 92
 
92  
-#### TODO
93  
-
94  
-- Generate warnings when syntax is not supported.
95 93
 
96 94
 ### 0.0.6
97 95
 
51  lib/code_rippa.rb
@@ -30,7 +30,8 @@ module CodeRippa
30 30
   #
31 31
   # Returns nothing 
32 32
   def self.parse(path, theme)
33  
-    output = ""
  33
+    logfile = File.open('code_rippa.log', 'w')
  34
+    output  = ""
34 35
     
35 36
     if FileTest.file?(path)
36 37
       output = parse_file(path, theme)
@@ -39,7 +40,7 @@ def self.parse(path, theme)
39 40
       counter  = 0          
40 41
 
41 42
       Find.find path do |p|     
42  
-        puts "Parsing: #{p} "
  43
+        logfile << "Parsing: #{p}\n"
43 44
         depth = p.to_s.count('/')
44 45
 
45 46
         if File.basename(p)[0] == ?.
@@ -49,7 +50,7 @@ def self.parse(path, theme)
49 50
           begin
50 51
             output << parse_file(p, theme)
51 52
           rescue Exception => e
52  
-            puts "Failed: #{p}".color(:red)
  53
+            logfile << "* Failed: #{p}\n"
53 54
           end
54 55
         end
55 56
         counter += 1
@@ -61,8 +62,23 @@ def self.parse(path, theme)
61 62
     outfile = File.open('out.tex', 'w')     
62 63
     output  = preamble(theme) << output << postscript
63 64
     outfile.write output
64  
-    puts completed_message(path, File.expand_path(outfile))
65 65
     outfile.close
  66
+
  67
+    # Run the 'pdflatex' command
  68
+    puts "=================================================="
  69
+    if pdflatex_installed?
  70
+      puts "pdflatex found!. Converting TeX -> PDF".color(:green)
  71
+      puts "Compiling [1/2]" 
  72
+      `pdflatex -interaction=batchmode #{File.expand_path(outfile)}`
  73
+      puts "Compiling [2/2]" 
  74
+      `pdflatex -interaction=batchmode #{File.expand_path(outfile)}` 
  75
+      puts completed_message(path, File.expand_path(outfile))
  76
+    else
  77
+      puts install_pdflatex_message "#{File.expand_path(outfile)}"
  78
+    end
  79
+    puts "=================================================="
  80
+
  81
+    logfile.close
66 82
   end
67 83
   
68 84
   
@@ -280,13 +296,30 @@ def self.postscript
280 296
   end
281 297
   
282 298
   def self.completed_message(in_path, out_path)
283  
-    msg =  "Completed successfully.\n".color(:green)
  299
+    msg =  "Success!. ".color(:green)
284 300
     msg << "Output file written to: "
  301
+    msg << "#{out_path.gsub!('tex', 'pdf')}".color(:green)
  302
+  end
  303
+
  304
+  def self.install_pdflatex_message(out_path)
  305
+    msg = "You do not have 'pdflatex' installed!\n".color(:red)
  306
+    msg << "Please install it at "
  307
+    msg << "http://www.tug.org/texlive'\n".color(:yellow)
  308
+    msg << "Output TEX file written to: "
285 309
     msg << "#{out_path}\n".color(:yellow)
286  
-    msg << "Now run "
287  
-    msg << "pdflatex -interaction=batchmode #{out_path}".color(:red)
288  
-    msg << " ** TWICE ** " if FileTest.directory?(in_path)
289  
-    msg << "to generate PDF."
  310
+  end
  311
+
  312
+  def self.pdflatex_installed?
  313
+    cmd  = 'pdflatex'
  314
+    exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  315
+    ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
  316
+      exts.each do |ext|
  317
+        exe = "#{path}/#{cmd}#{ext}"
  318
+        exe if File.executable? exe
  319
+        return exe
  320
+      end
  321
+    end
  322
+    nil  
290 323
   end
291 324
   
292 325
 end

0 notes on commit 7459e92

Please sign in to comment.
Something went wrong with that request. Please try again.