3 # ly2dvi.py -- Run LilyPond, add titles to bare score, generate printable
5 # Invokes: lilypond, latex (or pdflatex), dvips, ps2pdf, gs
7 # source file of the GNU LilyPond music typesetter
9 # (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 # Jan Nieuwenhuizen <janneke@gnu.org>
12 # This is the third incarnation of ly2dvi.
14 # Earlier incarnations of ly2dvi were written by
15 # Jeffrey B. Reed<daboys@austin.rr.com> (Python version)
16 # Jan Arne Fagertun <Jan.A.Fagertun@@energy.sintef.no> (Bourne shell script)
19 # Note: gettext work best if we use ' for docstrings and "
20 # for gettextable strings.
21 # --> DO NOT USE ''' for docstrings.
27 * figure out which set of command line options should make ly2dvi:
30 na: create latex only?
31 na: create tex and latex
32 default: create dvi only
33 na: create tex, latex and dvi
40 * for foo.ly, rename ly2dvi.dir to out-ly2dvi, foo.ly2dvi, foo.dir ?
42 * move versatile taglines,
45 beginfooter=\mutopiaPD
46 endfooter=\tagline -> 'lily was here <version>'
49 lilytagline (->lily was here), usertagline, copyright, lily-version
52 * head/header tagline/endfooter
54 * dvi from lilypond .tex output? This is hairy, because we create dvi
55 from lilypond .tex *and* header output.
57 * multiple \score blocks?
59 * Introduce verbosity levels
61 0 = QUIET: mute all command output, no ly2dvi progress
62 1 = BRIEF: mute all command output, only ly2dvi progress
63 2a = NORMAL: show only LilyPond command output, show ly2dvi progress
64 2b = NORMAL: show command output, show ly2dvi progress
65 3 = VERBOSE: show command output, run lilypond --verbose
66 4 = DEBUGGING: show all command output, run lilypond --verbose, print
67 environment and all kinds of client side debugging stuff
69 Currently, we only have 1 and 4, but we kludge to have 2a and 4.
78 ################################################################
79 # Users of python modules should include this snippet
80 # and customize variables below.
82 # We'll suffer this path init stuff as long as we don't install our
83 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
84 # it as we do with teTeX on Red Hat Linux: set some environment var
85 # (PYTHONPATH) in profile)
87 # If set, LILYPONDPREFIX must take prevalence
88 # if datadir is not set, we're doing a build and LILYPONDPREFIX
89 import getopt
, os
, sys
90 datadir
= '@local_lilypond_datadir@'
91 if not os
.path
.isdir (datadir
):
92 datadir
= '@lilypond_datadir@'
93 if os
.environ
.has_key ('LILYPONDPREFIX') :
94 datadir
= os
.environ
['LILYPONDPREFIX']
95 while datadir
[-1] == os
.sep
:
98 sys
.path
.insert (0, os
.path
.join (datadir
, 'python'))
101 #if __name__ == '__main__':
108 program_name
= 'ly2dvi'
111 original_dir
= os
.getcwd ()
112 temp_dir
= os
.path
.join (original_dir
, '%s.dir' % program_name
)
114 preview_resolution
= 90
118 ## ly2dvi: silly name?
119 ## do -P or -p by default?
120 ##help_summary = _ ("Run LilyPond using LaTeX for titling")
121 help_summary
= _ ("Run LilyPond, add titles, generate printable document")
122 copyright
= ('Han-Wen Nienhuys <hanwen@cs.uu.nl',
123 'Jan Nieuwenhuizen <janneke@gnu.org')
125 option_definitions
= [
126 ('', 'd', 'dependencies',
127 _ ("write Makefile dependencies for every input file")),
128 ('', 'h', 'help', _ ("this help")),
129 ('', '', 'debug', _ ("print even more output")),
130 (_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")),
132 _ ("keep all output, output to directory %s.dir") % program_name
),
133 ('', '', 'no-lily', _ ("don't run LilyPond")),
134 ('', 'm', 'no-paper', _ ("produce MIDI output only")),
135 (_ ("FILE"), 'o', 'output', _ ("write ouput to FILE")),
136 (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
137 (_ ('RES'), '', 'preview-resolution',
138 _ ("set the resolution of the preview to RES")),
139 ('', 'P', 'postscript', _ ("generate PostScript output")),
140 ('', '', 'png', _("generate PNG page images")),
141 ('', '', 'psgz', _("generate PS.GZ")),
142 ('', 'p', 'pdf', _ ("generate PDF output")),
143 ('', '', 'pdftex', _ ("use pdflatex to generate a PDF output")),
144 # FIXME: preview, picture; to indicate creation of a PNG?
145 ('', '', 'preview', _ ("make a picture of the first system")),
146 ('','', 'html', _("make HTML file with links to all output")),
147 (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")),
148 ('', 'V', 'verbose', _ ("verbose")),
149 ('', 'v', 'version', _ ("print version number")),
150 ('', 'w', 'warranty', _ ("show warranty and copyright")),
164 tex_extension
= '.tex' ## yuk.
166 #lilypond_binary = 'valgrind --suppressions=%(home)s/usr/src/guile-1.6.supp --num-callers=10 %(home)s/usr/src/lilypond/lily/out/lilypond '% { 'home' : '/home/hanwen' }
168 lilypond_binary
= os
.path
.join ('@bindir@', 'lilypond')
170 # only use installed binary when we're installed too.
171 if '@bindir@' == ('@' + 'bindir@') or not os
.path
.exists (lilypond_binary
):
172 lilypond_binary
= 'lilypond'
175 layout_fields
= ['dedication', 'title', 'subtitle', 'subsubtitle',
176 'footer', 'head', 'composer', 'arranger', 'instrument',
177 'opus', 'piece', 'metre', 'meter', 'poet', 'texttranslator']
180 # init to empty; values here take precedence over values in the file
182 ## TODO: change name.
186 'latexpackages' : ['geometry'],
189 'latexoptions' : ['compat2'],
199 extra_fields
= extra_init
.keys ()
200 fields
= layout_fields
+ extra_fields
208 # Output formats that ly2dvi should create
209 targets
= ['DVI', 'LATEX', 'MIDI', 'TEX']
211 track_dependencies_p
= 0
212 dependency_files
= []
215 def set_setting (dict, key
, val
):
217 val
= string
.atoi (val
)
219 #ly.warning (_ ("invalid value: %s") % `val`)
222 if type(val
) == type ('hoi'):
224 val
= string
.atof (val
)
226 #ly.warning (_ ("invalid value: %s") % `val`)
230 dict[key
].append (val
)
232 ly
.warning (_ ("no such setting: `%s'") % `key`
)
236 def run_lilypond (files
, dep_prefix
):
239 opts
= opts
+ ' ' + string
.join (map (lambda x
: '-I ' + x
,
242 opts
= opts
+ ' --output=lelie'
244 opts
= opts
+ ' ' + string
.join (map (lambda x
: '-H ' + x
,
247 opts
= opts
+ ' --no-paper'
250 opts
= opts
+ ' -f pdftex'
252 if track_dependencies_p
:
253 opts
= opts
+ " --dependencies"
255 opts
= opts
+ ' --dep-prefix=%s' % dep_prefix
257 fs
= string
.join (files
)
261 opts
= opts
+ ' --verbose'
264 ly
.print_environment ()
266 cmd
= string
.join ((lilypond_binary
, opts
, fs
))
267 status
= ly
.system (cmd
, ignore_error
= 1, progress_p
= 1)
268 signal
= 0x0f & status
269 exit_status
= status
>> 8
271 # 2 == user interrupt.
272 if signal
and signal
!= 2:
273 sys
.stderr
.write ('\n\n')
274 ly
.error (_ ("LilyPond crashed (signal %d).") % signal
)
275 ly
.error (_ ("Please submit a bug report to bug-lilypond@gnu.org"))
279 sys
.stderr
.write ('\n')
281 ly
.error (_ ("LilyPond failed on input file %s (exit status %d)") % (files
[0], exit_status
))
284 ly
.error (_ ("LilyPond failed on an input file (exit status %d)") % exit_status
)
285 ly
.error (_ ("Continuing..."))
286 global lilypond_error_p
290 def analyse_lilypond_output (filename
, extra
):
293 '''Grep FILENAME for interesting stuff, and
294 put relevant info into EXTRA.'''
295 filename
= filename
+ tex_extension
296 ly
.progress (_ ("Analyzing %s...") % filename
)
297 s
= open (filename
).read ()
299 # search only the first 10k
301 for x
in extra_fields
:
302 m
= re
.search (r
'\\def\\lilypondpaper%s{([^}]*)}'%x, s
)
304 set_setting (extra
, x
, m
.group (1))
307 def find_tex_files_for_base (base
, extra
):
309 Find the \header fields dumped from BASE.
313 for f
in layout_fields
:
315 if os
.path
.exists (fn
):
318 if os
.path
.exists (base
+'.dep'):
319 dependency_files
.append (base
+ '.dep')
321 for f
in extra_fields
:
323 if os
.path
.exists (fn
):
324 extra
[f
].append (open (fn
).read ())
326 return (base
+ tex_extension
, headerfiles
)
329 def find_tex_files (files
, extra
):
331 Find all .tex files whose prefixes start with some name in FILES.
340 fname
= os
.path
.basename (f
)
341 fname
= ly
.strip_extension (fname
, '.ly')
343 fname
= fname
+ '-%d' % x
345 if os
.path
.exists (fname
+ tex_extension
):
346 tfiles
.append (find_tex_files_for_base (fname
, extra
))
347 analyse_lilypond_output (fname
, extra
)
353 fstr
= string
.join (files
, ', ')
354 ly
.warning (_ ("no LilyPond output found for `%s'") % fstr
)
357 def one_latex_definition (defn
, first
):
359 for (k
,v
) in defn
[1].items ():
360 val
= open (v
).read ()
361 if (string
.strip (val
)):
362 s
= s
+ r
'''\def\lilypond%s{%s}''' % (k
, val
)
364 s
= s
+ r
'''\let\lilypond%s\relax''' % k
368 s
= s
+ '\\def\\mustmakelilypondtitle{}\n'
370 s
= s
+ '\\def\\mustmakelilypondpiecetitle{}\n'
372 s
= s
+ '\\input %s\n' % defn
[0] # The final \n seems important here. It ensures that the footers and taglines end up on the right page.
376 ly_paper_to_latexpaper
= {
377 'letter' : 'letterpaper',
384 #TODO: should set textheight (enlarge) depending on papersize.
385 def global_latex_preamble (extra
):
386 '''construct preamble from EXTRA,'''
388 s
= s
+ '% generation tag\n'
393 if extra
['papersize']:
395 options
= ly_paper_to_latexpaper
[extra
['papersize'][0]]
397 ly
.warning (_ ("invalid value: `%s'") % `extra
['papersize'][0]`
)
400 if extra
['latexoptions']:
401 options
= options
+ ',' + extra
['latexoptions'][-1]
403 s
= s
+ '\\documentclass[%s]{article}\n' % options
405 if extra
['language']:
406 s
= s
+ r
'\usepackage[%s]{babel}' % extra
['language'][-1] + '\n'
409 s
= s
+ '\\usepackage{%s}\n' \
410 % string
.join (extra
['latexpackages'], ',')
412 if extra
['latexheaders']:
413 s
= s
+ '\\include{%s}\n' \
414 % string
.join (extra
['latexheaders'], '}\n\\include{')
416 unit
= extra
['unit'][-1]
419 if extra
['textheight']:
420 textheight
= ',textheight=%f%s' % (extra
['textheight'][0], unit
)
422 orientation
= 'portrait'
423 if extra
['orientation']:
424 orientation
= extra
['orientation'][0]
426 # set sane geometry width (a4-width) for linewidth = -1.
427 maxlw
= max (extra
['linewidth'] + [-1])
429 # who the hell is 597 ?
432 linewidth
= '%d%s' % (maxlw
, unit
)
433 s
= s
+ '\geometry{width=%s%s,headheight=2mm,footskip=2mm,%s}\n' % (linewidth
, textheight
, orientation
)
435 if extra
['latexoptions']:
436 s
= s
+ '\geometry{twosideshift=4mm}\n'
439 \usepackage[latin1]{inputenc}
443 if extra
['pagenumber'] and extra
['pagenumber'][-1] and extra
['pagenumber'][-1] != 'no':
444 s
= s
+ '\setcounter{page}{%d}\n' % (extra
['pagenumber'][-1])
445 s
= s
+ '\\pagestyle{plain}\n'
447 s
= s
+ '\\pagestyle{empty}\n'
453 def global_latex_definition (tfiles
, extra
):
454 '''construct preamble from EXTRA, dump Latex stuff for each
455 lily output file in TFILES after that, and return the Latex file constructed. '''
458 s
= global_latex_preamble (extra
) + '\\begin{document}\n'
459 s
= s
+ '\\parindent 0pt\n'
460 s
= s
+ '\\thispagestyle{firstpage}\n'
464 s
= s
+ one_latex_definition (t
, first
)
468 s
= s
+ '\\thispagestyle{lastpage}\n'
469 s
= s
+ '\\end{document}'
473 def run_latex (files
, outbase
, extra
):
475 '''Construct latex file, for FILES and EXTRA, dump it into
476 OUTBASE.latex. Run LaTeX on it.
483 latex_fn
= outbase
+ '.latex'
485 wfs
= find_tex_files (files
, extra
)
486 s
= global_latex_definition (wfs
, extra
)
488 f
= open (latex_fn
, 'w')
492 cmd
= latex_cmd
+ ' \\\\nonstopmode \\\\input %s' % latex_fn
493 # Ugh. (La)TeX writes progress and error messages on stdout
495 cmd
+= ' 1>/dev/stderr'
496 status
= ly
.system (cmd
, ignore_error
= 1)
497 signal
= 0xf & status
498 exit_status
= status
>> 8
504 logstr
= open (outbase
+ '.log').read ()
505 m
= re
.search ("\n!", logstr
)
507 logstr
= logstr
[start
:start
+200]
511 ly
.error (_ ("LaTeX failed on the output file."))
512 ly
.error (_ ("The error log is as follows:"))
513 sys
.stderr
.write (logstr
+ '\n')
517 # make a preview by rendering only the 1st line
519 for score
in find_tex_files (files
, extra
):
520 preview_base
= ly
.strip_extension (score
[0], '.tex')
521 preview_fn
= preview_base
+ '.preview.tex'
522 s
= global_latex_definition ((score
,), extra
)
523 s
= re
.sub ('thispagestyle{firstpage}',
524 r
'''thispagestyle{empty}%
525 \\def\\interscoreline{\\endinput}''', s
)
526 s
= re
.sub ('thispagestyle{lastpage}',
527 r
'''thispagestyle{empty}%
528 \\def\\interscoreline{\\endinput}''', s
)
529 f
= open (preview_fn
, 'w')
532 cmd
= '%s \\\\nonstopmode \\\\input %s' \
533 % (latex_cmd
, preview_fn
)
537 def run_dvips (outbase
, extra
):
540 '''Run dvips using the correct options taken from EXTRA,
541 leaving a PS file in OUTBASE.ps
548 if extra
['papersize']:
549 opts
= opts
+ ' -t%s' % extra
['papersize'][0]
551 if extra
['orientation'] and extra
['orientation'][0] == 'landscape':
552 opts
= opts
+ ' -tlandscape'
556 where
= ly
.read_pipe ('kpsewhich feta20.pfa').strip()
561 pfa_file
= open (where
, 'r')
566 opts
= opts
+ ' -Ppdf -G0 -u +lilypond.map'
568 ly
.warning (_ ('''Trying create PDF, but no PFA fonts found.
569 Using bitmap fonts instead. This will look bad.'''))
571 cmd
= 'dvips %s -o%s %s' % (opts
, outbase
+ '.ps', outbase
+ '.dvi')
575 for score
in find_tex_files (files
, extra
):
576 preview_base
= ly
.strip_extension (score
[0], '.tex')
577 cmd
= 'dvips -E -o%s %s' \
578 % (preview_base
+ '.preview.ps',
579 preview_base
+ '.preview.dvi')
583 cmd
= 'ps2pdf %s.ps %s.pdf' % (outbase
, outbase
)
586 def generate_dependency_file (depfile
, outname
):
587 df
= open (depfile
, 'w')
588 df
.write (outname
+ ':' )
590 for d
in dependency_files
:
592 s
= re
.sub ('#[^\n]*\n', '', s
)
593 s
= re
.sub (r
'\\\n', ' ', s
)
594 m
= re
.search ('.*:(.*)\n', s
)
596 # ugh. Different targets?
598 df
.write ( m
.group (1) + ' ' )
603 def find_file_in_path (path
, name
):
604 for d
in string
.split (path
, os
.pathsep
):
605 if name
in os
.listdir (d
):
606 return os
.path
.join (d
, name
)
608 # Added as functionality to ly2dvi, because ly2dvi may well need to do this
611 def find_pfa_fonts (name
):
612 s
= open (name
).read ()
613 if s
[:len (PS
)] != PS
:
615 ly
.error (_ ("not a PostScript file: `%s\'" % name
))
618 m
= re
.match ('.*?/(feta[-a-z0-9]+) +findfont', s
[here
:], re
.DOTALL
)
622 pfa
.append (m
.group (1))
623 m
= re
.match ('.*?/(feta[-a-z0-9]+) +findfont', s
[here
:], re
.DOTALL
)
627 def make_html_menu_file (html_file
, files_found
):
629 'pdf' : "Print (PDF, %s)",
630 'ps.gz' : "Print (gzipped PostScript, %s)",
631 'png' : "View (PNG, %s)",
632 'midi' : "Listen (MIDI, %s)",
633 'ly' : "View source code (%s)",
637 pages
= filter (lambda x
: re
.search ('page[0-9]+.png', x
),
639 rest
= filter (lambda x
: not re
.search ('page[0-9]+.png', x
),
642 preview
= filter (lambda x
: re
.search ('.png$', x
), rest
)
644 html_str
= '<img src="%s">' % preview
[0]
647 page
= re
.sub ('.*page([0-9])+.*', 'View page \\1 (PNG picture, %s)\n', p
)
648 page
= page
% 'unknown size'
650 html_str
+= '<li><a href="%s">%s</a>' % (p
, page
)
653 for e
in ['pdf', 'ps.gz', 'midi', 'ly']:
654 fs
= filter (lambda x
: re
.search ('.%s$' % e
, x
), rest
)
656 entry
= exts
[e
] % 'unknown size' # todo
657 html_str
+= '<li><a href="%s">%s</a>\n\n' % (f
, entry
)
659 html_str
+= "\n\n</li>"
660 ly
.progress (_("Writing HTML menu `%s'") % html_file
)
662 open (html_file
, 'w').write (html_str
)
664 ################################################################
666 ################################################################
668 (sh
, long) = ly
.getopt_args (option_definitions
)
670 (options
, files
) = getopt
.getopt (sys
.argv
[1:], sh
, long)
671 except getopt
.error
, s
:
672 sys
.stderr
.write ('\n')
673 ly
.error (_ ("getopt says: `%s\'" % s
))
674 sys
.stderr
.write ('\n')
684 elif o
== '--help' or o
== '-h':
687 elif o
== '--find-pfa' or o
== '-f':
688 fonts
= map (lambda x
: x
+ '.pfa', find_pfa_fonts (a
))
689 files
= map (lambda x
:
690 find_file_in_path (os
.environ
['GS_FONTPATH'], x
),
692 print string
.join (files
, ' ')
694 elif o
== '--include' or o
== '-I':
695 include_path
.append (a
)
696 elif o
== '--postscript' or o
== '-P':
697 targets
.append ('PS')
698 elif o
== '--pdf' or o
== '-p':
699 targets
.append ('PS')
700 targets
.append ('PDF')
701 elif o
== '--keep' or o
== '-k':
706 elif o
== '--no-lily':
708 elif o
== '--preview':
710 if 'PNG' not in targets
:
711 targets
.append ('PNG')
712 elif o
== '--preview-resolution':
713 preview_resolution
= string
.atoi (a
)
714 elif o
== '--no-paper' or o
== '-m':
717 elif o
== '--output' or o
== '-o':
719 elif o
== '--set' or o
== '-s':
720 ss
= string
.split (a
, '=')
721 set_setting (extra_init
, ss
[0], ss
[1])
722 elif o
== '--dependencies' or o
== '-d':
723 track_dependencies_p
= 1
724 elif o
== '--verbose' or o
== '-V':
726 elif o
== '--version' or o
== '-v':
727 ly
.identify (sys
.stdout
)
729 elif o
== '--pdftex':
730 latex_cmd
= 'pdflatex'
731 targets
.remove('DVI')
732 targets
.append('PDFTEX')
734 tex_extension
= '.pdftex'
735 elif o
== '--warranty' or o
== '-w':
736 status
= os
.system ('%s -w' % lilypond_binary
)
744 if 'PNG' not in targets
:
745 targets
.append ('PNG')
747 targets
.append ('PS.GZ')
749 unimplemented_option () # signal programming error
751 # Don't convert input files to abspath, rather prepend '.' to include
753 include_path
.insert (0, '.')
755 # As a neat trick, add directory part of first input file
756 # to include path. That way you can do without the clumsy -I in:
758 # ly2dvi -I foe/bar/baz foo/bar/baz/baz.ly
759 if files
and files
[0] != '-' and os
.path
.dirname (files
[0]) != '.':
760 include_path
.append (os
.path
.dirname (files
[0]))
762 include_path
= map (ly
.abspath
, include_path
)
764 if files
and (files
[0] == '-' or output_name
== '-'):
767 output_name
= 'lelie'
769 ly
.progress (_ ("pseudo filter") + '\n')
772 ly
.error (_ ("pseudo filter only for single input file"))
777 ly
.error (_ ("no files specified on command line"))
781 ly
.identify (sys
.stderr
)
782 original_output
= output_name
784 # Ugh, maybe make a setup () function
785 files
= map (lambda x
: ly
.strip_extension (x
, '.ly'), files
)
787 # hmmm. Wish I'd 've written comments when I wrote this.
788 # now it looks complicated.
790 (outdir
, outbase
) = ('','')
792 outbase
= os
.path
.basename (files
[0])
793 outdir
= ly
.abspath ('.')
794 elif output_name
[-1] == os
.sep
:
795 outdir
= ly
.abspath (output_name
)
796 outbase
= os
.path
.basename (files
[0])
798 (outdir
, outbase
) = os
.path
.split (ly
.abspath (output_name
))
800 for i
in ('.dvi', '.latex', '.ly', '.ps', '.tex', '.pdftex'):
801 output_name
= ly
.strip_extension (output_name
, i
)
802 outbase
= ly
.strip_extension (outbase
, i
)
804 for i
in files
[:] + [output_name
]:
805 if string
.find (i
, ' ') >= 0:
806 ly
.error (_ ("filename should not contain spaces: `%s'") %
810 if os
.path
.dirname (output_name
) != '.':
811 dep_prefix
= os
.path
.dirname (output_name
)
815 reldir
= os
.path
.dirname (output_name
)
816 if outdir
!= '.' and (track_dependencies_p
or targets
):
817 ly
.mkdir_p (outdir
, 0777)
819 tmpdir
= ly
.setup_temp ()
820 ly
.setup_environment ()
822 # to be sure, add tmpdir *in front* of inclusion path.
823 #os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS']
826 # We catch all exceptions, because we need to do stuff at exit:
827 # * copy any successfully generated stuff from tempdir and
828 # notify user of that
832 run_lilypond (files
, dep_prefix
)
834 ### ARGH. This also catches python programming errors.
835 ### this should only catch lilypond nonzero exit status
839 # TODO: friendly message about LilyPond setup/failing?
843 traceback
.print_exc ()
845 ly
.warning (_("Running LilyPond failed. Rerun with --verbose for a trace."))
847 # Our LilyPond pseudo filter always outputs to 'lelie'
848 # have subsequent stages and use 'lelie' output.
852 if 'PS.GZ' in targets
:
853 targets
.append ('PS')
855 if 'PNG' in targets
and 'PS' not in targets
:
856 targets
.append ('PS')
857 if 'PS' in targets
and 'DVI' not in targets
:
858 targets
.append('DVI')
862 run_latex (files
, outbase
, extra_init
)
863 # unless: add --tex, or --latex?
864 targets
.remove ('TEX')
865 targets
.remove('LATEX')
867 # TODO: friendly message about TeX/LaTeX setup,
868 # trying to run tex/latex by hand
870 targets
.remove ('DVI')
872 targets
.remove ('PS')
874 traceback
.print_exc ()
878 run_dvips (outbase
, extra_init
)
882 targets
.remove ('PS')
884 traceback
.print_exc ()
886 ly
.warning (_("Failed to make PS file. Rerun with --verbose for a trace."))
889 for score
in find_tex_files (files
, extra_init
):
890 preview_base
= ly
.strip_extension (score
[0], '.tex')
891 ly
.make_ps_images (preview_base
+ '.preview.ps',
892 resolution
=preview_resolution
895 if 'PDFTEX' in targets
:
897 run_latex (files
, outbase
, extra_init
)
898 # unless: add --tex, or --latex?
899 targets
.remove ('TEX')
900 targets
.remove ('LATEX')
901 targets
.remove ('PDFTEX')
902 if 'PDF' not in targets
:
903 targets
.append('PDF')
905 # TODO: friendly message about TeX/LaTeX setup,
906 # trying to run tex/latex by hand
907 if 'PDFTEX' in targets
:
908 targets
.remove ('PDFTEX')
910 targets
.remove ('PDF')
912 targets
.remove ('PS')
914 traceback
.print_exc ()
916 ly
.warning (_("Running LaTeX falied. Rerun with --verbose for a trace."))
919 ly
.make_ps_images (outbase
+ '.ps' )
921 # add DEP to targets?
922 if track_dependencies_p
:
923 depfile
= os
.path
.join (outdir
, outbase
+ '.dep')
924 generate_dependency_file (depfile
, depfile
)
925 if os
.path
.isfile (depfile
):
926 ly
.progress (_ ("dependencies output to `%s'...") %
932 for i
in 'PDF', 'PS', 'PNG', 'DVI', 'LATEX':
937 ly
.progress (_ ("%s output to <stdout>...") % i
)
938 outname
= outbase
+ '.' + string
.lower (main_target
)
939 if os
.path
.isfile (outname
):
940 sys
.stdout
.write (open (outname
).read ())
942 ly
.warning (_ ("can't find file: `%s'") % outname
)
946 if 'PS.GZ' in targets
:
947 ly
.system ("gzip *.ps")
948 targets
.remove ('PS')
950 # Hmm, if this were a function, we could call it the except: clauses
953 ext
= string
.lower (i
)
955 pattern
= '%s.%s' % (outbase
, ext
)
958 ls
= glob
.glob (pattern
)
960 ly
.cp_to_dir ('.*\.%s$' % ext
, outdir
)
964 names
= string
.join (map (lambda x
: "`%s'" % x
, ls
))
965 ly
.progress (_ ("%s output to %s...") % (i
, names
))
968 ly
.warning (_ ("can't find file: `%s'") % outname
)
971 make_html_menu_file (os
.path
.join (outdir
, outbase
+ ".html"),
974 os
.chdir (original_dir
)
977 sys
.exit (lilypond_error_p
)