]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
release: 1.3.120
[lilypond.git] / scripts / lilypond-book.py
index 79f63be70c5dc3e7c06cddc710a9524769da05ec..bd0e3c822e6a64d1c6d1bc87f229c4581826ca3f 100644 (file)
@@ -348,7 +348,6 @@ output_dict= {
 # should also support fragment in
                  
                  'output-all': r"""
-@include %(fn)s-doc.texi
 @tex
 \catcode`\@=12
 \input lilyponddefs
@@ -776,7 +775,7 @@ def schedule_lilypond_block (chunk):
                needed_filetypes.append('png')
        if 'eps' in opts and not ('eps' in needed_filetypes):
                needed_filetypes.append('eps')
-       outname = os.path.join(g_outdir, basename)
+       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
@@ -786,11 +785,11 @@ def schedule_lilypond_block (chunk):
                                not os.path.isfile(base + ext2):
                        return 1
        todo = []
-       if 'tex' in needed_filetypes and f(outname, '.ly', '.tex'):
+       if 'tex' in needed_filetypes and f(pathbase, '.ly', '.tex'):
                todo.append('tex')
-       if 'eps' in needed_filetypes and f(outname, '.tex', '.eps'):
+       if 'eps' in needed_filetypes and f(pathbase, '.tex', '.eps'):
                todo.append('eps')
-       if 'png' in needed_filetypes and f(outname, '.eps', '.png'):
+       if 'png' in needed_filetypes and f(pathbase, '.eps', '.png'):
                todo.append('png')
        newbody = ''
        if 'verbatim' in opts:
@@ -806,8 +805,8 @@ def schedule_lilypond_block (chunk):
                else:
                        s = 'output-tex'
        else: # format == 'texi'
-               s = 'output-all'
-       newbody = newbody + get_output(s) % {'fn': basename }
+               s = 'output-all'
+       newbody = newbody + get_output (s) % {'fn': basename }
        return ('lilypond', newbody, opts, todo, basename)
 
 def process_lilypond_blocks(outname, chunks):#ugh rename
@@ -840,28 +839,6 @@ def system (cmd):
                error ('Error command exited with value %d\n' % st)
        return st
 
-
-texidoc_re = re.compile (r'.*?\n\s*texidoc\s*=\s*"((([^"])|([^\\]\\"))*)".*', re.DOTALL)
-def extract_texidoc (lyfile):
-       """
-       Extract the ``texidoc'' entry from the lyfile.ly, and write it to
-       lyfile-doc.texi.
-
-       Maybe this should be output by `lilypond --header=texidoc' or so?
-       """
-       outfile = os.path.basename (os.path.splitext (lyfile)[0]) + "-doc.texi"
-       sys.stderr.write ("Writing `%s'\n" % outfile)
-       f = open (lyfile)
-       s = f.read (-1)
-#      doc = re.sub (r'(.|\n)*?\n\s*texidoc\s*=\s*"((([^"])|([^\\]\\"))*)"(.|\n)*', '\\2', s) + '\n'
-       m = texidoc_re.match (s)
-       doc = ''
-       if m:
-               doc = m.group (1) + '\n'
-       f = open (outfile, 'w')
-       f.write (doc)
-       f.close ()
-
 def compile_all_files (chunks):
        eps = []
        tex = []
@@ -894,9 +871,7 @@ def compile_all_files (chunks):
                incs =  map (incl_opt, include_path)
                lilyopts = string.join (incs, ' ' )
                texfiles = string.join (tex, ' ')
-               system ('lilypond %s %s' % (lilyopts, texfiles))
-               for i in tex:
-                       extract_texidoc (i)
+               system ('lilypond --header=texidoc %s %s' % (lilyopts, texfiles))
        for e in eps:
                system(r"tex '\nonstopmode \input %s'" % e)
                system(r"dvips -E -o %s %s" % (e + '.eps', e))
@@ -1022,6 +997,30 @@ Distributed under terms of the GNU General Public License. It comes with
 NO WARRANTY.
 """)
 
+
+def check_texidoc (chunks):
+       n = []
+        for c in chunks:
+               if c[0] == 'lilypond':
+                       (type, body, opts, todo, basename) = c;
+                       pathbase = os.path.join (g_outdir, basename)
+                       if os.path.isfile (pathbase + '.texidoc'):
+                               body = '\n@include %s.texidoc' % basename + body
+                               c = (type, body, opts, todo, basename)
+               n.append (c)
+       return n
+
+def fix_epswidth (chunks):
+       newchunks = []
+       for c in chunks:
+               if c[0] == 'lilypond' and 'eps' in c[2]:
+                       body = re.sub (r"""\\lilypondepswidth{(.*?)}""", find_eps_dims, c[1])
+                       newchunks.append(('lilypond', body, c[2], c[3], c[4]))
+               else:
+                       newchunks.append (c)
+       return newchunks
+
+
 def do_file(input_filename):
        file_settings = {}
        if outname:
@@ -1042,18 +1041,15 @@ def do_file(input_filename):
        #sys.exit()
        scan_preamble(chunks)
        chunks = process_lilypond_blocks(my_outname, chunks)
+
        # Do It.
        if __main__.g_run_lilypond:
                compile_all_files (chunks)
-               newchunks = []
-               # finishing touch.
-               for c in chunks:
-                       if c[0] == 'lilypond' and 'eps' in c[2]:
-                               body = re.sub (r"""\\lilypondepswidth{(.*?)}""", find_eps_dims, c[1])
-                               newchunks.append (('lilypond', body))
-                       else:
-                               newchunks.append (c)
-               chunks = newchunks
+               chunks = fix_epswidth (chunks)
+
+       if __main__.format == 'texi':
+               chunks = check_texidoc (chunks)
+
        x = 0
        chunks = completize_preamble (chunks)
        foutn = os.path.join(g_outdir, my_outname + '.' + format)