Add the output wave files into track list
[Faustine.git] / interpretor / faust-0.9.47mr3 / tools / faust2appls / faust2mathdoc
1 #!/bin/bash
2
3 # faust2mathdoc.sh
4 #
5 # Generate a full Faust documentation, in a '*-mdoc' top directory.
6 #
7 # Karim Barkati
8 # November 2009
9 #
10 # Warning : this script requires several things to be installed :
11 # - svg2pdf, from the Cairo 2D graphics library;
12 # - pdflatex, to compile the tex file;
13 # - breqn, a latex package to break equations;
14 # - faust ;-)
15
16
17 # Usage.
18 print_usage()
19 {
20 echo "usage: faust2mathdoc [-l LANG] [-utf8] faust_file.dsp ..."
21 echo " LANG is usually a 2-lowercase-letters language name, like en, fr, or it."
22 echo " -utf8 force faust_file.dsp to be recoded in UTF-8 before being processed"
23 }
24
25
26 # Visit each directory transmited as argument,
27 # in order to convert process.svg files into pdf.
28 # This function uses the svg2pdf command,
29 # from the Cairo 2D graphics library.
30 convert_svgprocesses2pdf()
31 {
32 for DIR in $@ ; do
33 if [ -d $DIR ] ; then
34 echo "cd " $DIR
35 cd $DIR
36 FILE="process.svg"
37 for SRC in $FILE ; do
38 echo ' --> '$SRC
39 PDF=${SRC%.svg}'.pdf'
40 svg2pdf "$SRC" "$PDF"
41 echo ' <-- '$PDF
42 done
43 cd -
44 else
45 echo error : \'$DIR\' is not a directory.
46 fi
47 done
48 }
49
50
51 # Visit each directory transmited as argument,
52 # in order to convert .svg files into pdf.
53 # This function uses the svg2pdf command,
54 # from the Cairo 2D graphics library.
55 convert_svgdirs2pdf()
56 {
57 for DIR in $@ ; do
58 if [ -d $DIR ] ; then
59 #echo "cd " $DIR
60 cd $DIR
61 FILES=`ls | grep -E "\.svg"`
62 for SRC in $FILES ; do
63 #echo ' --> '$SRC
64 PDF=${SRC%.svg}'.pdf'
65 svg2pdf "$SRC" "$PDF"
66 echo "svg2pdf $SRC $PDF"
67 #echo ' <-- '$PDF
68 done
69 cd ..
70 else
71 echo error : \'$DIR\' is not a directory.
72 fi
73 done
74 }
75
76
77 # In-place recoding of a text file from its current encoding to UTF-8.
78 # This is useful for .dsp files with accents in comments that are coded
79 # with a different character set.
80 recode2utf8()
81 {
82 charset=`file -0 --mime-encoding $1 | cut -d' ' -f2`
83 recode $charset..utf-8 $1
84 }
85
86
87 MDLANGOPT=""
88 if [ $1 = "-mdlang" ] || [ $1 = "--mathdoc-lang" ] || [ $1 = "-l" ]
89 then
90 MDLANGOPT="-mdlang $2"
91 shift 2
92 fi
93
94 CONVERT=""
95 if [ $1 = "-utf8" ] || [ $1 = "--utf8" ]
96 then
97 CONVERT="utf8"
98 shift 1
99 fi
100
101 if [ $# -eq 0 ]
102 then
103 print_usage
104 exit 1
105 fi
106
107 # Main loop of this script :
108 # 1. Compile `faust --mathdoc` to generate the TeX file and SVG block-diagrams.
109 # 2. Move to the "${FILEPATH%.dsp}-mdoc" directory created by faust.
110 # 3. Convert SVG files into PDF files recursively (with svg2pdf).
111 # 4. Compile pdflatex twice (including the top-level block-diagram).
112 # 5. Copy some important files where needed.
113 for FILEPATH in $@ ; do
114 if [ -f $FILEPATH ] ; then
115 FILENAME=`basename $FILEPATH` &&
116 case $FILENAME in
117 *.dsp )
118 if [ $CONVERT = "utf8" ]
119 then
120 recode2utf8 $FILENAME
121 fi
122 faust $MDLANGOPT -o ${FILEPATH%.dsp}.cpp --mathdoc $FILEPATH &&
123 cd ${FILEPATH%.dsp}-mdoc/ &&
124 cd svg && convert_svgdirs2pdf svg-* && cd .. &&
125 cd tex && pdflatex ${FILENAME%.dsp}.tex && pdflatex ${FILENAME%.dsp}.tex && cd .. &&
126 mkdir -p pdf && cp tex/${FILENAME%.dsp}.pdf pdf &&
127 mkdir -p cpp && mv ../${FILENAME%.dsp}.cpp cpp &&
128 cd ..
129 ;;
130 * )
131 echo error : \'$FILENAME\' does not have a \'.dsp\' extension.
132 exit 2
133 ;;
134 esac
135 else
136 print_usage
137 exit 1
138 fi
139 done
140 exit 0
141