Created
December 13, 2014 12:46
-
-
Save fliiiix/8f849ca419e76cef3c2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| Red='\e[0;31m'; | |
| # reset color | |
| RCol='\e[0m' | |
| cleanUp(){ | |
| # clean up | |
| unset counter | |
| unset PDFNAME | |
| unset BUILDOUT | |
| unset RELEASEOUT | |
| unset BASE | |
| } | |
| setup(){ | |
| export PDFNAME=LePDF.pdf | |
| export BUILDOUT=./build | |
| export RELEASEOUT=./release | |
| export BASE=. | |
| } | |
| fail(){ | |
| echo -e "${Red}$1${RCol}" | |
| cleanUp | |
| exit 1 | |
| } | |
| buildPdf(){ | |
| echo "Build document" | |
| # this run pdflatex until every lable is right or break the script | |
| export counter=0 | |
| while true; do | |
| pdflatex -no-shell-escape -interaction=nonstopmode -output-directory=$BUILDOUT $BASE/main.tex > "$BUILDOUT/pdflatex.log" | |
| grep -q -i "LaTeX Warning: Label(s) may have changed." "$BUILDOUT/pdflatex.log" || break | |
| # this prevent the script from running endless in case of a Label error | |
| # http://tex.stackexchange.com/questions/198517/labels-may-have-changed-run-pdflatex#comment460773_198517 | |
| # > BTW, it's possible that you never get a stable build, because a reference alternates between two sides. | |
| counter=$((counter+1)) | |
| if [[ "$counter" -gt 20 ]]; then | |
| fail "Counter: $counter times reached Exiting loop!" | |
| fi | |
| done | |
| } | |
| movePDF(){ | |
| # copy the file if pdflatex was successfull else show a error message | |
| if grep -q -i "error" "$BUILDOUT/pdflatex.log"; then | |
| fail "FAIL: pdflatex couldn't build the pdf documentation, you can check the log ${BUILDOUT}/pdflatex.log for more informations" | |
| else | |
| cp $BUILDOUT/main.pdf $RELEASEOUT/$PDFNAME | |
| fi | |
| } | |
| setup | |
| buildPdf | |
| movePDF | |
| cleanUp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment