| 1 | #! /bin/bash -e |
| 2 | |
| 3 | # faust2mathviewer.sh |
| 4 | # |
| 5 | # Generate a full Faust documentation, in a '*-mdoc' top directory |
| 6 | # and open the resulting pdf file |
| 7 | # |
| 8 | # Karim Barkati |
| 9 | # November 2009 |
| 10 | # |
| 11 | # Warning : this script requires several things to be installed : |
| 12 | # - svg2pdf, from the Cairo 2D graphics library; |
| 13 | # - pdflatex, to compile the tex file; |
| 14 | # - breqn, a latex package to break equations; |
| 15 | # - faust ;-) |
| 16 | |
| 17 | # Usage. |
| 18 | echoHelp() |
| 19 | { |
| 20 | echo Usage : args of faust2mathviewer should be a \'.dsp\' file, or a list of \'.dsp\' files. |
| 21 | exit |
| 22 | } |
| 23 | |
| 24 | # Visit each directory transmitted as argument, |
| 25 | # in order to convert .svg files into pdf. |
| 26 | # This function uses the svg2pdf command, |
| 27 | # from the Cairo 2D graphics library. |
| 28 | convert_svgdirs2pdf() |
| 29 | { |
| 30 | for DIR in $@ ; do |
| 31 | if [ -d $DIR ] ; then |
| 32 | echo "cd " $DIR |
| 33 | cd $DIR |
| 34 | FILES=`ls | grep -E "\.svg"` |
| 35 | for SRC in $FILES ; do |
| 36 | echo ' --> '$SRC |
| 37 | PDF=${SRC%.svg}'.pdf' |
| 38 | svg2pdf "$SRC" "$PDF" |
| 39 | echo ' <-- '$PDF |
| 40 | done |
| 41 | cd - |
| 42 | else |
| 43 | echo error : \'$DIR\' is not a directory. |
| 44 | fi |
| 45 | done |
| 46 | } |
| 47 | |
| 48 | # Main loop of this script : |
| 49 | # 1. Compile `faust -mdoc` to generate the TeX file and SVG block-diagrams. |
| 50 | # 2. Move to the "${FILEPATH%.dsp}-mdoc" directory created by faust. |
| 51 | # 3. Convert SVG files into PDF files recursively (with svg2pdf). |
| 52 | # 4. Compile pdflatex twice (including the top-level block-diagram). |
| 53 | # 5. Copy some important files where needed. |
| 54 | |
| 55 | if [[ $(uname) == Darwin ]]; then |
| 56 | OPEN=open |
| 57 | export PATH="/usr/texbin:$PATH" |
| 58 | else |
| 59 | OPEN=xdg-open |
| 60 | fi |
| 61 | |
| 62 | for FILEPATH in $@ ; do |
| 63 | if [ -f $FILEPATH ] ; then |
| 64 | FILENAME=`basename $FILEPATH` && |
| 65 | case $FILENAME in |
| 66 | *.dsp ) |
| 67 | faust -o ${FILEPATH%.dsp}.cpp --mathdoc $FILEPATH || exit |
| 68 | cd ${FILEPATH%.dsp}-mdoc/ && |
| 69 | cd svg && convert_svgdirs2pdf svg-* && cd .. && |
| 70 | cd tex && pdflatex ${FILENAME%.dsp}.tex && pdflatex ${FILENAME%.dsp}.tex && cd .. && |
| 71 | mkdir -p pdf && cp tex/${FILENAME%.dsp}.pdf pdf && |
| 72 | mkdir -p cpp && mv ../${FILENAME%.dsp}.cpp cpp && |
| 73 | ${OPEN} tex/${FILENAME%.dsp}.pdf && |
| 74 | cd .. |
| 75 | ;; |
| 76 | * ) |
| 77 | echo error : \'$FILENAME\' does not have a \'.dsp\' extension. |
| 78 | exit 2 |
| 79 | ;; |
| 80 | esac |
| 81 | else |
| 82 | echoHelp |
| 83 | fi |
| 84 | done |
| 85 | exit 0 |
| 86 |