7 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
10 lilypond-book --filter="convert-ly --no-version --from=1.6.11 -" BOOK
12 classic lilypond-book:
13 lilypond-book --process="lilypond" BOOK.tely
16 * ly-options: intertext ?
18 * eps in latex / eps by lilypond -fps ?
19 * check latex parameters, twocolumn, multicolumn?
21 * Converting from lilypond-book source, substitute:
22 @mbinclude foo.itely -> @include foo.itely
35 # * use --png --ps --pdf for making images?
38 ################################################################
39 # Users of python modules should include this snippet
40 # and customize variables below.
42 # We'll suffer this path init stuff as long as we don't install our
43 # python packages in <prefix>/lib/pythonx.y (and don't kludge around
44 # it as we do with teTeX on Red Hat Linux: set some environment var
45 # (PYTHONPATH) in profile)
47 # If set, LILYPONDPREFIX must take prevalence
48 # if datadir is not set, we're doing a build and LILYPONDPREFIX
49 import getopt, os, sys
50 datadir = '@local_lilypond_datadir@'
51 if not os.path.isdir (datadir):
52 datadir = '@lilypond_datadir@'
53 if os.environ.has_key ('LILYPONDPREFIX'):
54 datadir = os.environ['LILYPONDPREFIX']
55 while datadir[-1] == os.sep:
58 sys.path.insert (0, os.path.join (datadir, 'python'))
61 #if __name__ == '__main__':
68 program_version = '@TOPLEVEL_VERSION@'
69 program_name = sys.argv[0]
72 original_dir = os.getcwd ()
74 help_summary = _ ('''Process LilyPond snippets in hybrid HTML, LaTeX or texinfo document.
77 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
78 lilypond-book --filter="convert-ly --no-version --from=2.0.0 -" BOOK
79 lilypond-book --process='lilypond -I include' BOOK
83 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>',
84 'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
86 option_definitions = [
87 (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
88 (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
89 ('', 'h', 'help', _ ("print this help")),
90 (_ ("DIR"), 'I', 'include', _ ("add DIR to include path")),
91 (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
92 (_ ("DIR"), 'o', 'output', _ ("write output to DIR")),
93 ('', 'V', 'verbose', _ ("be verbose")),
94 ('', 'v', 'version', _ ("print version information")),
95 ('', 'w', 'warranty', _ ("show warranty and copyright")),
98 include_path = [ly.abspath (os.getcwd ())]
99 lilypond_binary = os.path.join ('@bindir@', 'lilypond')
101 # only use installed binary when we're installed too.
102 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
103 lilypond_binary = 'lilypond'
108 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
111 default_ly_options = {}
114 # is this pythonic? Personally, I find this rather #define-nesque. --hwn
118 EXAMPLEINDENT = 'exampleindent'
120 FRAGMENT = 'fragment'
125 LINEWIDTH = 'linewidth'
126 NOFRAGMENT = 'nofragment'
127 NOINDENT = 'noindent'
132 PREAMBLE = 'preamble'
133 PRINTFILENAME = 'printfilename'
135 RAGGEDRIGHT = 'raggedright'
136 RELATIVE = 'relative'
137 STAFFSIZE = 'staffsize'
140 VERBATIM = 'verbatim'
142 # Recognize special sequences in the input;
144 # (?P<name>regex) -- assign result of REGEX to NAME
145 # *? -- match non-greedily.
146 # (?m) -- multiline regex: make ^ and $ match at each line
147 # (?s) -- make the dot match all characters including newline
148 # (?x) -- ignore whitespace in patterns
160 (\s*(?P<options>.*?)\s*:)?\s*
168 \s*(?P<options>.*?)\s*
177 \s*(?P<options>.*?)\s*
179 \s*(?P<filename>.*?)\s*
186 (?P<code><!--\s.*?!-->)
189 'singleline_comment':
195 (?P<code><pre>.*?</pre>))''',
201 (?P<code><pre>\s.*?</pre>\s))''',
220 \s*(?P<options>.*?)\s*
231 \s*(?P<options>.*?)\s*
235 \\end\s*{lilypond})''',
243 \s*(?P<options>.*?)\s*
251 'singleline_comment':
274 \\end\s*{verbatim}))''',
283 (?P<filename>\S+))''',
287 ^[^\n]*?(?!@c\s+)[^\n]*?
291 \s*(?P<options>.*?)\s*
301 \s*(?P<options>.*?)\s*
304 ^@end\s+lilypond)\s''',
311 \s*(?P<options>.*?)\s*
322 @end\s+ignore))\s''',
324 'singleline_comment':
329 @c([ \t][^\n]*|)\n))''',
331 # don't do this: fucks up with @code{@{}
332 # 'verb': r'''(?P<code>@code{.*?})''',
340 @end\s+example\s))''',
346 'intertext': r',?\s*intertext=\".*?\"',
351 'intertext': r',?\s*intertext=\".*?\"',
352 'option_sep': '\s*,\s*',
356 'intertext': r',?\s*intertext=\".*?\"',
357 'option_sep': '\s*,\s*',
364 RELATIVE: r'''\relative c%(relative_quotes)s''',
369 INDENT: r'''indent = %(indent)s''',
371 LINEWIDTH: r'''linewidth = %(linewidth)s''',
373 NOINDENT: r'''indent = 0.0\mm''',
375 QUOTE: r'''linewidth = %(linewidth)s - 2.0 * %(exampleindent)s''',
377 RAGGEDRIGHT: r'''raggedright = ##t''',
384 NOTIME: r'''\context {
386 \remove Time_signature_engraver
392 STAFFSIZE: r'''#(set-global-staff-size %(staffsize)s)''',
399 FILTER: r'''<lilypond %(options)s>
409 <a href="%(base)s.ly">''',
412 <img align="center" valign="center"
413 border="0" src="%(image)s" alt="[image of music]">''',
415 PRINTFILENAME: '<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
417 QUOTE: r'''<blockquote>
434 \ifx\preLilyPondExample \undefined
439 \def\lilypondbook{}%%
441 \ifx\postLilyPondExample \undefined
448 PRINTFILENAME: '''\\texttt{%(filename)s}
451 QUOTE: r'''\begin{quotation}
456 VERBATIM: r'''\noindent
458 %(verb)s\end{verbatim}
461 FILTER: r'''\begin{lilypond}[%(options)s]
468 FILTER: r'''@lilypond[%(options)s]
476 OUTPUT: r'''@noindent
477 @image{%(base)s,,,[image of music],%(ext)s}''',
479 PRINTFILENAME: '''@file{%(filename)s}
482 QUOTE: r'''@quotation
487 # FIXME: @exampleindent 5 is the default...
488 VERBATIM: r'''@exampleindent 0
496 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
497 %%%% Options: [%(option_string)s]
499 #(set! toplevel-score-handler ly:parser-print-score)
500 #(set! toplevel-music-handler (lambda (p m)
501 (ly:parser-print-score
502 p (ly:music-scorify m p))))
507 #(define dump-extents #t)
519 %% ly snippet contents follows:
531 texinfo_linewidths = {
532 '@afourpaper': '160\\mm',
533 '@afourwide': '6.5\\in',
534 '@afourlatex': '150\\mm',
535 '@smallbook': '5\\in',
536 '@letterpaper': '6\\in',
539 def classic_lilypond_book_compatibility (key, value):
540 if key == 'singleline' and value == None:
541 return (RAGGEDRIGHT, None)
543 m = re.search ('relative\s*([-0-9])', key)
545 return ('relative', m.group (1))
547 m = re.match ('([0-9]+)pt', key)
549 return ('staffsize', m.group (1))
551 if key == 'indent' or key == 'linewidth':
552 m = re.match ('([-.0-9]+)(cm|in|mm|pt|staffspace)', value)
554 f = float (m.group (1))
555 return (key, '%f\\%s' % (f, m.group (2)))
559 def compose_ly (code, options, type):
562 if string.find (i, '=') > 0:
563 (key, value) = re.split ('\s*=\s*', i)
564 option_dict[key] = value
566 option_dict[i] = None
568 has_linewidth = option_dict.has_key (LINEWIDTH)
570 for i in default_ly_options.keys ():
571 if i not in option_dict.keys ():
572 option_dict[i] = default_ly_options[i]
574 if not INDENT in option_dict.keys ():
575 option_dict[NOINDENT] = None
577 if not has_linewidth and LINEWIDTH in option_dict.keys ():
578 if QUOTE in option_dict.keys () or type == 'lilypond':
579 del option_dict[LINEWIDTH]
580 option_dict[RAGGEDRIGHT] = None
582 if FRAGMENT in option_dict.keys ():
590 # FIXME: Where to get sane value for exampleindent?
591 # In texinfo.tex, its maximum value is 0.4in, so we use that.
592 override[EXAMPLEINDENT] = r'0.4\in'
593 override[LINEWIDTH] = None
594 override.update (default_ly_options)
597 for (key, value) in option_dict.items ():
599 option_list.append (key)
601 option_list.append (key + '=' + value)
602 option_string = string.join (option_list, ',')
605 compose_types = [NOTES, PREAMBLE, LAYOUT, PAPER]
606 for a in compose_types:
609 for (key, value) in option_dict.items():
611 classic_lilypond_book_compatibility (key, value)
615 (_ ("deprecated ly-option used: %s=%s" \
618 (_ ("compatibility mode translation: %s=%s" \
622 (_ ("deprecated ly-option used: %s" \
625 (_ ("compatibility mode translation: %s" \
628 (key, value) = (c_key, c_value)
631 override[key] = value
633 if not override.has_key (key):
637 for type in compose_types:
638 if ly_options[type].has_key (key):
639 compose_dict[type].append (ly_options[type][key])
643 if not found and key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
644 RELATIVE, VERBATIM, TEXIDOC):
645 ly.warning (_ ("ignoring unknown ly option: %s") % i)
648 if RELATIVE in override.keys () and override[RELATIVE]:
649 relative = string.atoi (override[RELATIVE])
655 relative_quotes += ',' * (- relative)
657 relative_quotes += "'" * relative
659 program_name = __main__.program_name
662 string.join (compose_dict[PAPER], '\n ') % override
664 string.join (compose_dict[LAYOUT], '\n ') % override
666 string.join (compose_dict[NOTES], '\n ') % vars ()
668 string.join (compose_dict[PREAMBLE], '\n ') % override
670 return (PREAMBLE_LY + body) % vars ()
673 # use lilypond for latex (.lytex) books,
674 # and lilypond --preview for html, texinfo books?
676 cmd = r'latex "\nonstopmode \input %s"' % file
677 # Ugh. (La)TeX writes progress and error messages on stdout
679 cmd = '(( %s >&2 ) >&- )' % cmd
681 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
684 # check if it really is EPS.
685 # Otherwise music glyphs disappear from 2nd and following pages.
687 # TODO: should run dvips -pp -E per page, then we get proper
690 f = open ('%s.eps' % file)
691 for x in range (0, 10):
692 if re.search ("^%%Pages: ", f.readline ()):
694 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
698 def find_file (name):
699 for i in include_path:
700 full = os.path.join (i, name)
701 if os.path.exists (full):
703 ly.error (_ ("file not found: %s") % name + '\n')
707 def verbatim_html (s):
708 return re.sub ('>', '>',
710 re.sub ('&', '&', s)))
712 def verbatim_texinfo (s):
713 return re.sub ('{', '@{',
715 re.sub ('@', '@@', s)))
717 def split_options (option_string):
718 return re.split (format_res[format]['option_sep'], option_string)
721 def replacement_text (self):
724 def filter_text (self):
725 return self.replacement_text ()
727 def ly_is_outdated (self):
730 def png_is_outdated (self):
733 class Substring (Chunk):
734 def __init__ (self, source, start, end):
739 def replacement_text (self):
740 return self.source [self.start:self.end]
742 class Snippet (Chunk):
743 def __init__ (self, type, match, format):
750 def replacement_text (self):
751 return self.match.group ('match')
753 def substring (self, s):
754 return self.match.group (s)
757 return `self.__class__` + " type = " + self.type
759 class Include_snippet (Snippet):
760 def processed_filename (self):
761 f = self.substring ('filename')
762 return os.path.splitext (f)[0] + format2ext[format]
764 def replacement_text (self):
765 s = self.match.group ('match')
766 f = self.substring ('filename')
768 return re.sub (f, self.processed_filename (), s)
770 class Lilypond_snippet (Snippet):
771 def __init__ (self, type, match, format):
772 Snippet.__init__ (self, type, match, format)
773 os = match.group ('options')
775 self.options = split_options (os)
778 return self.substring ('code')
783 return compose_ly (s, self.options, self.type)
789 self.hash = abs (hash (self.full_ly ()))
794 return 'lily-%d' % self.get_hash ()
798 outf = open (self.basename () + '.ly', 'w')
799 outf.write (self.full_ly ())
801 open (self.basename () + '.txt', 'w').write ("image of music")
803 def ly_is_outdated (self):
804 base = self.basename ()
806 tex_file = '%s.tex' % base
807 ly_file = '%s.ly' % base
808 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
809 and os.stat (tex_file)[stat.ST_SIZE] \
810 and open (tex_file).readlines ()[-1][1:-1] \
813 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
814 # TODO: something smart with target formats
815 # (ps, png) and m/ctimes
819 def png_is_outdated (self):
820 base = self.basename ()
821 ok = self.ly_is_outdated ()
822 if format == HTML or format == TEXINFO:
823 ok = ok and (os.path.exists (base + '.png')
824 or glob.glob (base + '-page*.png'))
827 def filter_text (self):
828 code = self.substring ('code')
829 s = run_filter (code)
832 'options': self.match.group ('options')
835 return output[self.format][FILTER] % d
837 def replacement_text (self):
838 func = Lilypond_snippet.__dict__ ['output_' + self.format]
841 def get_images (self):
842 base = self.basename ()
844 single = '%(base)s.png' % vars ()
845 multiple = '%(base)s-page1.png' % vars ()
847 if os.path.exists (multiple) \
848 and (not os.path.exists (single) \
849 or (os.stat (multiple)[stat.ST_MTIME] \
850 > os.stat (single)[stat.ST_MTIME])):
851 images = glob.glob ('%(base)s-page*.png' % vars ())
854 def output_html (self):
856 base = self.basename ()
858 str += self.output_print_filename (HTML)
859 if VERBATIM in self.options:
860 verb = verbatim_html (self.substring ('code'))
861 str += write (output[HTML][VERBATIM] % vars ())
862 if QUOTE in self.options:
863 str = output[HTML][QUOTE] % vars ()
865 str += output[HTML][BEFORE] % vars ()
866 for image in self.get_images ():
867 (base, ext) = os.path.splitext (image)
868 str += output[HTML][OUTPUT] % vars ()
869 str += output[HTML][AFTER] % vars ()
872 def output_info (self):
873 str = self.output_print_filename (HTML)
874 str = output[TEXINFO][BEFORE] % vars ()
875 for image in self.get_images ():
876 (base, ext) = os.path.splitext (image)
878 # URG, makeinfo implicitely prepends dot to ext
879 # specifying no extension is most robust
881 str += output[TEXINFO][OUTPUT] % vars ()
882 str += output[TEXINFO][AFTER] % vars ()
885 def output_latex (self):
887 base = self.basename ()
889 str += self.output_print_filename (LATEX)
890 if VERBATIM in self.options:
891 verb = self.substring ('code')
892 str += (output[LATEX][VERBATIM] % vars ())
893 if QUOTE in self.options:
894 str = output[LATEX][QUOTE] % vars ()
896 str += (output[LATEX][BEFORE]
897 + (output[LATEX][OUTPUT] % vars ())
898 + output[LATEX][AFTER])
901 def output_print_filename (self,format):
903 if PRINTFILENAME in self.options:
904 base = self.basename ()
905 filename = self.substring ('filename')
906 str = output[format][PRINTFILENAME] % vars ()
909 def output_texinfo (self):
911 if self.output_print_filename (TEXINFO):
912 str += ('@html\n' + self.output_print_filename (HTML)
914 str += ('@tex\n' + self.output_print_filename (LATEX)
916 base = self.basename ()
917 if TEXIDOC in self.options:
918 texidoc = base + '.texidoc'
919 if os.path.exists (texidoc):
920 str += '@include %(texidoc)s\n\n' % vars ()
922 if VERBATIM in self.options:
923 verb = verbatim_texinfo (self.substring ('code'))
924 str += (output[TEXINFO][VERBATIM] % vars ())
926 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
927 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
928 str += ('@html\n' + self.output_html () + '\n@end html\n')
930 if QUOTE in self.options:
931 str = output[TEXINFO][QUOTE] % vars ()
933 # need par after image
938 class Lilypond_file_snippet (Lilypond_snippet):
940 name = self.substring ('filename')
941 return '\\renameinput \"%s\"\n%s' % (name, open (find_file (name)).read ())
943 snippet_type_to_class = {
944 'lilypond_file': Lilypond_file_snippet,
945 'lilypond_block': Lilypond_snippet,
946 'lilypond': Lilypond_snippet,
947 'include': Include_snippet,
950 def find_toplevel_snippets (s, types):
953 res[i] = ly.re.compile (snippet_res[format][i])
957 ## found = dict (map (lambda x: (x, None), types))
960 map (lambda x, f = found: f.setdefault (x, None), types)
962 # We want to search for multiple regexes, without searching
963 # the string multiple times for one regex.
964 # Hence, we use earlier results to limit the string portion
966 # Since every part of the string is traversed at most once for
967 # every type of snippet, this is linear.
973 if not found[type] or found[type][0] < index:
975 m = res[type].search (s[index:endex])
980 if snippet_type_to_class.has_key (type):
981 cl = snippet_type_to_class[type]
982 snip = cl (type, m, format)
983 start = index + m.start ('match')
984 found[type] = (start, snip)
987 and (not first or found[type][0] < found[first][0]):
992 # Limiting the search space is a cute
993 # idea, but this *requires* to search
994 # for possible containing blocks
995 # first, at least as long as we do not
996 # search for the start of blocks, but
997 # always/directly for the entire
998 # @block ... @end block.
1000 endex = found[first][0]
1003 snippets.append (Substring (s, index, len (s)))
1006 (start, snip) = found[first]
1007 snippets.append (Substring (s, index, start))
1008 snippets.append (snip)
1010 index = start + len (snip.match.group ('match'))
1014 def filter_pipe (input, cmd):
1016 ly.progress (_ ("Opening filter `%s'") % cmd)
1018 (stdin, stdout, stderr) = os.popen3 (cmd)
1020 status = stdin.close ()
1024 output = stdout.read ()
1025 status = stdout.close ()
1026 error = stderr.read ()
1030 signal = 0x0f & status
1031 if status or (not output and error):
1032 exit_status = status >> 8
1033 ly.error (_ ("`%s' failed (%d)") % (cmd, exit_status))
1034 ly.error (_ ("The error log is as follows:"))
1035 sys.stderr.write (error)
1036 sys.stderr.write (stderr.read ())
1045 return filter_pipe (s, filter_cmd)
1047 def is_derived_class (cl, baseclass):
1050 for b in cl.__bases__:
1051 if is_derived_class (b, baseclass):
1055 def process_snippets (cmd, ly_snippets, png_snippets):
1056 ly_names = filter (lambda x: x, map (Lilypond_snippet.basename, ly_snippets))
1057 png_names = filter (lambda x: x, map (Lilypond_snippet.basename, png_snippets))
1061 status = ly.system (string.join ([cmd] + ly_names),
1062 ignore_error = 1, progress_p = 1)
1065 ly.error ('Process %s exited unsuccessfully.' % cmd)
1068 if format == HTML or format == TEXINFO:
1070 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
1072 ly.make_ps_images (i + '.eps', resolution = 110)
1074 # elif os.path.exists (i + '.ps'):
1075 # ly.make_ps_images (i + '.ps', resolution = 110)
1077 LATEX_DOCUMENT = r'''
1080 \typeout{textwidth=\the\textwidth}
1081 \typeout{columnsep=\the\columnsep}
1082 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
1085 #need anything else besides textwidth?
1086 def get_latex_textwidth (source):
1087 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
1088 preamble = source[:m.start (0)]
1089 latex_document = LATEX_DOCUMENT % vars ()
1090 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
1093 m = re.search ('columns=([0-9.]*)', parameter_string)
1095 columns = string.atoi (m.group (1))
1098 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
1100 columnsep = string.atof (m.group (1))
1103 m = re.search ('textwidth=([0-9.]*)pt', parameter_string)
1105 textwidth = string.atof (m.group (1))
1107 textwidth = (textwidth - columnsep) / columns
1119 '.texinfo': TEXINFO,
1125 #TEXINFO: '.texinfo',
1130 class Compile_error:
1133 def do_process_cmd (chunks):
1134 ly_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1135 and x.ly_is_outdated (), chunks)
1136 png_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1137 and x.png_is_outdated (), chunks)
1139 ly.progress (_ ("Writing snippets..."))
1140 map (Lilypond_snippet.write_ly, ly_outdated)
1144 ly.progress (_ ("Processing...\n"))
1145 process_snippets (process_cmd, ly_outdated, png_outdated)
1147 ly.progress (_ ("All snippets are up to date..."))
1150 def do_file (input_filename):
1154 e = os.path.splitext (input_filename)[1]
1155 if e in ext2format.keys ():
1157 format = ext2format[e]
1159 ly.error (_ ("cannot determine format for: %s" \
1163 if not input_filename or input_filename == '-':
1164 in_handle = sys.stdin
1165 input_fullname = '<stdin>'
1167 if os.path.exists (input_filename):
1168 input_fullname = input_filename
1169 elif format == LATEX:
1170 # urg python interface to libkpathsea?
1171 input_fullname = ly.read_pipe ('kpsewhich '
1172 + input_filename)[:-1]
1174 input_fullname = find_file (input_filename)
1175 in_handle = open (input_fullname)
1177 if input_filename == '-':
1178 input_base = 'stdin'
1180 input_base = os.path.basename \
1181 (os.path.splitext (input_filename)[0])
1183 # only default to stdout when filtering
1184 if output_name == '-' or (not output_name and filter_cmd):
1185 output_filename = '-'
1186 output_file = sys.stdout
1189 output_filename = input_base + format2ext[format]
1191 if not os.path.isdir (output_name):
1192 os.mkdir (output_name, 0777)
1193 output_filename = (output_name
1195 + format2ext[format])
1197 if (os.path.exists (input_filename) and
1198 os.path.exists (output_filename) and
1199 os.path.samefile (output_filename, input_fullname)):
1200 ly.error (_ ("Output would overwrite input file; use --output."))
1203 output_file = open (output_filename, 'w')
1205 os.chdir (output_name)
1207 ly.progress (_ ("Reading %s...") % input_fullname)
1208 source = in_handle.read ()
1211 # FIXME: containing blocks must be first, see
1212 # find_toplevel_snippets
1214 'multiline_comment',
1218 'singleline_comment',
1222 ly.progress (_ ("Dissecting..."))
1223 chunks = find_toplevel_snippets (source, snippet_types)
1226 global default_ly_options
1228 if not default_ly_options.has_key (LINEWIDTH):
1230 textwidth = get_latex_textwidth (source)
1231 default_ly_options[LINEWIDTH] = \
1232 '''%.0f\\pt''' % textwidth
1233 elif format == TEXINFO:
1234 for (k, v) in texinfo_linewidths.items ():
1235 # FIXME: @layout is usually not in chunk #0:
1236 # \input texinfo @c -*-texinfo-*-
1237 # bluntly search first K of source
1238 # s = chunks[0].replacement_text ()
1239 if re.search (k, source[:1024]):
1240 default_ly_options[LINEWIDTH] = v
1244 output_file.writelines ([c.filter_text () for c in chunks])
1247 do_process_cmd (chunks)
1248 ly.progress (_ ("Compiling %s...") % output_filename)
1249 output_file.writelines ([s.replacement_text () \
1253 def process_include (snippet):
1254 os.chdir (original_dir)
1255 name = snippet.substring ('filename')
1256 ly.progress (_ ("Processing include: %s") % name)
1260 map (process_include,
1261 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
1262 except Compile_error:
1263 os.chdir (original_dir)
1264 ly.progress (_ ("Removing `%s'") % output_filename)
1267 os.unlink (output_filename)
1271 global format, output_name
1272 global filter_cmd, process_cmd, verbose_p
1274 (sh, long) = ly.getopt_args (option_definitions)
1276 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
1277 except getopt.error, s:
1278 sys.stderr.write ('\n')
1279 ly.error (_ ("getopt says: `%s'" % s))
1280 sys.stderr.write ('\n')
1290 elif o == '--filter' or o == '-F':
1293 elif o == '--format' or o == '-f':
1295 if a == 'texi-html' or a == 'texi':
1297 elif o == '--help' or o == '-h':
1300 elif o == '--include' or o == '-I':
1301 include_path.append (os.path.join (original_dir,
1303 elif o == '--output' or o == '-o':
1305 elif o == '--outdir':
1307 elif o == '--process' or o == '-P':
1310 elif o == '--version' or o == '-v':
1311 ly.identify (sys.stdout)
1313 elif o == '--verbose' or o == '-V':
1315 elif o == '--warranty' or o == '-w':
1322 files = do_options ()
1324 if process_cmd == '':
1325 process_cmd = lilypond_binary + " -f tex "
1328 process_cmd += string.join ([(' -I %s' % p)
1329 for p in include_path])
1331 ly.identify (sys.stderr)
1332 ly.setup_environment ()
1336 except Compile_error:
1339 if __name__ == '__main__':