Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright © 2013 by Kyle Baldwin. All rights reserved.
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- ############################################################################
- #
- # Current Version: 0.1
- # Release Date: 2013-04-13
- #
- #
- # What does this engine do?
- # This engine automates the process of building .pdf files when both
- # lilypond-book and latexmk are being used.
- #
- # Great, What do I need to know?
- # Currently, this script only works if both lilypond-book and latexmk
- # are in your bash $PATH. The all of the non-essential files are created
- # in the folder '/tmp/lily_dump' (default) so that they don't clutter the main
- # directory and you never have to worry about cleaning them up.
- #
- # Cool, so who can use this?
- # I use OS X, but since I'm making this script without absolute paths to
- # the binaries, it is very possible that this could be ported very easily
- # to any Unix based system. However, this was written with TeXShop in mind
- # which is only for OSX.
- #
- # Rad, Anything else?
- # Yes. A lot of the little bits that make this script work I took from
- # Nicola Vitacolonna's Lilypond/LaTeX script for TeXShop. I would like to
- # Send out a "Thank you!" for your work with this. Her website where her
- # script, and many other useful programs, can be found at:
- # http://users.dimi.uniud.it/~nicola.vitacolonna/home/
- #
- # Do I need to set any options?
- # Generally, No. If you do, they are the ones just below marked "Change These."
- ###############################################
- ## Change These #####
- ###############################################
- ## The directory where the output files are put.
- tmpDir="/tmp/lily_dump"
- backUpDir="/Volumes/BACKUP"
- ##Rsync options
- cp_opt="-avzP"
- # Get some information for later.
- # Get the basename of the file
- baseName=${1%.*}
- # Get the current directory
- curPWD="$(pwd)"
- #Create backup of files first
- if [ -d "$backUpDir" ]; then
- eval rsync "$cp_opt --filter 'exclude .*'" ./ "$backUpDir/$baseName"
- fi
- # Create folder in tmp if it doesn't exist
- if [ -d "$tmpDir" ]; then
- echo "$tmpDir appears to exist..."
- else
- mkdir "$tmpDir"
- fi
- #Now Start processing the document.
- # Run Lilypond-Book. Absolute path is needed.
- eval /Applications/LilyPond.app/Contents/Resources/bin/lilypond-book --pdf -o "$tmpDir $1"
- # Copy other files and directories into working directory such as .bib
- # Exclude the current pdf file in main directory
- # Exclude all source files as they should be transfered by lilypond-book
- declare -a exFiles=($baseName'.pdf' '*.tex' '*.ly' '*.texly' '.*')
- # Create the filter string of files to exclude
- for e in "${exFiles[@]}"
- do
- if [ -n "$filter" ]; then
- filter="$filter --filter 'exclude $e'"
- else
- filter="--filter 'exclude $e'"
- fi
- done
- # Run rsync to copy files.
- eval rsync "$cp_opt" "$filter" ./ "$tmpDir"
- cd "$tmpDir"
- # Run the final typesetting commands
- pdflatex "$tmpDir/$baseName.tex"
- biber "$tmpDir/$baseName"
- pdflatex "$tmpDir/$baseName.tex"
- pdflatex "$tmpDir/$baseName.tex"
- #Move the completed pdf Back to the original directory
- eval cp -f "$tmpDir"/$baseName.pdf \'$curPWD\'
- echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment