1 \chapter{Mathematical Documentation
}
4 The
\faust compiler provides a mechanism to produce a self-describing documentation of the mathematical semantic of a
\faust program, essentially as a pdf file. The corresponding options are
\lstinline!-mdoc! (short) or
\lstinline!--mathdoc! (long).
6 \section{Goals of the mathdoc
}
7 \label{sec:goals-of-mdoc
}
9 There are three main goals, or uses, of this mathematical documentation:
11 \item to preserve signal processors, independently from any computer language but only under a mathematical form;
12 \item to bring some help for debugging tasks, by showing the formulas as they are really computed after the compilation stage;
13 \item to give a new teaching support, as a bridge between code and formulas for signal processing.
16 \section{Installation requirements
}
20 \item \lstinline!faust!, of course!
21 \item \lstinline!svg2pdf! (from the Cairo
2D graphics library), to convert block-diagrams, as
\latex doesn't eat
\svg directly yet...
22 \item \lstinline!breqn!, a
\latex package to handle automatic breaking of long equations,
23 \item \lstinline!pdflatex!, to compile the
\latex output file.
27 \section{Generating the mathdoc
}
28 \label{sec:generating-mdoc
}
30 The easiest way to generate the complete mathematical documentation is to call the
\lstinline!faust2mathdoc! script on a
\faust file, as the
\lstinline!-mdoc! option leave the documentation production unfinished. For example:
32 faust2mathdoc noise.dsp
35 \subsection{Invoking the -mdoc option
}
36 \label{sec:invoking-mdoc
}
38 Calling directly
\lstinline!faust -mdoc! does only the first part of the work, generating:
40 \item a top-level directory, suffixed with "
\texttt{-mdoc
}",
41 \item 5 subdirectories (
\lstinline!cpp/!,
\lstinline!pdf/!,
\lstinline!src/!,
\lstinline!svg/!,
\lstinline!tex/!),
42 \item a
\latex file containing the formulas,
43 \item \svg files for block-diagrams.
48 \item \lstinline!cpp/! remains empty,
49 \item \lstinline!pdf/! remains empty,
50 \item \lstinline!src/! contains all
\faust sources used (even libraries),
51 \item \lstinline!svg/! contains
\svg block-diagram files,
52 \item \lstinline!tex/! contains the generated
\latex file.
55 \subsection{Invoking faust2mathdoc
}
56 \label{sec:invok-faust2m
}
58 The
\lstinline!faust2mathdoc! script calls
\lstinline!faust --mathdoc! first, then it finishes the work:
60 \item moving the output C++ file into
\lstinline!cpp/!,
61 \item converting all
\svg files into pdf files (you must have
\lstinline!svg2pdf! installed, from the Cairo
2D graphics library),
62 \item launching
\lstinline!pdflatex! on the
\latex file (you must have both
\lstinline!pdflatex! and the
\lstinline!breqn! package installed),
63 \item moving the resulting pdf file into
\lstinline!pdf/!.
66 \subsection{Online examples
}
67 \label{sec:mdoc-examples
}
69 To get an idea of the results of this mathematical documentation, which captures the mathematical semantic of
\faust programs, you can look at two pdf files online:
71 \item \myurl{http://faust.grame.fr/pdf/karplus.pdf
} (automatic documentation),
72 \item \myurl{http://faust.grame.fr/pdf/noise.pdf
} (manual documentation).
75 You can also generate all
\emph{mdoc
} pdfs at once, simply invoking the
\lstinline!make mathdoc! command inside the
\lstinline!examples/! directory:
77 \item for each
\lstinline!
%.dsp! file, a complete \lstinline!%-mdoc! directory will be generated,
78 \item a single
\lstinline!allmathpdfs/! directory will gather all the generated pdf files.
82 \section{Automatic documentation
}
83 \label{sec:auto-docum
}
85 By default, when no
\lstinline!<mdoc>! tag can be found in the input
\faust file, the
\lstinline!-mdoc! option automatically generates a
\latex file with four sections:
87 \item ''
\textbf{Equations of process
}'', gathering all formulas needed for
\lstinline!process!,
88 \item ''
\textbf{Block-diagram schema of process
}'', showing the top-level block-diagram of
\lstinline!process!,
89 \item ''
\textbf{Notice of this documentation
}'', summing up generation and conventions information,
90 \item ''
\textbf{Complete listing of the input code
}'', listing all needed input files (including libraries).
94 \section{Manual documentation
}
95 \label{sec:manual-mdoc
}
97 You can specify yourself the documentation instead of using the automatic mode, with five xml-like tags. That permits you to modify the presentation and to add your own comments, not only on
\lstinline!process!, but also about any expression you'd like to. Note that as soon as you declare an
\lstinline!<mdoc>! tag inside your
\faust file, the default structure of the automatic mode is ignored, and all the
\latex stuff becomes up to you!
102 Here are the six specific tags:
104 \item \lstinline!<mdoc></mdoc>!, to open a documentation field in the
\faust code,
106 \item \lstinline!<equation></equation>!, to get equations of a
\faust expression,
107 \item \lstinline!<diagram></diagram>!, to get the top-level block-diagram of a
\faust expression,
108 \item \lstinline!<metadata></metadata>!, to reference
\faust metadatas (cf. declarations), calling the corresponding keyword,
109 \item \lstinline!<notice />!, to insert the "adaptive'' notice all formulas actually printed,
110 \item \lstinline!<listing
[attributes
] />!, to insert the listing of
\faust files called.
114 The
\lstinline!<listing />! tag can have up to three boolean attributes (set to
\lstinline!"true"! by default):
116 \item \lstinline'mdoctags' for
\lstinline'<mdoc>' tags;
117 \item \lstinline'dependencies' for other files dependencies;
118 \item \lstinline'distributed' for the distribution of interleaved
\faust code between
\lstinline'<mdoc>' sections.
122 \subsection{The mdoc top-level tags
}
125 The
\lstinline!<mdoc></mdoc>! tags are the top-level delimiters for
\faust mathematical documentation sections. This means that the four other documentation tags can't be used outside these pairs (see section
\ref{sec:documentation
}).
127 In addition of the four inner tags,
\lstinline!<mdoc></mdoc>! tags accept free
\latex text, including its standard macros (like
\lstinline!
\section!,
\lstinline!
\emph!, etc.). This allows to manage the presentation of resulting tex file directly from within the input
\faust file.
129 The complete list of the
\latex packages included by
\faust can be found in the file
\lstinline!architecture/latexheader.tex!.
131 \subsection{An example of manual mathdoc
}
132 \label{sec:ex-mathdoc
}
137 \title{<metadata>name</metadata>
}
138 \author{<metadata>author</metadata>
}
144 \textbf{name
} & <metadata>name</metadata> \\
145 \textbf{version
} & <metadata>version</metadata> \\
146 \textbf{author
} & <metadata>author</metadata> \\
147 \textbf{license
} & <metadata>license</metadata> \\
148 \textbf{copyright
} & <metadata>copyright</metadata> \\
153 //-----------------------------------------------------------------
154 // Noise generator and demo file for the Faust math documentation
155 //-----------------------------------------------------------------
157 declare name "Noise";
158 declare version "
1.1";
159 declare author "Grame";
160 declare author "Yghe";
161 declare license "BSD";
162 declare copyright "(c)GRAME
2009";
165 \section{Presentation of the "noise.dsp" Faust program
}
166 This program describes a white noise generator with an interactive volume, using a random function.
168 \subsection{The random function
}
171 random = +(
12345)~*(
1103515245);
174 The
\texttt{random
} function describes a generator of random numbers, which equation follows. You should notice hereby the use of an integer arithmetic on
32 bits, relying on integer wrapping for big numbers.
175 <equation>random</equation>
177 \subsection{The noise function
}
180 noise = random/
2147483647.0;
183 The white noise then corresponds to:
184 <equation>noise</equation>
186 \subsection{Just add a user interface element to play volume!
}
189 process = noise * vslider("Volume
[style:knob
]",
0,
0,
1,
0.1);
192 Endly, the sound level of this program is controlled by a user slider, which gives the following equation:
193 <equation>process</equation>
195 \section{Block-diagram schema of process
}
196 This process is illustrated on figure
1.
197 <diagram>process</diagram>
199 \section{Notice of this documentation
}
200 You might be careful of certain information and naming conventions used in this documentation:
203 \section{Listing of the input code
}
204 The following listing shows the input Faust code, parsed to compile this mathematical documentation.
205 <listing mdoctags="false" dependencies="false" distributed="true" />
210 The following page which gathers the four resulting pages of
\lstinline!noise.pdf! in small size. might give you an idea of the produced documentation.
213 \subsection{The -stripmdoc option
}
214 \label{sec:striping-option
}
216 As you can see on the resulting file
\lstinline!noisemetadata.pdf! on its pages
3 and
4, the listing of the input code (section\,
4) contains all the mathdoc text (here colored in grey). As it may be useless in certain cases (see Goals, section
\ref{sec:goals-of-mdoc
}), we provide an option to strip mathdoc contents directly at compilation stage:
\lstinline!-stripmdoc! (short) or
\lstinline!--strip-mdoc-tags! (long).
219 \section{Localization of mathdoc files
}
220 \label{sec:localization-mdoc
}
222 By default, texts used by the documentator are in English, but you can specify another language (French, German and Italian for the moment), using the
\lstinline!-mdlang! (or
\lstinline!--mathdoc-lang!) option with a two-letters argument (
\lstinline!en!,
\lstinline!fr!,
\lstinline!it!, etc.).
224 The
\lstinline!faust2mathdoc! script also supports this option, plus a third short form with
\lstinline!-l!:
226 faust2mathdoc -l fr myfaustfile.dsp
229 If you would like to contribute to the localization effort, feel free to translate the mathdoc texts from any of the
\lstinline!mathdoctexts-*.txt! files, that are in the
\lstinline!architecture! directory (
\lstinline!mathdoctexts-fr.txt!,
\lstinline!mathdoctexts-it.txt!, etc.). As these files are dynamically loaded, just adding a new file with an appropriate name should work.
231 \includepdf[pages=-, frame=true, angle=-
90, scale=
0.75, nup=
1x2
]{images/noisemetadata
}
234 \section{Summary of the mathdoc generation steps
}
235 \label{sec:mdoc-summary
}
238 \item First, to get the full mathematical documentation done on your faust file, call
\lstinline!faust2mathdoc myfaustfile.dsp!.
239 \item Then, open the pdf file
\lstinline!myfaustfile-mdoc/pdf/myfaustfile.pdf!.