cwd = os.getcwd ()
include_path = [cwd]
-# TODO: use splitting iso. \mudelagraphic.
+# TODO: Figure out clean set of options.
+# BUG: does not handle \verb|\begin{verbatim}\end{verbatim}| correctly.
+# Should make a joint RE for \verb and \begin, \end{verbatim}
#
+
default_music_fontsize = 16
default_text_fontsize = 12
%s
@end example
""",
+
+# do some tweaking: @ is needed in some ps stuff.
+# override EndLilyPondOutput, since @tex is done
+# in a sandbox, you can't do \input lilyponddefs at the
+# top of the document.
'output-all': r"""@tex
+\catcode`\@=12
+\input lilyponddefs
+\def\EndLilyPondOutput{}
\input %s.tex
+\catcode`\@=0
@end tex
@html
<img src=%s.png>
}
}
+def output_verbatim (body):
+ if __main__.format == 'texi':
+ body = re.sub ('([@{}])', '@\\1', body)
+ return get_output ('output-verbatim') % body
+
re_dict = {
'latex': {'input': '\\\\input{?([^}\t \n}]*)',
'include': '\\\\include{([^}]+)}',
re_dict[r] = newdict
+def uniq (list):
+ list.sort ()
+ s = list
+ list = []
+ for x in s:
+ if x not in list:
+ list.append (x)
+ return list
+
+
def get_output (name):
return output_dict[format][name]
if 'twocolumn' in opts:
cols = 2
- if 'fragment' or 'singleline' in opts:
- l = -1.0;
- else:
- l = latex_linewidths[cols][paper][latex_size]
# urg: breaks on \include of full score
# Use nofly option if you want to \include full score.
if not 'nofly' in opts and not re.search ('\\\\score', body):
opts.append ('fly')
+ if 'fragment' in opts or 'singleline' in opts:
+ l = -1.0;
+ else:
+ l = latex_linewidths[cols][paper][latex_size]
+
+
if 'fly' in opts:
body = r"""\score {
\notes\relative c {
\paper { }
}""" % body
+ opts = uniq (opts)
+ optstring = string.join (opts, ' ')
+ optstring = re.sub ('\n', ' ', optstring)
body = r"""
-%% Generated by mudela-book.py
+%% Generated by mudela-book.py; options are %s
\include "paper%d.ly"
\paper { linewidth = %f \pt; }
-""" % (music_size, l) + body
+""" % (optstring, music_size, l) + body
return body
-def inclusion_func (match, surround):
- insert = match.group (0)
- try:
- (insert, d) = read_doc_file (match.group(1))
- deps = deps + d
- insert = surround + insert + surround
- except:
- sys.stderr.write("warning: can't find %s, let's hope latex will\n" % m.group(1))
-
- return (insert, deps)
-
def find_inclusion_chunks (regex, surround, str):
chunks = []
while str:
def read_doc_file (filename):
"""Read the input file, substituting for \input, \include, \mudela{} and \mudelafile"""
str = ''
- for fn in [filename, filename+'.tex', filename+'.doc']:
+ for ext in ['', '.tex', '.doc', '.tely']:
try:
- f = open(fn)
+ f = open(filename+ ext)
str = f.read (-1)
except:
pass
if not str:
- raise IOError
+ error ("File not found `%s'\n" % filename)
retdeps = [filename]
else:
__main__.format = 'latex'
- chunks = find_verbatim_chunks (str)
- newchunks = []
+ chunks = [('input', str)]
- for func in (find_include_chunks, find_input_chunks):
+ for func in (find_verbatim_chunks, find_verb_chunks, find_include_chunks, find_input_chunks):
+ newchunks = []
for c in chunks:
if c[0] == 'input':
ch = func (c[1])
newchunks = newchunks + ch
else:
newchunks.append (c)
-
+ chunks = newchunks
return chunks
(TYPE_STR, CONTENT_STR), where TYPE_STR is one of 'input' and 'verbatim'
"""
-
chunks = []
-
while str:
m = get_re ('verbatim').search( str)
- m2 = get_re ("verb").search( str)
+ if m == None:
+ chunks.append( ('input', str))
+ str = ''
+ else:
+ chunks.append (('input', str[:m.start (0)]))
+ chunks.append (('verbatim', m.group (0)))
+
+ str = str [m.end(0):]
+
+ return chunks
- if m == None and m2 == None:
+def find_verb_chunks (str):
+
+ chunks = []
+ while str:
+ m = get_re ("verb").search(str)
+ if m == None:
chunks.append (('input', str))
str = ''
- break
-
- if m == None:
- m = m2
+ else:
+ chunks.append (('input', str[:m.start (0)]))
+ chunks.append (('verbatim', m.group (0)))
+ str = str [m.end(0):]
- if m2 and m2.start (0) < m.start (0):
- m = m2
+ return chunks
- chunks.append (('input', str[:m.start (0)]))
- chunks.append (('verbatim', m.group (0)))
-
- str = str [m.end(0):]
- return chunks
def find_mudela_shorthand_chunks (str):
def schedule_mudela_block (base, chunk, extra_opts):
-
"""Take the body and options from CHUNK, figure out how the
real .ly should look, and what should be left MAIN_STR (meant
for the main file). The .ly is written, and scheduled in
newbody = ''
if 'verbatim' in opts:
- verbatim_mangle = body
- if __main__.format == 'texi':
- verbatim_mangle = re.sub ('([{}])', '@\\1', body)
- newbody = get_output ('output-verbatim') % verbatim_mangle
+ newbody = output_verbatim (body)
file_body = compose_full_body (body, opts)
updated = update_file (file_body, base + '.ly')
newchunks.append (('mudela', body))
else:
newchunks.append (c)
-
-
- chunks = newchunks
+ chunks = newchunks
+
if chunks and chunks[0][0] == 'input':
chunks[0] = ('input', completize_preamble (chunks[0][1]))
sys.stderr.write ("invoking `%s'\n" % cmd)
st = os.system (cmd)
if st:
- sys.stderr.write ('Error command exited with value %d\n' % st)
+ error ('Error command exited with value %d\n' % st)
return st
def compile_all_files (chunks):