if not self.m_use_geometry:
return latex_linewidths[self.m_papersize][self.m_fontsize]
else:
- geo_opts = (a == None, b == None, c == None)
-
+ geo_opts = (self.m_geo_lmargin == None,
+ self.m_geo_width == None,
+ self.m_geo_rmargin == None)
+
if geo_opts == (1, 1, 1):
if self.m_geo_textwidth:
return self.m_geo_textwidth
%s
}
>
-\end{lilypond}""",
- 'output-lilypond':r"""\begin[%s]{lilypond}
+\end{lilypond}""",
+ 'output-filename' : r'''
+
+\verb+%s+:''',
+ 'output-lilypond': r"""\begin[%s]{lilypond}
%s
\end{lilypond}""",
'output-verbatim': "\\begin{verbatim}%s\\end{verbatim}",
%s
@end lilypond
""",
+ 'output-filename' : r'''
+
+@file{%s}:''',
'output-lilypond-fragment': """@lilypond[%s]
\context Staff\context Voice{ %s }
@end lilypond """,
optstring = string.join (opts, ' ')
optstring = re.sub ('\n', ' ', optstring)
body = r"""
-%% Generated by lilypond-book.py; options are %s %%ughUGH not original options
+%% Generated automatically by: lilypond-book.py
+%% options are %s %%ughUGH not original options
\include "paper%d.ly"
\paper { linewidth = %f \pt; }
""" % (optstring, music_size, l) + body
read_files = []
def find_file (name):
"""
- Search the include path for NAME. If found, return the contents of teh file.
+ Search the include path for NAME. If found, return the (CONTENTS, PATH) of the file.
"""
+
f = None
+ nm = ''
for a in include_path:
try:
nm = os.path.join (a, name)
pass
if f:
sys.stderr.write ("Reading `%s'\n" % nm)
- return f.read ()
+ return (f.read (), nm)
else:
error ("File not found `%s'\n" % name)
- return ''
+ return ('', '')
def do_ignore(match_object):
return [('ignore', match_object.group('code'))]
(options, m.group('code')))]
def make_lilypond_file(m):
+ """
+
+ Find @lilypondfile{bla.ly} occurences and substitute bla.ly
+ into a @lilypond .. @end lilypond block.
+
+ """
+
if m.group('options'):
options = m.group('options')
else:
options = ''
+ (content, nm) = find_file(m.group('filename'))
+ options = "filename=%s," % nm + options
+
return [('input', get_output('output-lilypond') %
- (options, find_file(m.group('filename'))))]
+ (options, content))]
def make_lilypond_block(m):
if m.group('options'):
def read_doc_file (filename):
"""Read the input file, find verbatim chunks and do \input and \include
"""
- str = find_file(filename)
+ (str, path) = find_file(filename)
determine_format (str)
chunks = [('input', str)]
(type, body, opts) = chunk
assert type == 'lilypond'
file_body = compose_full_body (body, opts)
- basename = `abs(hash (file_body))`
+ basename = 'lily-' + `abs(hash (file_body))`
for o in opts:
m = re.search ('filename="(.*?)"', o)
if m:
if 'png' in needed_filetypes and f(pathbase, '.eps', '.png'):
todo.append('png')
newbody = ''
+
+ if 'printfilename' in opts:
+ for o in opts:
+ m= re.match ("filename=(.*)", o)
+ if m:
+ newbody = newbody + get_output ("output-filename") % m.group(1)
+ break
+
+
if 'verbatim' in opts:
newbody = output_verbatim (body)
return st
def compile_all_files (chunks):
+ global foutn
eps = []
tex = []
png = []
x = os.path.join (g_here_dir, x)
return ' -I %s' % x
- incs = map (incl_opt, include_path)
+ incs = map (incl_opt, include_path)
lilyopts = string.join (incs, ' ' )
+ if do_deps:
+ lilyopts = lilyopts + ' --dependencies '
+ if g_outdir:
+ lilyopts = lilyopts + '--dep-prefix=' + g_outdir + '/'
texfiles = string.join (tex, ' ')
system ('lilypond --header=texidoc %s %s' % (lilyopts, texfiles))
+
+ #
+ # Ugh, fixing up dependencies for .tex generation
+ #
+ if do_deps:
+ depfiles=map (lambda x: re.sub ('(.*)\.ly', '\\1.dep', x), tex)
+ for i in depfiles:
+ text=open (i).read ()
+ text=re.sub ('\n([^:\n]*):', '\n' + foutn + ':', text)
+ open (i, 'w').write (text)
+
for e in eps:
system(r"tex '\nonstopmode \input %s'" % e)
system(r"dvips -E -o %s %s" % (e + '.eps', e))
cmd = r"""gs -sDEVICE=pgm -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=- -r90 -dNOPAUSE %s -c quit | pnmcrop | pnmtopng > %s"""
cmd = cmd % (g + '.eps', g + '.png')
system (cmd)
- if g_outdir:
- os.chdir(d)
+ os.chdir (d)
def update_file (body, name):
sys.exit (0)
-def write_deps (fn, target):
- sys.stdout.write('writing `%s\'\n' % os.path.join(g_outdir, fn))
+def write_deps (fn, target, chunks):
+ global read_files
+ sys.stdout.write('Writing `%s\'\n' % os.path.join(g_outdir, fn))
f = open (os.path.join(g_outdir, fn), 'w')
f.write ('%s%s: ' % (g_dep_prefix, target))
- for d in __main__.read_files:
+ for d in read_files:
f.write ('%s ' % d)
+ basenames=[]
+ for c in chunks:
+ if c[0] == 'lilypond':
+ (type, body, opts, todo, basename) = c;
+ basenames.append (basename)
+ for d in basenames:
+ if g_outdir:
+ d=g_outdir + '/' + d
+ if g_dep_prefix:
+ #if not os.isfile (d): # thinko?
+ if not re.search ('/', d):
+ d = g_dep_prefix + d
+ f.write ('%s.tex ' % d)
+ f.write ('\n')
+ #if len (basenames):
+ # for d in basenames:
+ # f.write ('%s.ly ' % d)
+ # f.write (' : %s' % target)
f.write ('\n')
f.close ()
- __main__.read_files = []
+ read_files = []
def identify():
sys.stdout.write ('lilypond-book (GNU LilyPond) %s\n' % program_version)
(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
+ body = '\n@include %s.texidoc\n' % basename + body
c = (type, body, opts, todo, basename)
n.append (c)
return n
return newchunks
+foutn=""
def do_file(input_filename):
+ global foutn
file_settings = {}
if outname:
my_outname = outname
scan_preamble(chunks)
chunks = process_lilypond_blocks(my_outname, chunks)
+ foutn = os.path.join (g_outdir, my_outname + '.' + format)
+
# Do It.
if __main__.g_run_lilypond:
compile_all_files (chunks)
x = 0
chunks = completize_preamble (chunks)
- foutn = os.path.join(g_outdir, my_outname + '.' + format)
sys.stderr.write ("Writing `%s'\n" % foutn)
fout = open (foutn, 'w')
for c in chunks:
# should chmod -w
if do_deps:
- write_deps (my_depname, foutn)
+ write_deps (my_depname, foutn, chunks)
outname = ''