Skip to content

Computer Science

The ideas under the software: algorithms, theory, and the comforting news that the fundamentals never really change.

Avoiding eqnarray

Since reading about its faults in The Not So Short Introduction to LaTeX (highly recommended read), I've avidly stayed away from eqnarray. However, I don't think the book conveys the ideas as well as it should. Its suggestion was IEEEeqnarray, as opposed to the classically recommended align. This article from the TeX Users Group conveys them more eloquently and provides better alternatives.

latexerr

The most frustrating thing about compiling LaTeX in a terminal is the wall of text that gets written to stdout. An easy solution would be piping to /dev/nullβ€”except then you wouldn't be able to get error messages (even if you only pipe stdout to /dev/null and keep stderr). So, I made a solution that handles compiling by piping error messages to less. The syntax latexerr FILENAME will compile the file. Passing --clean will delete temporary LaTeX files.

#!/bin/bash

# USAGE: ./script FILE --clean --glossary

extensions_to_delete=(\
	gz fls fdb_latexmk blg bbl log\
    aux out nav toc snm glg glo xdy
)

compile_and_open() {
    argument="$1"
    auxname="${argument%.tex}.aux"
    errors=$(pdflatex -shell-escape \
        -interaction=nonstopmode \
        -file-line-error "$argument" | \
        grep ".*:[0-9]*:.*")

    if [[ -n $errors ]]; then
        echo "$1 Errors Detected"
        echo "$errors" | less
    else
        open_file $1
        echo "$1 Compile Successful"
    fi
}

open_file() {
    filename=`echo "$1" | cut -d'.' -f1`
    open "$filename.pdf"
    echo "$filename Opened"
}

# http://tex.stackexchange.com/questions/6845/compile-latex-with-bibtex-and-glossaries
glossary() {
    compile $1
    makeglossaries $1
    compile $1
    compile $1
}

clean() {
    for file in $(dirname $1)/*; do
        filename=$(basename "$file")
        extension="${filename##*.}"
        filename="${filename%.*}"

        for bad_extensions in "${extensions_to_delete[@]}" ; do
            if [[ $bad_extensions = $extension ]]; then
                rm $file
                echo "$file Deleted"
            fi
        done
    done
}

main() {
    compile_and_open $1

    if [ "$3" = "--glossary" ]; then
       glossary $1
    fi

    if [ "$2" = "--clean" ]; then
        clean $1
    fi

}

main "$@"