Skip to content

Commit

Permalink
checks if pdflatex is installed or not. automatically runs pdflatex
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Tan Wei Hao committed Apr 12, 2012
1 parent 0a1dfe8 commit 7459e92
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -25,7 +25,7 @@ In case your system doesn't have `pdflatex`, you should install a [LaTeX](http:/

### List all available themes (84 and counting!)

Many of the themes found in CodeRippa can be found [here](http://wiki.macromates.com/Themes/UserSubmittedThemes)
Many of the themes found in CodeRippa can be found [here](http://textmatetheme.com/)

$ code_rippa -l

Expand Down Expand Up @@ -88,10 +88,8 @@ Currently this gem is in its infancy. Any bug reports and feature requests are v
- 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.
- Wrap lines of troublesome files such as minified javascript and parser generator outputs.
- Sensible defaults, removed the need for specifying the syntax
- Detects if pdflatex is installed, and automatically runs pdflatex if so

#### TODO

- Generate warnings when syntax is not supported.

### 0.0.6

Expand Down
51 changes: 42 additions & 9 deletions lib/code_rippa.rb
Expand Up @@ -30,7 +30,8 @@ module CodeRippa
#
# Returns nothing
def self.parse(path, theme)
output = ""
logfile = File.open('code_rippa.log', 'w')
output = ""

if FileTest.file?(path)
output = parse_file(path, theme)
Expand All @@ -39,7 +40,7 @@ def self.parse(path, theme)
counter = 0

Find.find path do |p|
puts "Parsing: #{p} "
logfile << "Parsing: #{p}\n"
depth = p.to_s.count('/')

if File.basename(p)[0] == ?.
Expand All @@ -49,7 +50,7 @@ def self.parse(path, theme)
begin
output << parse_file(p, theme)
rescue Exception => e
puts "Failed: #{p}".color(:red)
logfile << "* Failed: #{p}\n"
end
end
counter += 1
Expand All @@ -61,8 +62,23 @@ def self.parse(path, theme)
outfile = File.open('out.tex', 'w')
output = preamble(theme) << output << postscript
outfile.write output
puts completed_message(path, File.expand_path(outfile))
outfile.close

# Run the 'pdflatex' command
puts "=================================================="
if pdflatex_installed?
puts "pdflatex found!. Converting TeX -> PDF".color(:green)
puts "Compiling [1/2]"
`pdflatex -interaction=batchmode #{File.expand_path(outfile)}`
puts "Compiling [2/2]"
`pdflatex -interaction=batchmode #{File.expand_path(outfile)}`
puts completed_message(path, File.expand_path(outfile))
else
puts install_pdflatex_message "#{File.expand_path(outfile)}"
end
puts "=================================================="

logfile.close
end


Expand Down Expand Up @@ -280,13 +296,30 @@ def self.postscript
end

def self.completed_message(in_path, out_path)
msg = "Completed successfully.\n".color(:green)
msg = "Success!. ".color(:green)
msg << "Output file written to: "
msg << "#{out_path.gsub!('tex', 'pdf')}".color(:green)
end

def self.install_pdflatex_message(out_path)
msg = "You do not have 'pdflatex' installed!\n".color(:red)
msg << "Please install it at "
msg << "http://www.tug.org/texlive'\n".color(:yellow)
msg << "Output TEX file written to: "
msg << "#{out_path}\n".color(:yellow)
msg << "Now run "
msg << "pdflatex -interaction=batchmode #{out_path}".color(:red)
msg << " ** TWICE ** " if FileTest.directory?(in_path)
msg << "to generate PDF."
end

def self.pdflatex_installed?
cmd = 'pdflatex'
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = "#{path}/#{cmd}#{ext}"
exe if File.executable? exe
return exe
end
end
nil
end

end
Expand Down

0 comments on commit 7459e92

Please sign in to comment.