Advertisement
Guest User

Gradle build script for TeX

a guest
Jul 18th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.37 KB | None | 0 0
  1. defaultTasks "tex"
  2.  
  3. ext.jobname = 'main'
  4. ext.texengine = 'lualatex'
  5. ext.mainfile = file('main.tex')
  6. ext.tmpdir = file("${buildDir}/tex-output")
  7.  
  8. task tex << {
  9.   tmpdir.mkdirs()
  10.   texRun()
  11.   texErrors(file("${tmpdir}/${jobname}.log"))
  12.   ant.copy(file: "${tmpdir}/${jobname}.pdf", todir: projectDir, overwrite: true, force: true)
  13.   pdfInfo()
  14.   fontInfo()
  15. }
  16.  
  17. def texRun() {
  18.   def proc = "${texengine} --jobname=\"${jobname}\" --output-directory=\"${tmpdir.absolutePath}\" --interaction=nonstopmode \"${mainfile.absolutePath}\"".execute()
  19.   proc.in.eachLine {line -> println line}
  20.   proc.err.eachLine {line -> println 'ERROR: ' + line}
  21.   proc.waitFor()
  22. }
  23.  
  24. def texErrors(logFile) {
  25.   def errors = logFile.readLines('utf-8').findAll { line -> line.startsWith('! ') }
  26.   if(0 < errors.size) {
  27.     println "\nThe following errors occured during the TeX run:"
  28.     errors.each { error -> println (error - '! ') }
  29.   }
  30. }
  31.  
  32. def pdfInfo() {
  33.   println ''
  34.   def proc = "pdfinfo ${file(jobname + '.pdf').absolutePath}".execute()
  35.   proc.in.eachLine {line -> println line}
  36.   proc.err.eachLine {line -> println 'ERROR: ' + line}
  37.   proc.waitFor()
  38. }
  39.  
  40. def fontInfo() {
  41.   println ''
  42.   def proc = "pdffonts ${file(jobname + '.pdf').absolutePath}".execute()
  43.   proc.in.eachLine {line -> println line}
  44.   proc.err.eachLine {line -> println 'ERROR: ' + line}
  45.   proc.waitFor()
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement