Skip to main content

bash Script: Print a LaTeX document (with references) to a PDF file with one command.

Printer-friendly version

I wrote this script a while ago to simplify the conversion process when working with LaTeX documents. It's a very simple script (the actual conversion only uses four lines) that uses the pdflatex package and various LaTeX commands. It could also be incorporated into a "for" loop for batch operation, if the last line, which opens a PDF viewer and calls the pdf document, is commented out.

#!/bin/bash
##########################################################################
# Print a LaTeX document to a PDF file                                                                                                        
##########################################################################
# FILE: latex2pdf.sh
# AUTHOR: Brian Napoletano
# DATE: 2007-06-22
# VERSION: 0.0.1
# DESCRIPTION: A simple script to automate the steps necessary to print a tex
# file as a pdf. This script is designed to handle tex documents and can
# accommodate citation extraction from a bibtex database.
# USAGE: latex2pdf.sh 
# NOTE: Do not include the .tex extension in the command; the script already 
# knows to look for it.
# DEPENDS: pdflatex, evince*
# *Automatically calling Evince is more of a convenience, and the command may
# be modified to, say, xpdf or removed altogether for batch operation.
#
# Step 1: Initial compile
pdflatex -interaction=nonstopmode $1.tex;
#
# Step 2: Read the bibtex database
bibtex $1.aux;
#
# Step 3: Build the needed indices
makeindex $1.tex;
#
# Step 4: Re-compile the tex file
pdflatex -interaction=nonstopmode $1.tex
#
# Step 5: Open the finished product for viewing in evince
evince $1.pdf