5 # Generate a full Faust documentation, in a '*-mdoc' top directory.
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;
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"
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
()
45 echo error
: \'$DIR\' is not a directory.
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.
61 FILES
=`ls | grep -E "\.svg"`
62 for SRC
in $FILES ; do
66 echo "svg2pdf $SRC $PDF"
71 echo error
: \'$DIR\' is not a directory.
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.
82 charset
=`file -0 --mime-encoding $1 | cut -d' ' -f2`
83 recode $charset..utf-8
$1
88 if [ $1 = "-mdlang" ] ||
[ $1 = "--mathdoc-lang" ] ||
[ $1 = "-l" ]
90 MDLANGOPT
="-mdlang $2"
95 if [ $1 = "-utf8" ] ||
[ $1 = "--utf8" ]
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` &&
118 if [ $CONVERT = "utf8" ]
120 recode2utf8
$FILENAME
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
&&
131 echo error
: \'$FILENAME\' does not have a
\'.dsp
\' extension.