]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
remove bogus docstring.
[lilypond.git] / scripts / lilypond-book.py
index e9560f36845a164ea83df3f38b6bfdfaef043530..c0ca09a5537a3aab397da096459f3d33a3d50219 100644 (file)
@@ -1,40 +1,54 @@
 #!@PYTHON@
 # vim: set noexpandtab:
-# TODO:
-# * junk --outdir for--output
-# * Figure out clean set of options.
-# *
-# * texinfo: add support for @pagesize
 
-# todo: dimension handling (all the x2y) is clumsy. (tca: Thats
-#       because the values are taken directly from texinfo.tex,
-#       geometry.sty and article.cls. Give me a hint, and I'll
-#       fix it.)
+"""
 
-#
-# TODO: magnification support should also work for texinfo -> html: eg. add as option to dvips.
-#
+  TODO:
+  * junk --outdir for--output
+  * Figure out clean set of options.
+  *
+  * texinfo: add support for @pagesize
 
+  todo: dimension handling (all the x2y) is clumsy. (tca: Thats
+        because the values are taken directly from texinfo.tex,
+        geometry.sty and article.cls. Give me a hint, and I'll
+        fix it.)
 
-#
-# This is a slightly hairy program. The general approach is as follows 
-# The input string is chopped up in chunks, i.e. ,  a list of tuples
-#
-#   with the format  (TAG_STR, MAIN_STR, OPTIONS, TODO, BASE)
-#
-# This list is build step by step: first ignore and verbatim commands are handled,
-# delivering a list of chunks.
-# 
-# then all chunks containing lilypnod commands are chopped up
-#
-# when all chunks have their final form, all bodies from lilypond blocks are 
-# extracted, and if applicable, written do disk and run through lilypond.
-# 
 
+  TODO: magnification support should also work for texinfo -> html: eg. add as option to dvips.
+
+
+
+  This is a slightly hairy program. The general approach is as follows 
+  The input string is chopped up in chunks, i.e. ,  a list of tuples
+
+    with the format  (TAG_STR, MAIN_STR, OPTIONS, TODO, BASE)
+
+  This list is built step by step: first ignore and verbatim commands
+  are handled, delivering a list of chunks.
+  
+  then all chunks containing lilypond commands are chopped up
+
+  when all chunks have their final form, all bodies from lilypond blocks are 
+  extracted, and if applicable, written do disk and run through lilypond.
+  
+
+tags supported
 
-# This is was the idea for handling of comments:
+  ignore
+  lilypond
+  input
+  verb
+  verbatim
+  multicols
+  numcols
+  
 
 
+
+"""
+
+#  This is was the idea for handling of comments:
 #      Multiline comments, @ignore .. @end ignore is scanned for
 #      in read_doc_file, and the chunks are marked as 'ignore', so
 #      lilypond-book will not touch them any more. The content of the
@@ -54,7 +68,7 @@
 #      The the rest of the rexeces are searched for. They don't have to test
 #      if they are on a commented out line.
 
-
+import glob
 import stat
 import string
 
@@ -89,14 +103,13 @@ global _;_=ly._
 global re;re = ly.re
 
 # lilylib globals
+program_version = '@TOPLEVEL_VERSION@'
 program_name = 'lilypond-book'
 verbose_p = 0
 pseudo_filter_p = 0
 original_dir = os.getcwd ()
-#temp_dir = os.path.join (original_dir,  '%s.dir' % program_name)
-#urg
-temp_dir = '/tmp'
-keep_temp_dir_p = 0
+
+
 preview_resolution = 90
 
 ## FIXME
