121 reputation
2
bio website
location Germany
age
visits member for 4 years, 2 months
seen Sep 27 '10 at 23:44
#!/bin/bash
# PROVIDED AS IS. USE AT YOUR OWN RISK.
# CONSIDER THIS SCRIPT TO BE BETA QUALITY.
# NOT GUARANTEED TO WORK WITH YOUR CONFIG.
# MAY CAUSE DATA LOSS.
# PLEASE BACKUP YOUR SYSTEM BEFORE USE.
# For MacOSX/Linux teTeX distribution. FREEWARE.
# Permission granted to use, modify & redistribute
# as long as all copyright & usage notices are kept.
# Inspired by MiKTeX texify.
# http://tex.stackexchange.com/users/1314/archimedix
echo "texify 0.12 Copyright (C) 2008 Archimedix/HHN"
TEX="pdflatex"
EXT="pdf"
"$TEX" --help | grep "^[ \t]*-jobname" >/dev/null
if [ $? -ne 0 ]; then echo "$TEX does not support -jobname switch.";exit 2;fi
if [ $# -lt 1 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
    echo "Usage: "`basename "$0"`" <texfile> [<latex param> ...]";exit 3
elif [ ! -f "$1" ]; then
    echo "Not found: $1";exit 4
fi
FPATH="$1"
FNAME="$(basename "$FPATH")"
FDIR="$(dirname "$FPATH")"
shift
pushd . >/dev/null
cd "$FDIR"
case "$FNAME" in
    *.tex ) BASEFNAME="$(echo "$FNAME" | sed -e "s/\(.*\)\.tex\$/\1/g")" ;;
    * ) BASEFNAME="$FNAME"
esac
DATESTAMP="$(date +"%Y%m%d%H%M%S")"
PID="$$"
JNAMEB="texify-tmp-$DATESTAMP-$PID-"
JNAME="$JNAMEB$(basename "$FNAME")"
AUXFILE="$JNAME.aux"
LOG="$JNAME.log"
OFNAME="$BASEFNAME.$EXT"
OLOG="$BASEFNAME.log"
RERUN="1"
EXCODE=5
while [ ! "$RERUN" = "" ]; do
    "$TEX" $@ -jobname "$JNAME" "$FPATH"
    EXCODE="$?"
    if [ ! -f "$LOG" ]; then break; fi
    WARNS=`grep "^LaTeX Warning:" "$LOG"`
    RERUN=`echo "$WARNS" | grep "^LaTeX Warning: Label(s) may have changed\. Rerun to get cross-references"`
    UNDEF_REF=`echo "$WARNS" | grep "^LaTeX Warning: There were undefined references"`
    INDEX_FILE="$(grep "^Writing index file " "$LOG" | sed -e "s/^Writing index file \(.*\)/\"\1\"/g")"
    if [ "$INDEX_FILE" != "" ]; then
        if [ -f "$BASEFNAME.ist" ]; then eval "makeindex -s '$BASEFNAME.ist' '$INDEX_FILE'"
        else eval "makeindex '$INDEX_FILE'";fi
    fi
    if [ ! "$UNDEF_REF" = "" ]; then bibtex "$AUXFILE"; fi
done
AUXF="$(grep "^\\\\@input{.*\.aux}" "$AUXFILE" | sed -e "s/^\\\\@input{\(.*\)}/\"\1\"/g")"
if [ -f "$JNAME.$EXT" ]; then
    echo "Output file moved to $OFNAME."
    mv "$JNAME.$EXT" "$OFNAME"
fi
if [ -f "$LOG" ]; then mv "$LOG" "$OLOG";if [ $? -eq 0 ]; then echo "Transcript moved to $OLOG."; fi; fi
if [ "$JNAMEB" != "" ]; then find "$FDIR" -maxdepth 1 -type f -name "$JNAMEB*" -exec rm {} \; ; fi
if [ "$AUXF" != "" ]; then
    old_IFS="$IFS";IFS=$'\n'
    for temp_aux_file in $AUXF ; do eval "rm '$temp_aux_file'"; done
    IFS="$old_IFS"
fi
popd >/dev/null
exit "$EXCODE"

This user has not asked any questions
Stack Overflow 4,269 rep 1738
Electrical Engineering 231 rep 8
Server Fault 203 rep 27
Programmers 153 rep 15
Physics 142 rep 3

0 Votes Cast

This user has not cast any votes