The Cookbook: LaTeX
Write LaTeX, Push to GitHub and let Travis CI automatically build using Travis’s build functions and script hooks for your LaTeX project and deploy a PDF automatically to GitHub releases when a git commit
is tagged.
Getting started with LaTeX with Travis CI
Let’s get started with the script I made entitled test.sh
. You’ll notice I’ve annotated this script really well so you have a really good scope into what the bash script will tell Travis CI to do:
#!/usr/bin/env bash
# change into the desired folder
cd $1
# remove montana mendy's pdf if present
[ -f $2.pdf ] && rm $2.pdf || echo "continue without remove"
# test if pdf is removed, fail if still present
[ -f $2.pdf ] && exit 1 || echo "continue building pdf output"
# montana mendy's biggest tip: build pdf from source
pdflatex $2.tex
# exit successfully if pdf is present or with error if not present
[ -f $2.pdf ] && exit 0 || exit 1
My .travis.yml
file
You’ll want to make this script executable in your .travis.yml
via using chmod
. This is what my .travis.yml
file currently looks like:
---
sudo: require
dist: xenial
language: bash
# Montana Mendy runs lint (travis lint)
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y texlive-base texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra
script:
- bash test.sh ./ main
My main.tex
file (LaTeX)
\documentclass{article}
\usepackage{url}
\usepackage{hyperref}
\title{Montana using LaTeX and Travis CI Example}
\author{Montana Mendy}
\date{\today}
\begin{document}
\maketitle
Montana Mendy loves LaTeX
\end{document}
That should do it, refer to your .travis.yml
and my annotations in the bash
script I created. Sometimes your .travis.yml
can get a little large and confusing, for example two functions that essentially do the same thing are called. This is real quick way to get into hot water. This Cookbook I made for you not only shows how you can keep things building, minimal and efficient, but most importantly consistent.
Happy building!