]> git.donarmstrong.com Git - lilypond.git/blobdiff - scripts/lilypond-book.py
''
[lilypond.git] / scripts / lilypond-book.py
index 7689f6d2ada77fd034c86ee8bda9c6752d0fc752..cbb84e7b84ef6843c0e7f15f564b0a2184771d57 100644 (file)
@@ -103,15 +103,17 @@ else:
 while datadir[-1] == os.sep:
        datadir= datadir[:-1]
 
-# Try to cater for bad installations of LilyPond, that have
-# broken TeX setup.  Just hope this doesn't hurt good TeX
-# setups.  Maybe we should check if kpsewhich can find
-# feta16.{afm,mf,tex,tfm}, and only set env upon failure.
+kpse = os.popen ('kpsexpand \$TEXMF').read()
+kpse = re.sub('[ \t\n]+$','', kpse)
+type1_paths = os.popen ('kpsewhich -expand-path=\$T1FONTS').read ()
+
 environment = {
-       'MFINPUTS' : datadir + '/mf:',
-       'TEXINPUTS': datadir + '/tex:' + datadir + '/ps:.:',
-       'TFMFONTS' : datadir + '/tfm:',
-       'GS_FONTPATH' : datadir + '/afm:' + datadir + '/pfa',
+       # TODO: * prevent multiple addition.
+       #       * clean TEXINPUTS, MFINPUTS, TFMFONTS,
+       #         as these take prevalence over $TEXMF
+       #         and thus may break tex run?
+       'TEXMF' : "{%s,%s}" % (datadir, kpse) ,
+       'GS_FONTPATH' : type1_paths,
        'GS_LIB' : datadir + '/ps',
 }
 
@@ -123,6 +125,10 @@ non_path_environment = {
 }
 
 def setup_environment ():
+       # $TEXMF is special, previous value is already taken care of
+       if os.environ.has_key ('TEXMF'):
+               del os.environ['TEXMF']
        for key in environment.keys ():
                val = environment[key]
                if os.environ.has_key (key):
@@ -567,9 +573,11 @@ def output_verbatim (body):
 
 #warning: this uses extended regular expressions. Tread with care.
 
-# legenda (?P  name parameter
-# *? match non-greedily.
+# legenda
 
+# (?P  -- name parameter
+# *? -- match non-greedily.
+# (?m)  -- ?  
 re_dict = {
        'html': {
                 'include':  no_match,
@@ -579,9 +587,9 @@ re_dict = {
                 'landscape': no_match,
                 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
                 'verb': r'''(?P<code><pre>.*?</pre>)''',
-                'lilypond-file': '(?m)(?P<match><lilypondfile(?P<options>[^>]*)?>\s*(?P<filename>.*?)\s*</lilypondfile>)',
+                'lilypond-file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
                 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
-                'lilypond-block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]*)?>(?P<code>.*?)</lilypond>)''',
+                'lilypond-block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
                  'option-sep' : '\s*',
                  'intertext': r',?\s*intertext=\".*?\"',
                  'multiline-comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
@@ -623,7 +631,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",
@@ -1244,7 +1252,8 @@ def compile_all_files (chunks):
                texfiles = string.join (tex, ' ')
                cmd = 'lilypond --header=texidoc %s %s %s' \
                      % (lilyopts, g_extra_opts, texfiles)
-               quiet_system (cmd, 'LilyPond')
+
+               system (cmd)
 
                #
                # Ugh, fixing up dependencies for .tex generation
@@ -1261,7 +1270,7 @@ def compile_all_files (chunks):
                                f.close ()
 
        for e in eps:
-               cmd = r"tex '\nonstopmode \input %s'" % e
+               cmd = r"echo $TEXMF; tex '\nonstopmode \input %s'" % e
                quiet_system (cmd, 'TeX')
                
                cmd = r"dvips -E -o %s %s" % (e + '.eps', e)
@@ -1450,15 +1459,6 @@ def fix_epswidth (chunks):
 ##docme: why global?
 foutn=""
 def do_file(input_filename):
-       global foutn
-       file_settings = {}
-       if outname:
-               my_outname = outname
-       elif input_filename == '-' or input_filename == "/dev/stdin":
-               my_outname = '-'
-       else:
-               my_outname = os.path.basename (os.path.splitext(input_filename)[0]) + '.' + format
-       my_depname = my_outname + '.dep'                
 
        chunks = read_doc_file(input_filename)
        chunks = chop_chunks(chunks, 'lilypond', make_lilypond, 1)
@@ -1483,6 +1483,18 @@ def do_file(input_filename):
 
        x = 0
        chunks = completize_preamble (chunks)
+
+
+       global foutn
+
+       if outname:
+               my_outname = outname
+       elif input_filename == '-' or input_filename == "/dev/stdin":
+               my_outname = '-'
+       else:
+               my_outname = os.path.basename (os.path.splitext(input_filename)[0]) + '.' + format
+       my_depname = my_outname + '.dep'                
+       
        if my_outname == '-' or my_outname == '/dev/stdout':
                fout = sys.stdout
                foutn = "<stdout>"