- RECENT_LOG=$(find -maxdepth 1 -name "*.log" -type f | head -1)
- if [[ ${RECENT_LOG} ]]; then
- FILE=${RECENT_LOG/.log/}
- pdflatex ${FILE}
- bibtex ${FILE}
- pdflatex ${FILE}
- pdflatex ${FILE}
- if [[ "$1" == "--xpdf" ]]; then
- xpdf ${FILE}.pdf
+ RECENT_LOG=$(ls -t $(find -maxdepth 1 -name "*.log" -type f) | head -1)
+
+ if [ ${RECENT_LOG} ]; then
+ FILEBASE="${RECENT_LOG/.log/}"
+
+ if [ -f "${FILEBASE}.tex" ]; then
+
+ pdflatex "${FILEBASE}"
+ bibtex "${FILEBASE}"
+ pdflatex "${FILEBASE}"
+ pdflatex "${FILEBASE}"
+
+ if [ "$1" ]; then
+ if [ "$1" == "-v" ] || [ "$1" == "--view" ]; then
+ xpdf "${FILEBASE}.pdf"
+ elif [ "$1" == "-p" ] || [ "$1" == "--print" ]; then
+ lpr "${FILEBASE}.pdf"
+ else
+ echo "Usage: rl [-v|--view] [-p|--print]" >&2
+ echo "Unknown option $1" >&2
+ return 1
+ fi
+ fi
+
+ else
+
+ echo "Can not find a tex file corresponding to the most recent log (${RECENT_LOG/.log/})." >&2
+ return 1
+