@@ -112,21 +125,20 @@ option_definitions = [
        (_ ("DIM"),  '', 'default-music-fontsize', _ ("default fontsize for music.  DIM is assumed to be in points")),
        (_ ("DIM"),  '', 'default-lilypond-fontsize', _ ("deprecated, use --default-music-fontsize")),
        (_ ("OPT"), '', 'extra-options', _ ("pass OPT quoted to the lilypond command line")),
-       (_ ("DIM"), '', 'force-music-fontsize', _ ("force fontsize for all inline lilypond. DIM is assumed be to in points")),
+       (_ ("DIM"), '', 'force-music-fontsize', _ ("force fontsize for all inline lilypond. DIM is assumed to be in points")),
        (_ ("DIM"), '', 'force-lilypond-fontsize', _ ("deprecated, use --force-music-fontsize")),
-       ('', 'h', 'help', _ ("this help")),
+       ('', 'h', 'help', _ ("print this help")),
        (_ ("DIR"), 'I', 'include', _ ("include path")),
        ('', 'M', 'dependencies', _ ("write dependencies")),
        (_ ("PREF"), '',  'dep-prefix', _ ("prepend PREF before each -M dependency")),
        ('', 'n', 'no-lily', _ ("don't run lilypond")),
        ('', '', 'no-pictures', _ ("don't generate pictures")),
        ('', '', 'no-music', _ ("strip all lilypond blocks from output")),
-       ('', '', 'read-lys', _ ("don't write ly files.")),
        (_ ("FILE"), 'o', 'outname', _ ("filename main output file")),
        (_ ("FILE"), '', 'outdir', _ ("where to place generated files")),
        (_ ('RES'), '', 'preview-resolution',
         _ ("set the resolution of the preview to RES")),
-       ('', 'V', 'verbose', _ ("verbose")),
+       ('', 'V', 'verbose', _ ("be verbose")),
        ('', 'v', 'version', _ ("print version information")),
        ('', 'w', 'warranty', _ ("show warranty and copyright")),
        ]
@@ -137,14 +149,13 @@ option_definitions = [
 
 include_path = [os.getcwd ()]
 
-
 #lilypond_binary = 'valgrind --suppressions=/home/hanwen/usr/src/guile-1.6.supp  --num-callers=10 /home/hanwen/usr/src/lilypond/lily/out/lilypond'
 
-lilypond_binary = os.path.join ('@bindir@', 'lilypond')
+lilypond_binary = os.path.join ('@bindir@', 'lilypond-bin')
 
 # only use installed binary  when we're installed too.
 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
-       lilypond_binary = 'lilypond'
+       lilypond_binary = 'lilypond-bin'
 
 
 
@@ -152,7 +163,7 @@ ly2dvi_binary = os.path.join ('@bindir@', 'ly2dvi')
 
 # only use installed binary  when we're installed too.
 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
-       lilypond_binary = 'ly2dvi'
+       ly2dvi_binary = 'ly2dvi'
 
 
 
@@ -161,7 +172,6 @@ g_here_dir = os.getcwd ()
 g_dep_prefix = ''
 g_outdir = ''
 g_force_music_fontsize = 0
-g_read_lys = 0
 g_do_pictures = 1
 g_do_music = 1
 g_make_html = 0
@@ -209,7 +219,7 @@ class LatexPaper:
                cmd = "latex '\\nonstopmode \input %s'" % fname
                # Ugh.  (La)TeX writes progress and error messages on stdout
                # Redirect to stderr
-               cmd += ' 1>/dev/stderr'
+               cmd = '(( %s  >&2 ) >&- )' % cmd
                status = ly.system (cmd, ignore_error = 1)
                signal = 0xf & status
                exit_status = status >> 8
@@ -341,9 +351,6 @@ output_dict= {
 
        'html' : {
 
-               'output-lilypond': '''<lilypond%s>
-%s
-</lilypond>''',
                'output-filename' : r'''
 <!-- %s >
 <a href="%s">
@@ -369,29 +376,22 @@ output_dict= {
                ## inline music doesn't.
                ## possibly other center options?
                'output-html': r'''
-<a href="%(fn)s.png">
-<img align="center" valign="center" border="0" src="%(fn)s.png" alt="[picture of music]"></a>
-''',
+%(htmlimages)s''',
                },
 
 
        'latex': {
 
-               'output-lilypond-fragment' : r'''\begin[eps,singleline,%s]{lilypond}
-  \context Staff <
+               'output-lilypond-fragment' : r'''\begin[singleline,%s]{lilypond}
     \context Voice{
       %s
     }
-  >
 \end{lilypond}''',
                'output-filename' : r'''\verb+%s+:\\
 %% %s
 %% %s
 ''',
-               'output-lilypond': r'''\begin[%s]{lilypond}
-%s
-\end{lilypond}
-''',
+
                # verbatim text is always finished with \n
                'output-verbatim': r'''\begin{verbatim}
 %s\end{verbatim}
@@ -400,31 +400,28 @@ output_dict= {
                'output-small-verbatim': r'''{\small\begin{verbatim}
 %s\end{verbatim}}
 ''',
-               'output-default-post': "\\def\postLilypondExample{}\n",
-               'output-default-pre': "\\def\preLilypondExample{}\n",
+               'output-default-post': "\\def\postLilyPondExample{}\n",
+               'output-default-pre': "\\def\preLilyPondExample{}\n",
                'usepackage-graphics': '\\usepackage{graphics}\n',
-               'output-eps': '\\noindent\\parbox{\\lilypondepswidth{%(fn)s.eps}}{\includegraphics{%(fn)s}}',
                'output-noinline': r'''
 %% generated: %(fn)s.eps
 ''',
-               'output-latex-quoted': r'''{\preLilypondExample
+               'output-latex-quoted': r'''{\preLilyPondExample
 \input %(fn)s.tex
-\postLilypondExample}''',
+\postLilyPondExample}''',
                'output-latex-noquote': r'''{\parindent 0pt
-\preLilypondExample
+\preLilyPondExample
 \input %(fn)s.tex
-\postLilypondExample}''',
+\postLilyPondExample}''',
                'pagebreak': r'\pagebreak',
                },
 
 
        'texi' : {
 
-               'output-lilypond': '''@lilypond[%s]
-%s
-@end lilypond
-''',
-               'output-filename' : r'''@ifnothtml
+
+               'output-filename' : r'''
+@ifnothtml
 @file{%s}:@*
 @end ifnothtml
 @ifhtml
@@ -457,9 +454,8 @@ output_dict= {
 \catcode`\@=0
 @end tex
 @html
-<p><a href="%(fn)s.png">
-<img border=0 src="%(fn)s.png" alt="[picture of music]">
-</a><p>
+<p>%(htmlimages)s
+<p>
 @end html
 ''',
                'output-texi-quoted': r'''@quotation
@@ -470,9 +466,8 @@ output_dict= {
 \catcode`\@=0
 @end tex
 @html
-<a href="%(fn)s.png">
-<img border=0 src="%(fn)s.png" alt="[picture of music]">
-</a>
+<p>%(htmlimages)s
+<p>
 @end html
 @end quotation
 ''',
@@ -543,8 +538,8 @@ re_dict = {
                'lilypond-file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
                'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
                'lilypond-block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
-               'def-post-re': r"\\def\\postLilypondExample",
-               'def-pre-re': r"\\def\\preLilypondExample",
+               'def-post-re': r"\\def\\postLilyPondExample",
+               'def-pre-re': r"\\def\\preLilyPondExample",
                'usepackage-graphics': r"\usepackage\s*{graphics}",
                'intertext': r',?\s*intertext=\".*?\"',
                'multiline-comment': no_match,
@@ -558,7 +553,7 @@ re_dict = {
        # why do we have distinction between @mbinclude and @include?
 
        'texi': {
-               'include':  '(?m)^[^%\n]*?(?P<match>@mbinclude[ \n\t]+(?P<filename>[^\t \n]*))',
+               'include':  '(?m)^[^%\n]*?(?P<match>@mbinclude\s+(?P<filename>\S*))',
                'input': no_match,
                'header': no_match,
                'preamble-end': no_match,
@@ -567,7 +562,7 @@ re_dict = {
                'verb': r'''(?P<code>@code{.*?})''',
                'lilypond-file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
                'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
-               'lilypond-block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end +lilypond)\s''',
+               'lilypond-block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
                'option-sep' : ',\s*',
                'intertext': r',?\s*intertext=\".*?\"',
                'multiline-comment': r"(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end ignore)\s",
@@ -635,7 +630,7 @@ def error (str):
 
 
 def compose_full_body (body, opts):
-       '''Construct the lilypond code to send to Lilypond.
+       '''Construct the lilypond code to send to LilyPond.
        Add stuff to BODY using OPTS as options.'''
        music_size = default_music_fontsize
        if g_force_music_fontsize:
@@ -671,9 +666,9 @@ def compose_full_body (body, opts):
        if is_fragment and not 'multiline' in opts:
                opts.append ('singleline')
 
-       if 'singleline' in opts:
+       if 'raggedright' in opts or  'singleline' in opts:
                if not linewidth:
-                       linewidth = 'linewidth = -1.0'
+                       linewidth = 'raggedright = ##t'
                if not indent:
                        indent = 'indent = 0.0\mm'
        elif not linewidth:
@@ -692,6 +687,7 @@ def compose_full_body (body, opts):
 }
 '''
 
+       orig_name = ''
        for o in opts:
                m= re.search ('relative(.*)', o)
                v = 0
@@ -709,7 +705,10 @@ def compose_full_body (body, opts):
                                pitch = pitch + '\'' * v
 
                        body = '\\relative %s { %s }' % (pitch, body)
-
+               m =re.search ("filename=(.*)", o)
+               if m:
+                       orig_name = m.group (1)
+               
        if is_fragment:
                body = r'''
 \score {
@@ -733,6 +732,10 @@ def compose_full_body (body, opts):
 }
 ''' % (optstring, music_size, linewidth, indent, notime) + body
 
+       if orig_name:
+               body = '\\renameinput \"%s\"\n%s' % (orig_name, body)
+       
+
        # ughUGH not original options
        return body
 
@@ -753,7 +756,7 @@ def scan_latex_preamble (chunks):
                if not m:
                        error ("Latex documents must start with a \documentclass command")
                if m.group (1):
-                       options = re.split (',[\n \t]*', m.group (1)[1:-1])
+                       options = re.split (r',\s*', m.group (1)[1:-1])
                else:
                        options = []
                if 'twocolumn' in options:
@@ -897,14 +900,18 @@ def make_lilypond_file (m):
        '''
 
        if m.group ('options'):
-               options = m.group ('options')
+               options = get_re ('option-sep').split (m.group ('options'))
        else:
-               options = ''
+               options = []
        (content, nm) = find_file (m.group ('filename'))
-       options = "filename=%s," % nm + options
+       options.append ("filename=%s" % nm)
+       (path, base) = os.path.split (nm)
+       
+       if path not in include_path:
+               include_path.append (path)
 
-       return [('input', get_output ('output-lilypond') %
-                       (options, content))]
+       return [('lilypond', content, options)]
+       
 
 def make_ly2dvi_block (m):
        '''
@@ -970,6 +977,12 @@ def chop_chunks (chunks, re_name, func, use_match=0):
        return newchunks
 
 def determine_format (str):
+       """
+
+       SIDE EFFECT! This sets FORMAT and PAPERGURU
+
+       """
+       
        global format
        if format == '':
                html = re.search ('(?i)<[dh]tml', str[:200])
@@ -1029,14 +1042,16 @@ def unique_file_name (body):
 
 def schedule_lilypond_block (chunk):
        '''Take the body and options from CHUNK, figure out how the
-       real .ly should look, and what should be left MAIN_STR (meant
-       for the main file).  The .ly is written, and scheduled in
+       real .ly should look.  The .ly is written, and scheduled in
        TODO.
 
-       Return: a chunk (TYPE_STR, MAIN_STR, OPTIONS, TODO, BASE)
+       Return: a single chunk.
 
-       TODO has format [basename, extension, extension, ... ]
+       The chunk pertaining to the lilypond output
+       has the format (TYPE_STR, MAIN_STR, OPTIONS, TODO, BASE), 
+       where TODO has format [basename, extension, extension, ... ]
        '''
+
        (type, body, opts) = chunk
        assert type == 'lilypond'
        file_body = compose_full_body (body, opts)
@@ -1052,9 +1067,8 @@ def schedule_lilypond_block (chunk):
                                taken_file_names[basename] = 0
                        else:
                                taken_file_names[basename] = taken_file_names[basename] + 1
-                               basename = basename + "-%i" % taken_file_names[basename]
-       if not g_read_lys:
-               update_file (file_body, os.path.join (g_outdir, basename) + '.ly')
+                               basename = basename + "-t%i" % taken_file_names[basename]
+       update_file (file_body, os.path.join (g_outdir, basename) + '.ly')
        needed_filetypes = ['tex']
 
        if format == 'html' or g_make_html:
@@ -1064,35 +1078,72 @@ def schedule_lilypond_block (chunk):
                needed_filetypes.append ('eps')
 
        pathbase = os.path.join (g_outdir, basename)
-       def f (base, ext1, ext2):
-               a = os.path.isfile (base + ext2)
-               if (os.path.isfile (base + ext1) and
-                   os.path.isfile (base + ext2) and
-                               os.stat (base+ext1)[stat.ST_MTIME] >
-                               os.stat (base+ext2)[stat.ST_MTIME]) or \
-                               not os.path.isfile (base + ext2):
+       def must_rebuild (base, ext1, ext2):
+               
+               f2 = base + ext2
+               f1 = base + ext1
+               fp2 = base + '-page1' + ext2
+
+               isfile2 = os.path.isfile (f2)
+               
+               if not isfile2 and os.path.isfile (fp2):
+                       f2  = fp2
+                       isfile2 = os.path.isfile (fp2)
+                       
+               if (os.path.isfile (f2) and isfile2 and
+                   os.stat (f1)[stat.ST_MTIME] >
+                   os.stat (f2)[stat.ST_MTIME]) or \
+                   not isfile2:
+               
                        return 1
+               
        todo = []
-       if 'tex' in needed_filetypes and f (pathbase, '.ly', '.tex'):
+       if 'tex' in needed_filetypes and must_rebuild (pathbase, '.ly', '.tex'):
                todo.append ('tex')
-       if 'eps' in needed_filetypes and f (pathbase, '.tex', '.eps'):
+       if 'eps' in needed_filetypes and must_rebuild (pathbase, '.tex', '.eps'):
                todo.append ('eps')
-       if 'png' in needed_filetypes and f (pathbase, '.eps', '.png'):
+       if 'png' in needed_filetypes and must_rebuild (pathbase, '.eps', '.png'):
                todo.append ('png')
-       newbody = ''
 
+       return ('lilypond', body, opts, todo, basename)
+
+def format_lilypond_block (chunk):
+       """
+       
+       Figure out  what should be left MAIN_STR (meant
+       for the main file) from a lilypond chunk: process
+       verbatim, and other options. Return: multiple chunks.
+
+       
+       """
+
+       
+       return_chunks = []
+
+       (type, body, opts, todo, basename) = chunk
+       assert type == 'lilypond'
+
+
+       newbody = ''
+       filename_chunk = None 
        if 'printfilename' in opts:
                for o in opts:
                        m= re.match ("filename=(.*)", o)
                        if m:
-                               newbody = newbody + get_output ("output-filename") % (m.group (1), basename + '.ly', m.group (1))
+                               template = get_output ("output-filename")
+                               b =  basename + '.ly'
+                               human_base = os.path.basename (m.group (1))
+                                                 
+                               ## todo: include path, but strip 
+                               ## first part of the path.
+                               filename_chunk = ('input',  template % (human_base, b,human_base))
                                break
 
 
        if 'smallverbatim' in opts:
-               newbody = newbody + output_verbatim (body, 1)
+               newbody += output_verbatim (body, 1)
        elif 'verbatim' in opts:
-               newbody = newbody + output_verbatim (body, 0)
+               newbody += output_verbatim (body, 0)
 
        for o in opts:
                m = re.search ('intertext="(.*?)"', o)
@@ -1107,23 +1158,62 @@ def schedule_lilypond_block (chunk):
        if 'noinline' in opts:
                s = 'output-noinline'
        elif format == 'latex':
-               if 'eps' in opts:
-                       s = 'output-eps'
+               if 'quote' in opts:
+                       s = 'output-latex-quoted'
                else:
-                       if 'noquote' in opts:
-                               s = 'output-latex-noquote'
-                       else:
-                               s = 'output-latex-quoted'
+                       s = 'output-latex-noquote'
        elif format == 'texi':
-               if 'noquote' in opts:
-                       s = 'output-texi-noquote'
-               else:
+               if 'quote' in opts:
                        s = 'output-texi-quoted'
+               else:
+                       s = 'output-texi-noquote'
        else: # format == 'html'
                s = 'output-html'
-       newbody = newbody + get_output (s) % {'fn': basename }
-       return ('lilypond', newbody, opts, todo, basename)
 
+       def html_pages (basename):
+               pat = os.path.join (g_outdir, "%s-page*.png"%  basename)
+               
+               files =  glob.glob (pat)
+               
+               
+               template = '''<img align="center" valign="center"
+               border="0" src="%s" alt="[picture of music]">'''
+
+               str = ''
+               if  files == []:
+                       files = [basename+'.png' ]
+               else:
+                       files = map (os.path.basename, files)
+                       
+               for f in  files:
+                       str += template % f
+
+               str = '<a href="%s.ly">%s</a>' % (basename, str)
+
+               return str
+
+       
+       newbody = newbody + get_output (s) % {'fn': basename,
+                                             'htmlimages': html_pages(basename)
+                                             }
+
+       if filename_chunk:
+               return_chunks += [filename_chunk]
+       
+       return_chunks += [('lilypond', newbody, opts, todo, basename)]
+       
+       return return_chunks
+
+def format_lilypond_output_bodies (chunks):
+       newchunks = []
+       for c in chunks:
+
+               if c[0] == 'lilypond':
+                       newchunks += format_lilypond_block (c)
+               else:
+                       newchunks.append (c)
+
+       return newchunks
 
 
 
@@ -1137,7 +1227,9 @@ def process_lilypond_blocks (chunks):#ugh rename
                        paperguru.m_num_cols = c[2]
                elif c[0] == 'multicols':
                        paperguru.m_multicols = c[2]
+                       
                newchunks.append (c)
+               
        return newchunks
 
 def process_ly2dvi_blocks (chunks):
@@ -1163,12 +1255,15 @@ linking to the menu.
                outname = base + '.ly'
                changed = update_file (content, outname)
 
-               preview = base + ".png"
-               if changed or not os.path.isfile (preview):
+               preview = base + ".preview.png"
+               preview_page = base + '-page1.png'
+               
+               if changed or not (os.path.isfile (preview) or
+                                  os.path.isfile (preview_page)):
                        
                        ly.system ('%s --preview --postscript --verbose %s ' % (ly2dvi_binary, base) ) 
 
-                       ly.make_page_images (base)
+                       ly.make_ps_images (base + '.ps')
                        ly.system ('gzip -9 - < %s.ps > %s.ps.gz' %  (base, base))
                        
                def size_str (fn):
@@ -1189,9 +1284,9 @@ linking to the menu.
                        }
 
                menu = ''
-               page_files = ly.read_pipe ('ls --color=no -1 %s-page*.png' % base)
+               page_files = glob.glob ('%s-page*.png' % base)
 
-               for p in string.split (page_files, '\n'):
+               for p in page_files:
                        p = p.strip()
                        if os.path.isfile (p):
                                sz = size_str (p)
@@ -1229,7 +1324,7 @@ use scalable fonts and should look OK at any resolution."""
                
                open (base + '.html','w'). write (separate_menu)
 
-               inline_menu = '<p/><a href="%s.html"><img src="%s"><p/></a>' % (base, original_name, preview)
+               inline_menu = '<p/><a href="%s.html"><img alt="%s" src="%s"></a><p/>' % (base, original_name, preview)
 
                return ('ly2dvi', inline_menu)
 
@@ -1250,6 +1345,7 @@ def compile_all_files (chunks):
        for c in chunks:
                if c[0] != 'lilypond':
                        continue
+
                base  = c[4]
                exts = c[3]
                for e in exts:
@@ -1281,6 +1377,9 @@ def compile_all_files (chunks):
                texfiles = string.join (tex)
                cmd = string.join ((lilypond_binary, lilyopts, g_extra_opts,
                                    texfiles))
+
+               ly.lilypond_version_check (lilypond_binary, '@TOPLEVEL_VERSION@')
+               
                ly.system (cmd, ignore_error = 0, progress_p = 1)
 
                #
@@ -1304,12 +1403,13 @@ def compile_all_files (chunks):
                cmd = r"latex '\nonstopmode \input %s'" % file
                # Ugh.  (La)TeX writes progress and error messages on stdout
                # Redirect to stderr
-               cmd += ' 1>/dev/stderr'
+               cmd = '(( %s  >&2 ) >&- )' % cmd
+               
                ly.system (cmd)
                ly.system ("dvips -E -o %s.eps %s" % (file, file))
        map (to_eps, eps)
 
-       map (ly.make_preview, png)
+       map (ly.make_ps_images, map (lambda x: x + '.eps', png))
        os.chdir (d)
 
 
@@ -1340,29 +1440,20 @@ def write_deps (fn, target, chunks):
        f.write ('%s%s: ' % (g_dep_prefix, target))
        for d in read_files:
                f.write ('%s ' %  d)
-       basenames=[]
-        for c in chunks:
-               if c[0] == 'lilypond':
-                       (type, body, opts, todo, basename) = c;
-                       basenames.append (basename)
-       for d in basenames:
-               if g_outdir:
-                       d=g_outdir + '/' + d
-               if g_dep_prefix:
-                       #if not os.isfile (d): # thinko?
-                       if not re.search ('/', d):
-                               d = g_dep_prefix + d
-               f.write ('%s.tex ' %  d)
-       f.write ('\n')
-       #if len (basenames):
-       #       for d in basenames:
-       #               f.write ('%s.ly ' %  d)
-       #       f.write (' : %s' % target)
+
+
+       ## There used to be code to write .tex dependencies, but
+       ## that is silly: lilypond-book has its own dependency scheme
+       ## to ensure that all lily-XXX.tex files are there
+               
+
        f.write ('\n')
        f.close ()
        read_files = []
 
 def check_texidoc (chunks):
+       ## TODO: put file name in front of texidoc. 
+       ##
        n = []
         for c in chunks:
                if c[0] == 'lilypond':
@@ -1370,8 +1461,7 @@ def check_texidoc (chunks):
                        pathbase = os.path.join (g_outdir, basename)
                        if os.path.isfile (pathbase + '.texidoc') \
                           and 'notexidoc' not in opts:
-                               body = '\n@include %s.texidoc\n' % basename + body
-                               c = (type, body, opts, todo, basename)
+                               n.append( ('input', '\n@include %s.texidoc\n\n' % basename))
                n.append (c)
        return n
 
@@ -1416,9 +1506,7 @@ def do_file (input_filename):
        chunks = chop_chunks (chunks, 'preamble-end', do_preamble_end)
        chunks = chop_chunks (chunks, 'numcols', do_columns)
        chunks = chop_chunks (chunks, 'multicols', do_multicols)
-       #print "-" * 50
-       #for c in chunks: print "c:", c;
-       #sys.exit ()
+       
        scan_preamble (chunks)
        chunks = process_lilypond_blocks (chunks)
        chunks = process_ly2dvi_blocks (chunks)
@@ -1429,10 +1517,13 @@ def do_file (input_filename):
                compile_all_files (chunks)
                chunks = fix_epswidth (chunks)
 
+
+       chunks = format_lilypond_output_bodies (chunks)
        global format
        if format == 'texi':
                chunks = check_texidoc (chunks)
 
+
        x = 0
        chunks = completize_preamble (chunks)
 
@@ -1495,7 +1586,7 @@ for opt in options:
        elif o == '--outname' or o == '-o':
                if len (files) > 1:
                        #HACK
-                       sys.stderr.write ("Lilypond-book is confused by --outname on multiple files")
+                       sys.stderr.write ("lilypond-book is confused by --outname on multiple files")
                        sys.exit (1)
                outname = a
        elif o == '--help' or o == '-h':
@@ -1525,8 +1616,6 @@ for opt in options:
                g_do_pictures = 0
        elif o == '--no-music':
                g_do_music = 0
-       elif o == '--read-lys':
-               g_read_lys = 1
        elif o == '--outdir':
                g_outdir = a
        elif o == '--warranty' or o == '-w':
@@ -1550,6 +1639,7 @@ if not files:
 
 ly.setup_environment ()
 
+
 for input_filename in files:
        do_file (input_filename)