Created
          November 12, 2012 18:47 
        
      - 
      
- 
        Save mrtazz/4061113 to your computer and use it in GitHub Desktop. 
    a rakefile for generating pdf from latex
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Rakefile for building tex file | |
| require "rake/clean" | |
| require 'yaml' | |
| # variables | |
| BASE = "thesis" | |
| TYPE = ".tex" | |
| OUT = ".pdf" | |
| TEXFILE = FileList[BASE+TYPE] | |
| OUTFILE = BASE+OUT | |
| DVIFILE = BASE+".dvi" | |
| IMAGES = FileList["**/*.eps"] | |
| BIBTEXCMD = "/usr/texbin/bibtex" | |
| LATEXCMD = "/usr/texbin/pdflatex" | |
| PSCMD = "/usr/local/bin/ps2pdf" | |
| DVICMD = "/usr/texbin/dvipdfmx" | |
| TEMP = | |
| PDF = FileList["**/*.pdf"] | |
| ABBR = "include/abbreviations.tex" | |
| ABBR_YML = "include/abbreviations.yml" | |
| task :default => [OUTFILE] | |
| desc "compile literature with bibtex" | |
| task :bibtex do | |
| latex | |
| sh %{#{BIBTEXCMD} "#{BASE}"} | |
| end | |
| desc "rules for the DVI file" | |
| file DVIFILE => [ABBR, :bibtex] do | |
| latex | |
| end | |
| desc "show all todos for tex files" | |
| task :todo do | |
| sh "/usr/local/bin/ack --tex -r TODO" | |
| end | |
| desc "create PDF from DVI" | |
| file OUTFILE => DVIFILE do | |
| sh "#{DVICMD} #{BASE}.dvi" | |
| end | |
| desc "convert eps to pdf" | |
| task :epsconvert do | |
| IMAGES.each do |i| | |
| dir = File.dirname(i) | |
| file = File.basename(i, ".eps") | |
| pdffile = dir+"/"+file+".pdf" | |
| pdffile.gsub!(/ /, '\\\\ ') | |
| i.gsub!(/ /, '\\\\ ') | |
| if not File.exists?(pdffile) | |
| sh %{#{PSCMD} -dEPSCrop #{i} #{pdffile}} | |
| end | |
| end | |
| end | |
| desc "sort abbreviations.yml and pipe it into abbreviations.tex" | |
| file ABBR => ABBR_YML do |f| | |
| dict = File.open(ABBR_YML) {|yf| YAML::load(yf)} | |
| file = File.open(f.name, 'w') | |
| file.puts "\\begin{tabular}{ll}" | |
| dict.sort.each do |k,v| | |
| file.puts "#{k} & #{v} \\\\" | |
| end | |
| file.puts "\\end{tabular}" | |
| end | |
| CLEAN.include(FileList["*.aux", "*.bbl", "*.blg", "*.idx", "*.log", | |
| "*.out", "*.toc", "*.dvi", "*.lot", "*.nlo"]) | |
| CLOBBER.include(FileList["*.aux", "*.bbl", "*.blg", "*.idx", "*.log", | |
| "*.out", "*.toc", "*.dvi", "*.lot", "*.nlo"], | |
| PDF, OUTFILE) | |
| # method to compile latex, which can be | |
| # run more than once per rake run | |
| def latex | |
| 2.times do | |
| sh %{#{LATEXCMD} "#{TEXFILE.to_s}"} | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment