+%
+% written by Tom Cato Amundsen <tomcato@xoommail.com>
+% send questions/patches to:
+% gnu-music-discuss@gnu.org
+
\documentclass[a4paper, 12pt]{article}
\usepackage{t1enc,isolatin1}
send a patch.
So what does this look like? Well, here is an example:
-
-\begin{mudela}[verbatim]
-\score{
- \notes\relative c'{
- \time 5/8;
- [e16( g b c a g][e a b d] | )e2 d,8 |
- [e16( g b c a g][e a b d] | )b2 [a16( f] |
- [e a b d] )e4 c8 | [es16( bes a as g es][d c b! )g] |
- [f( a b d b a][f a b d] | )e2
- }
-}
-\end{mudela}
-
-\noindent produces this music:
-
-\begin{mudela}
+\begin{mudela}[veryverbatim, intertext="produces this music:"]
\score{
\notes\relative c'{
\time 5/8;
}
}
\end{mudela}
-
If you are lucky, the above example show a nice feature of LilyPond
and \LaTeX. Since LilyPond can output the music as \TeX~graphics,
\LaTeX~can insert pagebreaks between the lines of music.
If you want to make the music not so wide, you can insert a
\verb|\paper| statement that set the linewidth:
-\begin{mudela}[verbatim]
-\score{
- \notes\relative c'{
- \time 5/8;
- [e16( g b c a g][e a b d] | )e2 d,8 |
- [e16( g b c a g][e a b d] | )b2 [a16( f] |
- [e a b d] )e4 c8 | [es16( bes a as g es][d c b! )g] |
- [f( a b d b a][f a b d] | )e2
- }
- \paper{linewidth = 10.\cm;}
-}
-\end{mudela}
-
-\noindent produces this music:
-
-\begin{mudela}
-% dette er en kommentar
+\begin{mudela}[veryverbatim, intertext="produces this music:"]
\score{
\notes\relative c'{
\time 5/8;
will set the \verb|linewidth| variable to -1, so Lilypond
will make the music as short as possible but without breaking the
line. Here is a well know harmonic progression:
-\begin{mudela}
-% dette er en kommentar
- <c' e' g'> <b d' g'> <c'2 e' g'>
-\end{mudela}
-\noindent that is made by this code:
-\begin{mudela}[verbatim]
+\begin{mudela}[veryverbatim, intertext="produce a well known harmonic progression:"]
<c' e' g'> <b d' g'> <c'2 e' g'>
\end{mudela}
\verb|\includegraphics| command.
The code used look like this:
-\begin{mudela}[eps, verbatim]
+\begin{verbatim}
+\begin{mudela}[eps]
<c' e' g'> <b d' g'> <c'2 e' g'>
\end{mudela}
+\end{verbatim}
You can also use the \verb|eps| option if the block is a complete
mudela source. This 5 cm long empty line,
}
\end{mudela}
was created with this code:
-\begin{mudela}[eps, verbatim]
+\begin{verbatim}
+\begin{mudela}[eps]
\score{
\notes{s}
\paper{ linewidth = 5.\cm;}
}
\end{mudela}
+\end{verbatim}
+
To avoid that \LaTeX~places the music on a line of its one, there should
be no empty lines between the normal text and the mudela
environment.
\section{Fontsize options}
You can use all lilypond fontsizes in mudela-book.
-% LONG line just to test multiple mudela on one line
+% LONG line just to test multiple \mudela on one line
The default 16pt fontsize, \mudela{<c' e' g'>}, is probably to big to be included in the middle of the text. 11pt, \mudela[11pt]{<c' e' g'>} or 13pt, \mudela[13pt]{<c' e' g'>} is probably better.
The code can look like this:
-\begin{mudela}[13pt, eps, verbatim]
+\begin{verbatim}
+\begin{mudela}[13pt, eps]
<c' e' g'>
\end{mudela}
+\end{verbatim}
The following options set the fontsize:
\begin{itemize}
your own commands in a file specified by
the command line option \verb|--initfile=filename|. The format for the
file is a definition of a python dictionary:
-% mudela-book should really respect \begin{verbatim}
-
-\verb|{ 'mudela': r"""|
-
-\verb|\begin|\verb|{mudela}[eps \fontoptions]|
-\verb| \maininput|
-
-\verb|\end|\verb|{mudela}|
-
-\verb|""",|
-
-\verb| 'mudelaRhythm': r"""|
-
-\verb|\begin|\verb|{mudela}[eps \fontoptions]|
\begin{verbatim}
+{ 'mudela': r"""
+\begin{mudela}[eps \fontoptions]
+ \maininput
+\end{mudela}
+""",
+ 'mudelaRhythm': r"""
+\begin{mudela}[eps \fontoptions]
\score{
\type RhythmicStaff{
\notes{\stemup \maininput}
}
\paper{linewidth = -1.\cm;}
}
+\end{mudela}
+"""
+}
\end{verbatim}
-\verb|\end|\verb|{mudela}|
-
-\verb|"""|
-
-\verb|}|
-
The above code show how \verb|\mudela| could have been defined, and
also defines a new command \verb|mudelaRhythm|. Notice that you can
send fontsize options to the defined commands.
-\verb|\mudelaRhytm[11pt]{c4 c8 [c16 c] c4 c}| produce this music:
+\verb|\mudelaRhythm[11pt]{c4 c8 [c16 c] c4 c}| produce this music:
\begin{mudela}[eps, 11pt]
\score{
\type RhythmicStaff{
Since there is no finder's fee which doubles every year, there is no
need to wait for the price money to grow. So send a bug report today
-if you need this one of this options.
+if you need this one of these options.
\section{Examples}
This was all options to \verb|\begin{mudela}|. The rest of the
\begin{mudela}
\score{
\notes\relative c'{
- \time 12/8;
- r4-\fermata [b16-.( )b-.] [f'8-- dis16-.( )dis-. gis8--]
- [f16-.( )f-. dis8-- gis16-.( )gis-.] cis4.-\fermata |
-
- r4.-\fermata [cis,16 cis g'8 f16 f b8][g16 g f8 b16 b] dis4.-\fermata
+ \time 12/8;
+ r4-\fermata [b16-.( )b-.] [f'8-- dis16-.( )dis-. gis8--]
+ [f16-.( )f-. dis8-- gis16-.( )gis-.] cis4.-\fermata |
+ r4.-\fermata [cis,16 cis g'8 f16 f b8][g16 g f8 b16 b] dis4.-\fermata
}
\paper{linewidth = 7.\cm;}
}
the right marging if you set floatingfigure width and mudela linewidth
to the same value. The code looks like this:
-\verb|\begin{floatingfigure}{7cm}|
-\begin{mudela}[verbatim]
+\begin{verbatim}
+\begin{floatingfigure}[r]{7cm}
+\begin{mudela}
\score{
\notes\relative c'{
\time 12/8;
- r4.-\fermata [b16-.( )b-.] [f'8-- dis16-.( )dis-. gis8--]
- [f16-.( )f-. dis8-- gis16-.( )gis-.] cis8.-\fermata |
-
- r4.-\fermata [cis,16 cis g'8 f16 f b8]
- [g16 g f8 b16 b] dis4.-\fermata
+ r4-\fermata [b16-.( )b-.] [f'8-- dis16-.( )dis-. gis8--]
+ [f16-.( )f-. dis8-- gis16-.( )gis-.] cis4.-\fermata |
+ r4.-\fermata [cis,16 cis g'8 f16 f b8][g16 g f8 b16 b] dis4.-\fermata
}
\paper{linewidth = 7.\cm;}
}
\end{mudela}
-\verb|\end{floatingfigure}|
+\end{floatingfigure}
+\end{verbatim}
\twocolumn[\large The following is written in two columns just to show
what mudela-book can do..\normalsize]
mix braces that belongs to mudela-book and \LaTeX~on the same
line. The following code will probably break:
-\verb|\footnote{\begin{mudela}|
-
-\verb|\relative c''{ \key es; r8 [g g g] es2} |
-
-\verb|\end{mudela}}|
-
+\begin{verbatim}
+\footnote{\begin{mudela}
+\relative c''{ \key es; r8 [g g g] es2}
+\end{mudela}}
+\end{verbatim}
Mudela-book does know about \verb|\onecolumn| and \verb|\twocolumn|.
So the music will be adjusted to the new linewith:
-\begin{mudela}[verbatim]
-\score{
- \notes\relative c'{c d e f | g2 g | a4 a a a | g1 |
- f4 f f f | e2 e | d4 d d d | c1}
-}
-\end{mudela}
-produces
-\begin{mudela}
+\begin{mudela}[veryverbatim, intertext="produces"]
\score{
\notes\relative c'{c d e f | g2 g | a4 a a a | g1 |
f4 f f f | e2 e | d4 d d d | c1}
#!@PYTHON@
+#
+# The bugs you find are made by Tom Cato Amundsen <tomcato@xoommail.com>
+# Send patches/questions/bugreports to a mailinglist:
+# gnu-music-discuss@gnu.org
+# bug-gnu-music@gnu.org
+# help-gnu-music@gnu.org
+#
# All non-english comments are NOT in swedish, they are norwegian!
# TODO:
# * center option (??)
-# * mudela-book should treat \begin{verbatim} that contains inline mudela
-# correctly.
# * make mudela-book understand usepackage{geometry}
# * check that linewidth set in \paper is not wider than actual linewidth?
# * the following fails because mudelabook doesn't care that the
# - mudela-book will scan the mudela code to find out if it has to add
# paper-definition and \score{\notes{...}}
# - possible to define commands that look like this: \mudela{ c d e }
+# - don't produce .dvi output, it was a silly idea...
# 0.5.1:
# - removed init/mudela-book-defs.py, \mudela is defined inside mudela-book
# - fragment and nonfragment options will override autodetection of type of
# in mudela-block (voice contents or complete code)
+# 0.5.2:
+# - fixed verbatim option behaviour: don't show \begin{mudela} \end{mudela}
+# and show both mudela code and music
+# - veryverbatim option, same as verbatim but show \begin{mudela}
+# and \end{mudela}. (saves keystrokes in mudela-book-doc.doc)
+# - intertext="bla bla bla" option
+# - mudela-book now understand latex \begin{verbatim}
import os
import string
outdir = 'out'
initfile = ''
-program_version = '0.5.1'
+program_version = '0.5.2'
out_files = []
fontsize_pt2i = {'11pt':11, '13pt':13, '16pt':16, '20pt':20, '26pt':26}
begin_mudela_re = re.compile ('^ *\\\\begin{mudela}')
+begin_verbatim_re = re.compile ('^ *\\\\begin{verbatim}')
+end_verbatim_re = re.compile ('^ *\\\\end{verbatim}')
extract_papersize_re = re.compile('\\\\documentclass[\[, ]*(\w*)paper[\w ,]*\]\{\w*\}')
extract_fontsize_re = re.compile('[ ,\[]*([0-9]*)pt')
begin_mudela_opts_re = re.compile('\[[^\]]*\]')
preMudelaExample_re = re.compile('\\\\def\\\\preMudelaExample')
postMudelaExample_re = re.compile('\\\\def\\\\postMudelaExample')
boundingBox_re = re.compile('%%BoundingBox: ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)')
+intertext_re = re.compile("intertext=\"([^\"]*)\"")
def file_exist_b(name):
try:
self.code_type = 'fly'
if self.code_type_override:
self.code_type = self.code_type_override
- print "override:", self.code_type_override
self.write_red_tape()
for l in self.__lines:
self.file.write(l)
def __init__ (self, name):
self.output_fn = '%s/%s' % (outdir, name)
self.__lines = []
- def open_verbatim (self, line):
+ def open_verbatim (self, line, level):
self.__lines.append('\\begin{verbatim}\n')
- s = re.sub('[\s,]*verbatim[\s]*', '', line)
- s = re.sub('\[\]', '', s)
- self.__lines.append(s);
+ if level == 2:
+ s = re.sub('veryverbatim[\s,]*', '', line)
+ s = re.sub('intertext=\"([^\"]*)\"[\s,]*', '', s)
+ s = re.sub(',\s*\]', ']', s)
+ s = re.sub('\[\]', '', s)
+ self.__lines.append(s);
def close_verbatim (self):
self.__lines.append('\\end{verbatim}\n')
def write (self, s):
def do_it(self):
preMudelaDef = postMudelaDef = 0
(lines, self.deps) = self.get_lines ()
+ #HACK
+ latex_verbatim = 0
for line in lines:
if documentclass_re.search (line):
p = self.extract_papersize_from_documentclass (line)
preMudelaDef = 1
elif postMudelaExample_re.search (line):
postMudelaDef = 1
+ elif begin_verbatim_re.search (line):
+ latex_verbatim = 1
+ elif end_verbatim_re.search (line):
+ latex_verbatim = 0
elif begin_document_re.search (line):
if not preMudelaDef:
self.mudtex.write ('\\def\\preMudelaExample{}\n')
if not postMudelaDef:
self.mudtex.write ('\\def\\postMudelaExample{}\n')
- elif begin_mudela_re.search (line):
+ elif begin_mudela_re.search (line) and not latex_verbatim:
Props.clear_for_new_block()
if __debug__:
if self.mode == 'mudela':
if r:
o = r.group()[1:][:-1]
optlist = re.compile('[ ,]*').split(o)
+ m = intertext_re.search(r.group())
+ if m:
+ self.intertext = m.groups()[0]
+ else:
+ self.intertext = None
else:
optlist = []
- if ('verbatim' in optlist) or (Props.force_verbatim_b):
+ if ('veryverbatim' in optlist):
+ self.verbatim = 2
+ elif ('verbatim' in optlist) or (Props.force_verbatim_b):
self.verbatim = 1
- self.mudtex.open_verbatim (line)
- continue
else:
self.verbatim = 0
- self.mudela = Mudela_output (self.gen_basename ())
- elif end_mudela_re.search (line):
+ if self.verbatim:
+ self.mudtex.open_verbatim (line, self.verbatim)
+ self.mudela = Mudela_output (self.gen_basename ())
+ self.mudela.write (line)
+ continue
+ elif end_mudela_re.search (line) and not latex_verbatim:
if __debug__:
if self.mode != 'mudela':
raise AssertionError
- if self.mudela:
- self.mudela.close ()
- self.mudtex.write (self.mudela.insert_me_string())
- del self.mudela
- self.mudela = None
- self.fine_count = self.fine_count + 1
- else:
- self.mudtex.write (line)
+
+ if self.verbatim:
+ if self.verbatim == 2:
+ self.mudtex.write (line)
self.mudtex.close_verbatim ()
+ self.mudela.close ()
+ if self.verbatim and self.intertext:
+ self.mudtex.write(self.intertext)
+ self.mudtex.write (self.mudela.insert_me_string())
+ del self.mudela
+ self.mudela = None
+ self.fine_count = self.fine_count + 1
self.mode = 'latex'
continue
- if self.mode == 'mudela' and not self.verbatim:
+ if self.mode == 'mudela':
self.mudela.write (line)
+ if self.verbatim:
+ self.mudtex.write (line)
else:
self.mudtex.write (line)
self.set_sections(line)