Guest User

Custom pdflatex/lilypond script

a guest
May 1st, 2013
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.84 KB | None | 0 0
  1. #!/bin/bash
  2. #     Copyright © 2013 by Kyle Baldwin. All rights reserved.
  3. #
  4. #     This program is free software: you can redistribute it and/or modify
  5. #     it under the terms of the GNU General Public License as published by
  6. #     the Free Software Foundation, either version 3 of the License, or
  7. #     (at your option) any later version.
  8. #
  9. #     This program is distributed in the hope that it will be useful,
  10. #     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. #     GNU General Public License for more details.
  13. #
  14. #     You should have received a copy of the GNU General Public License
  15. #     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ############################################################################
  17. #
  18. #   Current Version:        0.1
  19. #   Release Date:           2013-04-13
  20. #
  21. #
  22. #   What does this engine do?
  23. #       This engine automates the process of building .pdf files when both
  24. #       lilypond-book and latexmk are being used.
  25. #
  26. #   Great, What do I need to know?
  27. #       Currently, this script only works if both lilypond-book and latexmk
  28. #       are in your bash $PATH. The all of the non-essential files are created
  29. #       in the folder '/tmp/lily_dump' (default) so that they don't clutter the main
  30. #       directory and you never have to worry about cleaning them up.  
  31. #
  32. #   Cool, so who can use this?
  33. #       I use OS X, but since I'm making this script without absolute paths to
  34. #       the binaries, it is very possible that this could be ported very easily
  35. #       to any Unix based system.  However, this was written with TeXShop in mind
  36. #       which is only for OSX.     
  37. #
  38. #   Rad, Anything else?
  39. #       Yes.  A lot of the little bits that make this script work I took from
  40. #       Nicola Vitacolonna's Lilypond/LaTeX script for TeXShop.  I would like to
  41. #       Send out a "Thank you!" for your work with this.  Her website where her
  42. #       script, and many other useful programs, can be found at:
  43. #       http://users.dimi.uniud.it/~nicola.vitacolonna/home/
  44. #      
  45. #   Do I need to set any options?
  46. #       Generally, No.  If you do, they are the ones just below marked "Change These."
  47.  
  48. ###############################################
  49. ##                        Change These              #####
  50. ###############################################
  51. ## The directory where the output files are put.
  52. tmpDir="/tmp/lily_dump"
  53. backUpDir="/Volumes/BACKUP"
  54. ##Rsync options
  55.  
  56. cp_opt="-avzP"
  57.  
  58.  
  59. # Get some information for later.
  60. # Get the basename of the file
  61. baseName=${1%.*}
  62. # Get the current directory
  63. curPWD="$(pwd)"
  64.  
  65.  
  66. #Create backup of files first
  67. if [ -d "$backUpDir" ]; then
  68.   eval rsync "$cp_opt --filter 'exclude .*'" ./ "$backUpDir/$baseName"
  69. fi
  70.  
  71. # Create folder in tmp if it doesn't exist
  72. if [ -d "$tmpDir" ]; then
  73.     echo "$tmpDir appears to exist..."
  74. else
  75.     mkdir "$tmpDir"
  76. fi
  77.  
  78.  
  79.  
  80.  
  81. #Now Start processing the document.
  82. # Run Lilypond-Book. Absolute path is needed.
  83.  
  84. eval /Applications/LilyPond.app/Contents/Resources/bin/lilypond-book --pdf -o "$tmpDir $1"
  85.  
  86. # Copy other files and directories into working directory such as .bib
  87. # Exclude the current pdf file in main directory
  88. # Exclude all source files as they should be transfered by lilypond-book
  89. declare -a exFiles=($baseName'.pdf' '*.tex' '*.ly' '*.texly' '.*')
  90.  
  91.  
  92.  
  93. # Create the filter string of files to exclude
  94. for e in "${exFiles[@]}"
  95. do
  96.     if [ -n "$filter" ]; then
  97.         filter="$filter --filter 'exclude $e'"
  98.     else
  99.         filter="--filter 'exclude $e'"
  100.     fi
  101. done
  102. # Run rsync to copy files.
  103.  
  104. eval rsync "$cp_opt" "$filter" ./ "$tmpDir"
  105.  
  106. cd "$tmpDir"
  107.  
  108. # Run the final typesetting commands
  109. pdflatex "$tmpDir/$baseName.tex"
  110. biber "$tmpDir/$baseName"
  111. pdflatex "$tmpDir/$baseName.tex"
  112. pdflatex "$tmpDir/$baseName.tex"
  113.  
  114. #Move the completed pdf Back to the original directory
  115. eval cp -f "$tmpDir"/$baseName.pdf \'$curPWD\'
  116.  
  117. echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment