Skip to content

Instantly share code, notes, and snippets.

@ExFed
Forked from LindsayBradford/build.gradle
Created February 26, 2019 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ExFed/274245aba3849c92095e1db0fb1c2d5e to your computer and use it in GitHub Desktop.
Save ExFed/274245aba3849c92095e1db0fb1c2d5e to your computer and use it in GitHub Desktop.
Gradle script for LaTeX pdf generation.
/*
* Usage:
* all LaTeX source files go in $rawDirectory
* base document to 'cook' should match content of $latexFile
* build script delivers resulting PDF file to $cookedDirectory
*/
defaultTasks 'full'
ext { documentBase = 'myBaseLaTeXFileName' }
project.ext {
latexFile = documentBase + '.tex'
pdfFile = documentBase + '.pdf'
rawDirectory = 'raw'
cookedDirectory = 'cooked'
}
task cook(type: Exec) {
doFirst {
println "Cooking $project.latexFile in /$project.rawDirectory."
}
outputs.upToDateWhen{false}
workingDir project.rawDirectory
standardOutput = new ByteArrayOutputStream() // stops output to STDOUT
2.times {
commandLine 'pdflatex', project.documentBase
}
outputs.file file("$project.rawDirectory/$project.pdfFile")
doLast {
println "Cooked $project.latexFile to $project.pdfFile."
}
}
task deliver(type: Copy) {
outputs.upToDateWhen{false}
from cook
into project.cookedDirectory
doLast {
println "Delivered $project.pdfFile to /$project.cookedDirectory."
}
}
task flush(type: Delete) {
dependsOn deliver
outputs.upToDateWhen{false}
delete {
fileTree(dir: project.rawDirectory, excludes: ['**/*.tex', '**/*.cls'])
}
doLast {
println "Flushed /$project.rawDirectory of temporary $documentBase files."
}
}
task full {
dependsOn flush
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment