#
# lilypond.py -- Run LilyPond, add titles to bare score, generate printable
# document
-# Invokes: lilypond, latex (or pdflatex), dvips, ps2pdf, gs
+# Invokes: lilypond-bin, latex (or pdflatex), dvips, ps2pdf, gs
#
# source file of the GNU LilyPond music typesetter
#
-# (c) 1998--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+# (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
# Jan Nieuwenhuizen <janneke@gnu.org>
# This is the third incarnation of ly2dvi, now renamed lilypond.
#
-# Earlier incarnations of ly2dvi were written by
+# Earlier incarnations of lilypond were written by
# Jeffrey B. Reed<daboys@austin.rr.com> (Python version)
# Jan Arne Fagertun <Jan.A.Fagertun@@energy.sintef.no> (Bourne shell script)
#
-# Note: gettext work best if we use ' for docstrings and "
+# Note: gettext work best if we use ' for program/docstrings and "
# for gettextable strings.
-# --> DO NOT USE ''' for docstrings.
+# USE ''' for docstrings.
'''
* Introduce verbosity levels
- 0 = QUIET: mute all command output, no ly2dvi progress
- 1 = BRIEF: mute all command output, only ly2dvi progress
- 2a = NORMAL: show only LilyPond command output, show ly2dvi progress
- 2b = NORMAL: show command output, show ly2dvi progress
+ 0 = QUIET: mute all command output, no lilypond progress
+ 1 = BRIEF: mute all command output, only lilypond progress
+ 2a = NORMAL: show only LilyPond command output, show lilypond progress
+ 2b = NORMAL: show command output, show lilypond progress
3 = VERBOSE: show command output, run lilypond --verbose
4 = DEBUGGING: show all command output, run lilypond --verbose, print
environment and all kinds of client side debugging stuff
debug_p = 0
## FIXME
-## ly2dvi: silly name?
## do -P or -p by default?
##help_summary = _ ("Run LilyPond using LaTeX for titling")
help_summary = _ ("Run LilyPond, add titles, generate printable document.")
_ ("write Makefile dependencies for every input file")),
('', 'h', 'help', _ ("print this help")),
('', '', 'debug', _ ("print even more output")),
+ (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
+ ('','', 'html', _("make HTML file with links to all output")),
(_ ("DIR"), 'I', 'include', _ ("add DIR to LilyPond's search path")),
('', 'k', 'keep',
_ ("keep all output, output to directory %s.dir") % program_name),
('', '', 'no-lily', _ ("don't run LilyPond")),
('', 'm', 'no-paper', _ ("produce MIDI output only")),
(_ ("FILE"), 'o', 'output', _ ("write output to FILE")),
- (_ ("FILE"), 'f', 'find-pfa', _ ("find pfa fonts used in FILE")),
(_ ('RES'), '', 'preview-resolution',
_ ("set the resolution of the preview to RES")),
+ ('', '', 'no-pdf', _ ("do not generate PDF output")),
+ ('', '', 'no-ps', _ ("do not generate PostScript outpug")),
+ ('', 'p', 'pdf', _ ("generate PDF output")),
('', 'P', 'postscript', _ ("generate PostScript output")),
- ('', '', 'png', _("generate PNG page images")),
- ('', '', 'psgz', _("generate PS.GZ")),
- # separate options for PDF / PS / DVI ?
('', '', 'pdftex', _ ("use pdflatex to generate a PDF output")),
- # FIXME: preview, picture; to indicate creation of a PNG?
+ ('', '', 'png', _("generate PNG page images")),
('', '', 'preview', _ ("make a picture of the first system")),
- ('','', 'html', _("make HTML file with links to all output")),
- (_ ("KEY=VAL"), 's', 'set', _ ("change global setting KEY to VAL")),
+ ('', '', 'psgz', _ ("generate PS.GZ")),
+ ('', 's', 'safe-mode', _ ("run in safe-mode")),
+ (_ ("KEY=VAL"), 'S', 'set', _ ("change global setting KEY to VAL")),
('', 'V', 'verbose', _ ("be verbose")),
('', 'v', 'version', _ ("print version number")),
('', 'w', 'warranty', _ ("show warranty and copyright")),
]
# other globals
+safe_mode_p = 0
preview_p = 0
page_images_p = 0
lilypond_error_p = 0
output_name = ''
-# Output formats that ly2dvi should create
+# Output formats that lilypond should create
targets = ['DVI', 'LATEX', 'MIDI', 'TEX', 'PDF', 'PS']
track_dependencies_p = 0
dict[key] = [val]
-def escape_path (x):
- return re.sub ('([ \n\t\\\\])', r'\\\1',x)
+def escape_shell (x):
+ return re.sub ("(\s|[`'\"\\\\])", r'\\\1',x)
+
def run_lilypond (files, dep_prefix):
def make_include_option (x):
- return '-I %s' % escape_path (x)
+ return '-I %s' % escape_shell (x)
opts = ''
opts = opts + ' ' + string.join (map (make_include_option, include_path))
if pdftex_p:
opts = opts + ' -f pdftex'
+ if safe_mode_p:
+ opts = opts + ' --safe-mode'
+
if track_dependencies_p:
opts = opts + " --dependencies"
if dep_prefix:
opts = opts + ' --dep-prefix=%s' % dep_prefix
- fs = string.join (map (escape_path, files))
+ fs = string.join (map (escape_shell, files))
global verbose_p
if verbose_p:
options = ''
-
if extra['latexoptions']:
options = options + ',' + extra['latexoptions'][-1]
s = s + '\\documentclass[%s]{article}\n' % options
- if extra['language']:
- s = s + r'\usepackage[%s]{babel}' % extra['language'][-1] + '\n'
+ if safe_mode_p:
+ s = s + '\\nofiles\n'
+ if extra['language']:
+ s = s + r'\usepackage[%s]{babel}' \
+ % extra['language'][-1] + '\n'
s = s + '\\usepackage{%s}\n' \
% string.join (extra['latexpackages'], ',')
linewidth = '597pt'
else:
linewidth = '%d%s' % (maxlw, unit)
- s = s + '\geometry{%swidth=%s%s,headheight=2mm,footskip=2mm,%s}\n' % (papersize, linewidth, textheight, orientation)
+ s = s + '\geometry{%swidth=%s%s,bottom=11mm,headsep=2mm,top=12mm,headheight=2mm,footskip=5mm,%s}\n' % (papersize, linewidth, textheight, orientation)
if 'twoside' in extra['latexoptions'] :
first = 0
- s = s + '\\thispagestyle{lastpage}\n'
+ s = s + '\n\\thispagestyle{lastpage}\n'
s = s + '\\end{document}'
return s
if preview_p:
for score in find_tex_files (files, extra):
preview_base = ly.strip_extension (score[0], '.tex')
- cmd = 'dvips -E -o%s %s' \
+ cmd = 'dvips -E -Ppdf -u+lilypond.map -o%s %s' \
% (preview_base + '.preview.ps',
preview_base + '.preview.dvi')
ly.system (cmd)
if name in os.listdir (d):
return os.path.join (d, name)
-# Added as functionality to ly2dvi, because ly2dvi may well need to do this
+# Added as functionality to lilypond, because lilypond may well need to do this
# in future too.
PS = '%!PS-Adobe'
def find_pfa_fonts (name):
elif o == '--include' or o == '-I':
include_path.append (a)
elif o == '--postscript' or o == '-P':
- targets.append ('PS')
+ if 'PDF' in targets:
+ targets.remove ('PDF')
+ if 'PS' not in targets:
+ targets.append ('PS')
+ elif o == '--pdf' or o == '-p':
+ if 'PDF' not in targets:
+ targets.append ('PDF')
+ elif o == '--no-pdf':
+ if 'PDF' in targets:
+ targets.remove ('PDF')
elif o == '--no-ps':
- targets.remove ('PS')
- targets.remove ('PDF')
+ if 'PS' in targets:
+ targets.remove ('PS')
+ if 'PDF' in targets:
+ targets.remove ('PDF')
elif o == '--keep' or o == '-k':
keep_temp_dir_p = 1
elif o == '--debug':
paper_p = 0
elif o == '--output' or o == '-o':
output_name = a
- elif o == '--set' or o == '-s':
+ elif o == '--safe-mode' or o == '-s':
+ safe_mode_p = 1
+ elif o == '--set' or o == '-S':
ss = string.split (a, '=')
set_setting (extra_init, ss[0], ss[1])
elif o == '--dependencies' or o == '-d':
sys.exit (0)
elif o == '--pdftex':
latex_cmd = 'pdflatex'
- targets.remove('DVI')
- targets.append('PDFTEX')
+ targets.remove ('DVI')
+ targets.append ('PDFTEX')
pdftex_p = 1
tex_extension = '.pdftex'
elif o == '--warranty' or o == '-w':
targets.append ('PNG')
elif o == '--psgz':
targets.append ('PS.GZ')
+ if 'PS' not in targets:
+ targets.append ('PS')
else:
unimplemented_option () # signal programming error
# As a neat trick, add directory part of first input file
# to include path. That way you can do without the clumsy -I in:
-# ly2dvi -I foe/bar/baz foo/bar/baz/baz.ly
+# lilypond -I foe/bar/baz foo/bar/baz/baz.ly
if files and files[0] != '-' and os.path.dirname (files[0]) != '.':
include_path.append (os.path.dirname (files[0]))
tmpdir = ly.setup_temp ()
ly.setup_environment ()
+ if safe_mode_p:
+ os.environ['openout_any'] = 'p'
# to be sure, add tmpdir *in front* of inclusion path.
#os.environ['TEXINPUTS'] = tmpdir + ':' + os.environ['TEXINPUTS']