
org.danilopianini.gradle.latex.PdfLatexTask.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-latex Show documentation
Show all versions of gradle-latex Show documentation
A plugin for compiling LaTeX, inspired by https://github.com/csabasulyok/gradle-latex
package org.danilopianini.gradle.latex
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.Console
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.OutputFiles
import org.gradle.api.tasks.TaskAction
import javax.inject.Inject
/**
* Gradle task to run pdflatex on a TeX file.
* One such task is created for each Latex artifact.
*
* @author csabasulyok
*/
open class PdfLatexTask @Inject constructor(artifact: LatexArtifact) : LatexTask(artifact) {
@Console
override fun getDescription() = "Uses pdflatex to compile ${artifact.tex} into ${artifact.pdf}"
/**
* Collection of all files whose change should trigger this task.
* Collected for Gradle's continuous build feature.
* Contains the following (based on the Latex artifact):
* - main TeX file
* - bib files, if there is one
* - outputs (PDF) of dependent TeX files
* - auxiliary files/folders
*/
open val inputFiles: FileCollection
@InputFiles get() = project.files(artifact.watching + artifact.tex)
.also { project.logger.debug("task {} is watching for changes {}", name, it) }
/**
* Output of current task. Not used by task itself.
* Set for Gradle's continuous build feature.
*/
@OutputFiles
open val outputFiles = project.files(artifact.pdf, artifact.aux)
/**
* Main task action.
* Empties auxiliary directory.
*/
@TaskAction
fun pdfLatex() {
project.logger.info("Executing ${extension.pdfLatexCommand.get()} for {}", artifact.tex)
val command = StringBuilder(extension.pdfLatexCommand.get())
.append(artifact.extraArgs.joinToString(separator = " ", prefix = " "))
.append(" \"")
.append(artifact.tex.absolutePath)
.append('\"')
.toString()
project.logger.debug("Prepared command {}", command)
command.runScript()
command.runScript()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy