Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/opt/local/bin/bash
- # USE AT YOUR OWN DISCRETION
- # Last edited: 2015/05/09
- ## Added support for multiple image types
- ## Streamlined code to ensure minimal file shuffling.
- ## Corrected problem of TeXShop not auto-opening final .pdf product.
- # runTBTT.engine is an .engine file for TeXShop and should be stored in ~/Library/TeXShop/Engine -- be sure to restart TeXShop
- # You could store your .bib and .bst files in the /Misc directory or use TeXLive's ~/Library/texmf/bibtex/bib and ~/Library/texmf/bibtex/bib/bst, respectively, for global access
- # This script will LaTeX-->BibTeX-->LaTeX-->LaTeX
- # Credit:
- ## Jesper Kristensen for created the bulk of this code:
- ### http://jespertoftkristensen.com/JTK/Blog/Entries/2014/1/13_Organize_your_LaTeX_Project.html
- ## Karthick Sundararajan for the awesome pictorial directory tree formula
- ### http://karthicks.blogspot.com/2013/09/bash-sed-display-unix-directory.html
- # Required directory structure (template)
- ## Project
- ## +--Figures
- ## | +--figure1.eps
- ## | +--figure2.eps
- ## | +--figureN.eps
- ## +--LaTeX
- ## | +--main.tex
- ## | +--include1.tex
- ## | +--include2.tex
- ## | +--includeN.tex
- ## +--Misc
- shopt -s nocasematch;
- dirparent="$(basename "$(pwd)")"
- filename="${@: -1}"
- curdir="$(dirname "$(pwd)")"
- # Check if the texfile, which is passed into this script, has a PWD of /LaTeX/
- if [[ "$dirparent" == LaTeX ]]; then
- echo 'Parent directory is /LaTeX/ and that is correct!'
- else
- echo "Parent directory of $filename must be /LaTeX/$filename"
- echo "${@: -1}"
- exit 1
- fi
- # Check if the directory ../Misc/ exists
- misctest=""$(dirname "$(pwd)")"/Misc"
- if [ -d "$misctest" ]
- then
- echo "../Misc/ exists!"
- else
- echo "../Misc/ does not exist! Making..."
- mkdir "$misctest"
- fi
- texfile="${@: -1}" #Get last parameter passed from shell
- texfile="${texfile%.*}" #This strips the extension
- function dolatex {
- echo `pwd`
- cp ../Misc/* .
- cp ../Figures/*{.eps,.jpg,.jpeg,.pdf,.png} . # should try to copy any images with listed extensions
- pdflatex --file-line-error --synctex=1 $texfile
- }
- function dobibtex {
- bibtex $texfile
- }
- function cleanup {
- mv $texfile.pdf $texfile.pdf.keep
- mv *{.eps,.jpg,.jpeg,.pdf,.png} ../Figures
- mv $texfile.pdf.keep $texfile.pdf
- ls -1 | grep -Ev ".*.(tex|pdf)$" | xargs -I {} mv {} ../Misc
- mv ${texfile%.*}.pdf ../
- rm -f *-eps-converted-to.pdf
- }
- function tree {
- find .. -name '*' | sed -e 's/^/|-/' -e 's/[^-][^\/]*\//| /g' -e 's/| \([A-Za-z0-9_.]\)/| +--\1/'
- }
- # This block of code is where the magic happens!
- dolatex
- echo "LaTeX...complete."
- dobibtex
- echo "BibTeX...complete."
- dolatex
- echo "LaTeX...complete."
- dolatex
- echo "LaTeX...complete."
- cleanup
- echo "Cleaning up...complete"
- echo "Looks like everything went off without a hitch. Please find your hot steaming .pdf in..."
- # This will spit out a pictorial version of the project directory tree
- if [ $( tree | wc -l ) -gt 47 ]; then tree | head -n 47; echo "Directory tree has been truncated to 47 lines." ; else tree; echo "Full directory tree on display." ; fi
- # This is a fix to get texshop to open the new pdf file.
- set +B
- echo "Opening "$curdir/$texfile.pdf""
- open -a TeXShop -F "$curdir/$texfile.pdf"
- set -B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement