]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
release: 1.3.120
[lilypond.git] / scripts / lilypond-book.py
index 07de5b75bd5dd97b28ccaf84854ee8f5b79c6b51..bd0e3c822e6a64d1c6d1bc87f229c4581826ca3f 100644 (file)
@@ -4,8 +4,12 @@
 # * Figure out clean set of options. Hmm, isn't it pretty ok now?
 # * add support for .lilyrc
 # * EndLilyPondOutput is def'd as vfil. Causes large white gaps.
+# * texinfo: add support for @pagesize
 
-# todo: dimension handling (all the x2y) is clumsy. 
+# 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 was the idea for handling of comments:
 #      Multiline comments, @ignore .. @end ignore is scanned for
@@ -38,7 +42,7 @@ import operator
 
 program_version = '@TOPLEVEL_VERSION@'
 if program_version == '@' + 'TOPLEVEL_VERSION' + '@':
-       program_version = '1.3.106'     
+       program_version = '1.3.113'
 
 include_path = [os.getcwd()]
 
@@ -250,7 +254,7 @@ class LatexPaper:
 
 class TexiPaper:
        def __init__(self):
-               self.m_papersize = 'a4'
+               self.m_papersize = 'letterpaper'
                self.m_fontsize = 12
        def get_linewidth(self):
                return texi_linewidths[self.m_papersize][self.m_fontsize]
@@ -278,10 +282,11 @@ latex_linewidths = {
        'executivepaper':{10: 345, 11: 360, 12: 379}}
 
 texi_linewidths = {
-       'a4': {12: 455},
-       'a4wide': {12: 470},
-       'smallbook': {12: 361},
-       'texidefault': {12: 433}}
+       'afourpaper': {12: mm2pt(160)},
+       'afourwide': {12: in2pt(6.5)},
+       'afourlatex': {12: mm2pt(150)},
+       'smallbook': {12: in2pt(5)},
+       'letterpaper': {12: in2pt(6)}}
 
 option_definitions = [
   ('EXT', 'f', 'format', 'set format.  EXT is one of texi and latex.'),
@@ -342,7 +347,8 @@ output_dict= {
 
 # should also support fragment in
                  
-                 'output-all': r"""@tex
+                 'output-all': r"""
+@tex
 \catcode`\@=12
 \input lilyponddefs
 \def\EndLilyPondOutput{}
@@ -429,6 +435,8 @@ def get_re (name):
        return  re_dict[format][name]
 
 def bounding_box_dimensions(fname):
+       if g_outdir:
+               fname = os.path.join(g_outdir, fname)
        try:
                fd = open(fname)
        except IOError:
@@ -562,12 +570,10 @@ def scan_texi_preamble (chunks):
        idx = 0
        while 1:
                if chunks[idx][0] == 'input':
-                       if string.find(chunks[idx][1], "@afourpaper") != -1:
-                               paperguru.m_papersize = 'a4'
-                       elif string.find(chunks[idx][1], "@afourwide") != -1:
-                               paperguru.m_papersize = 'a4wide'
-                       elif string.find(chunks[idx][1], "@smallbook") != -1:
-                               paperguru.m_papersize = 'smallbook'
+                       for s in ('afourpaper', 'afourwide', 'letterpaper',
+                                 'afourlatex', 'smallbook'):
+                               if string.find(chunks[idx][1], "@%s" % s) != -1:
+                                       paperguru.m_papersize = s
                idx = idx + 1
                if idx == 10 or idx == len(chunks):
                        break
@@ -769,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
@@ -779,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:
@@ -799,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
@@ -865,7 +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))
+               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))
@@ -991,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:
@@ -1011,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)
@@ -1031,6 +1058,7 @@ def do_file(input_filename):
        for c in chunks:
                fout.write (c[1])
        fout.close ()
+       # should chmod -w
 
        if do_deps:
                write_deps (my_depname, foutn)