Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/ gradle-latex Public archive

A Gradle plugin for compiling LaTeX, inspired by https://github.com/csabasulyok/gradle-latex. Works with gradle kts scripts.

License

Notifications You must be signed in to change notification settings

DanySK/gradle-latex

Repository files navigation

gradle-latex

A Gradle plugin for building LaTeX projects

Rationale

I wanted something to smootly build latex in CI without having to fiddle with bash

Usage

Importing the plugin

plugins {
    id ("org.danilopianini.gradle-latex") version "0.1.0" // Exemplificatory, pick the last stable one!
}

Configuring the plugin

Minimal configuration

latex {
    "myMainLatexFile"()
}

This configuration guesses your main tex file to be myMainLatexFile.tex, autodetects if a myMainLatexFile.bib is present, and builds the resulting myMainLatexFile.pdf.

Building multiple main files

latex {
    "oneFile"()
    "anotherFile"()
}

You can have one entry in the latex section of your build.gradle.kts per project you want to build. In case your files are spread across multiple directories, consider each sub-directory a subproject and configure Gradle accordingly.

See for instance the example with Elsevier's CAS LaTeX template, in particular look at settings.gradle.kts and build.gradle.kts both in the root and in the doc folder

Configuration options

Global options can be specified directly in the latex block. Per-project options can be specified in a block after the main file name. The following examples shows the available options and their default values.

latex {
    terminalEmulator.set("bash") // Your terminal
    waitTime.set(1) // How long before considering a process stalled
    waitUnit.set(TimeUnit.MINUTES) // Time unit for the number above
    pdfLatexCommand.set("pdflatex")
    bibTexCommand.set("bibtex")
    "myMainLatexFile" {
        // Options for pdflatex
        extraArguments = listOf("-shell-escape", "-synctex=1", "-interaction=nonstopmode", "-halt-on-error")
        /*
         * Additional files and directories whose change should trigger a build in case gradle is used with -t flag.
         * Can be passed files, strings, or any Object compatible with Gradle's project.files
         */
        watching = emptyList()
    }
    "anotherMainLatexFile"()
}

Contributing to the project

I gladly review pull requests and I'm happy to improve the work. If the software was useful to you, please consider supporting my development activity paypal