Last active
February 26, 2019 14:39
-
-
Save LindsayBradford/11274456 to your computer and use it in GitHub Desktop.
Gradle script for LaTeX pdf generation.
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
/* | |
* 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
Thank you, very helpful. As a comment, you can avoid the
2.times
by running:commandLine 'latexmk', '-pdf', project.documentBase
(it will automatically run the typesetting the required amount of times for generation of tables, references etc).