A shell script for ordinary LaTeX compilation

When using biber I usually follow the order of pdflatex → biber → pdflatex → pdflatex, which is not an available option of many IDEs.

#! /bin/bash
# 
# Author: Luglio
# Date: 07/12/2015
# Version: 0.1.1
# 
# Prerequisites
# LaTeX suite with biber, sam2p
# Settings
#   MODE:   latex, pdf, xe 
#   BIB:    no - no biber/biblatex
#           yes - use biber (will run tex for times)
#   PIC:    no - no picture converted to .eps file
#           yes - run sam2p to convert

MODE="pdf"
BIB="no"
PIC="no"

FILENAME=${1%.*}

if [ "$MODE"x = "latex"x ]
then
    mode="LaTeX"
    prog="latex"
elif [ "$MODE"x = "pdf"x ]
then
    mode="pdfLaTeX"
    prog="pdflatex"
elif [ "$MODE"x = "xe"x ]
then
    mode="XeLaTeX"
    prog="xelatex"
else
    mode="UNKNOWN"
    prog="pdflatex"
fi

if [ "$BIB"x = "no"x ]
then
    bib="out"
elif [ "$BIB"x = "yes"x ]
then
    bib=""
else
    bib="out"
fi

if [ "$PIC"x = "no"x ]
then
    pic=" not"
elif [ "$PIC"x = "yes"x ]
then
    pic=""
else
    pic=" not"
fi

echo "This is LaTeX make."
echo "Run in $mode mode, with$bib biber, pictures are$pic to be converted to .eps files."

# sam2p (from apt-get) 
if [ "$pic"x = ""x ]
then
    for format in .jpg .jpeg .bmp .png; do
        for picture in *${format}; do
            sam2p ${picture} ${picture%.*}.eps
        done
    done
fi

# Biber precondition
if [ "$bib"x = ""x ]
then
    eval "${prog} ${FILENAME}.tex"
    biber ${FILENAME}.tex
    eval "${prog} ${FILENAME}.tex"
fi

# Run TeX
eval "${prog} -synctex=-1 ${FILENAME}.tex"

# dvi -> pdf
if [ "$prog"x = "latex"x ]
then
    dvipdfmx ${FILENAME}.dvi
fi

 

posted @ 2015-12-07 14:44  luglio  阅读(248)  评论(0)    收藏  举报