Advertisement
paxperscientiam

TeXShop Engine with pdftex (LaTeX->BibTeX->LaTeX->LaTeX)

Apr 27th, 2015
948
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.29 KB | None | 0 0
  1. #!/opt/local/bin/bash
  2. # USE AT YOUR OWN DISCRETION
  3. # Last edited: 2015/05/09
  4. ## Added support for multiple image types
  5. ## Streamlined code to ensure minimal file shuffling.
  6. ## Corrected problem of TeXShop not auto-opening final .pdf product.
  7. # runTBTT.engine is an .engine file for TeXShop and should be stored in ~/Library/TeXShop/Engine -- be sure to restart TeXShop
  8. # 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
  9. # This script will LaTeX-->BibTeX-->LaTeX-->LaTeX
  10. # Credit:
  11. ## Jesper Kristensen for created the bulk of this code:
  12. ### http://jespertoftkristensen.com/JTK/Blog/Entries/2014/1/13_Organize_your_LaTeX_Project.html
  13. ## Karthick Sundararajan for the awesome pictorial directory tree formula
  14. ### http://karthicks.blogspot.com/2013/09/bash-sed-display-unix-directory.html
  15.  
  16. # Required directory structure (template)
  17. ## Project
  18. ##  +--Figures
  19. ##  |    +--figure1.eps
  20. ##  |    +--figure2.eps
  21. ##  |    +--figureN.eps
  22. ##  +--LaTeX
  23. ##  |    +--main.tex
  24. ##  |    +--include1.tex
  25. ##  |    +--include2.tex
  26. ##  |    +--includeN.tex
  27. ##  +--Misc
  28.  
  29. shopt -s nocasematch;
  30.  
  31. dirparent="$(basename "$(pwd)")"
  32. filename="${@: -1}"
  33. curdir="$(dirname "$(pwd)")"
  34.  
  35.  
  36. # Check if the texfile, which is passed into this script, has a PWD of /LaTeX/
  37. if [[ "$dirparent" == LaTeX ]]; then
  38.     echo 'Parent directory is /LaTeX/ and that is correct!'
  39. else
  40.     echo "Parent directory of $filename must be /LaTeX/$filename"
  41. echo "${@: -1}"
  42.     exit 1
  43. fi
  44.  
  45. # Check if the directory ../Misc/ exists
  46. misctest=""$(dirname "$(pwd)")"/Misc"
  47.  if [ -d "$misctest" ]
  48.  then
  49.      echo "../Misc/ exists!"
  50.  else
  51.      echo "../Misc/ does not exist! Making..."
  52.      mkdir "$misctest"
  53.  fi
  54.  
  55.  
  56. texfile="${@: -1}" #Get last parameter passed from shell
  57. texfile="${texfile%.*}" #This strips the extension
  58.  
  59. function dolatex {
  60.     echo `pwd`
  61.     cp ../Misc/* .
  62.     cp ../Figures/*{.eps,.jpg,.jpeg,.pdf,.png} . # should try to copy any images with listed extensions
  63.     pdflatex --file-line-error --synctex=1 $texfile
  64. }
  65.  
  66. function dobibtex {
  67.     bibtex $texfile
  68. }
  69.  
  70. function cleanup {
  71.     mv $texfile.pdf $texfile.pdf.keep
  72.     mv *{.eps,.jpg,.jpeg,.pdf,.png} ../Figures
  73.     mv $texfile.pdf.keep $texfile.pdf
  74.     ls -1 | grep -Ev ".*.(tex|pdf)$" | xargs -I {} mv {} ../Misc
  75.     mv ${texfile%.*}.pdf ../
  76.     rm -f *-eps-converted-to.pdf
  77.     }
  78.  
  79. function tree {
  80.     find .. -name '*' | sed -e 's/^/|-/' -e 's/[^-][^\/]*\//|   /g' -e 's/|   \([A-Za-z0-9_.]\)/|   +--\1/'
  81.     }
  82.  
  83.  
  84. # This block of code is where the magic happens!
  85. dolatex
  86. echo "LaTeX...complete."
  87. dobibtex
  88. echo "BibTeX...complete."
  89. dolatex
  90. echo "LaTeX...complete."
  91. dolatex
  92. echo "LaTeX...complete."
  93. cleanup
  94. echo "Cleaning up...complete"
  95. echo "Looks like everything went off without a hitch. Please find your hot steaming .pdf in..."
  96.  
  97. # This will spit out a pictorial version of the project directory tree
  98. 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
  99.  
  100. # This is a fix to get texshop to open the new pdf file.
  101. set +B
  102. echo "Opening "$curdir/$texfile.pdf""
  103. open -a TeXShop -F "$curdir/$texfile.pdf"
  104. set -B
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement