Posted by luc on Sat 23rd Oct 17:41 (modification of post by luc view diff)
diff | download | new post
- #!/bin/bash
- #
- #A script to compile .tex files to .pdf (and optionally, .rtf or .html)
- #with bibliography support.
- #
- #Depends on: latex, bibtex, dvips, ps2pdf,
- #Suggests: latex2rtf, latex2html, evince (or any other pdf viewer)
- #
- #Written by: J.Barney
- #Last updated: 22.10.10
- #Save working directory to come back to
- OLDDIR="`pwd`"
- #Check directory
- echo ""
- read -p "Is you latex project in the current directory? y|[n]" switchdir
- echo ""
- #Select directory besides the working one
- if [[ $switchdir =~ n|N|(no)|(No) ]] || [[ -z $switchdir ]]; then
- texdirectory=$(zenity --file-selection --directory --title="Select DIRECTORY of the .tex file");
- cd "$texdirectory"
- fi
- #Optional backup
- read -p "Would you like to create a backup before compiling? [y]|n" backup
- if [[ $backup =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $backup ]]; then
- CURDIR="`pwd`"
- if [[ ! -e $CURDIR/backups ]]; then
- echo "Backups directory not detected, making one..."
- mkdir "$CURDIR/backups"
- fi
- BACKUPDATE=`date +%m_%d_at_%H_%M`
- cd "$CURDIR/backups"
- nice tar cvpzf backup_$BACKUPDATE.tar --exclude="$CURDIR/backups" "$CURDIR/*"
- cd "$CURDIR"
- else
- echo "Warning: We are NOT making a backup!"
- echo ""
- fi
- #Select .tex file
- #Check to see if there is only one file -- use it if so."
- if [[ `ls *.tex | wc -l` -gt 1 ]]; then
- TEXLIST="`ls *.tex | sed 's/.tex$//'`"
- echo "Select .tex file"
- # TODO: warning this does not work with spaces in filenames!
- select texfile in $TEXLIST
- do
- break
- done
- else
- texfile="`ls *.tex`"
- texfile="{texfile%.tex}"
- echo "Using 1 found .tex file: $texfile"
- fi
- echo ""
- #Check for .bib
- if [[ -e *.bib ]] ; then
- read -p ".bib file found. Include it? [y]|n" biblio
- echo ""
- if [[ $biblio =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $biblio ]]; then
- #reset biblio for easy reuse (see further down)
- biblio="yes"
- #Select if more than 1 .bib file
- if [[ `ls *.bib | wc -l` -gt 1 ]]; then
- BIBLIST="`ls *.bib | sed 's/.bib$//'`"
- echo "Multiple .bibs found, select one"
- # TODO: warning this does not work with spaces in filenames!
- select biblioname in $BIBLIST
- do
- break
- done
- echo ""
- else
- biblioname="`ls *.bib`"
- biblioname="{biblioname%.bib}"
- echo "Using 1 found .bib file: $biblioname"
- sleep 2s
- fi
- else
- #reset biblio for easy reuse (see further down)
- biblio="no"
- fi
- fi
- latex "${texfile}.tex"
- #biblio was reset to be either "yes" or "no"
- if [[ $biblio = yes ]] ; then
- bibtex "${biblioname}.bib"
- fi
- latex "${texfile}.tex"
- latex "${texfile}.tex"
- dvips "${texfile}.div"
- ps2pdf "${texfile}.ps" "${texfile}.pdf"
- echo ""
- echo "Compilation complete."
- echo ""
- read -p "Create .rtf version now? [y]|n" rtfnow
- if [[ $rtfnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $rtfnow ]]; then
- latex2rtf "${texfile}.tex"
- fi
- echo ""
- read -p "Create .html version now? [y]|n" htmlnow
- if [[ $htmlnow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $htmlnow ]]; then
- latex2html "${texfile}.tex"
- fi
- echo ""
- read -p "Open .pdf now? (Y/n): " opennow
- if [[ $opennow =~ y|Y|(yes)|(Yes)|(YES) ]] || [[ -z $opennow ]]; then
- evince "${texfile}.pdf" &
- fi
- cd "$OLDDIR"
- exit 0
- #end
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.