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__':
69 program_version = '@TOPLEVEL_VERSION@'
70 program_name = 'lilypond-book'
73 original_dir = os.getcwd ()
76 help_summary = _ ("""Process LilyPond snippets in hybrid HTML, LaTeX or texinfo document.
79 lilypond-book --filter="tr '[a-z]' '[A-Z]'" BOOK
80 lilypond-book --filter="convert-ly --no-version --from=2.0.0 -" BOOK
81 lilypond-book --process='lilypond -I include' BOOK
85 copyright = ('Jan Nieuwenhuizen <janneke@gnu.org>',
86 'Han-Wen Nienhuys <hanwen@cs.uu.nl>')
88 option_definitions = [
89 (_ ("EXT"), 'f', 'format', _ ("use output format EXT (texi [default], texi-html, latex, html)")),
90 (_ ("FILTER"), 'F', 'filter', _ ("pipe snippets through FILTER [convert-ly -n -]")),
91 ('', 'h', 'help', _ ("print this help")),
92 (_ ("DIR"), 'I', 'include', _ ("add DIR to include path")),
93 (_ ("COMMAND"), 'P', 'process', _ ("process ly_files using COMMAND FILE...")),
94 (_ ("DIR"), 'o', 'output', _ ("write output to DIR")),
95 ('', 'V', 'verbose', _ ("be verbose")),
96 ('', 'v', 'version', _ ("print version information")),
97 ('', 'w', 'warranty', _ ("show warranty and copyright")),
100 include_path = [ly.abspath (os.getcwd ())]
101 lilypond_binary = os.path.join ('@bindir@', 'lilypond')
103 # only use installed binary when we're installed too.
104 if '@bindir@' == ('@' + 'bindir@') or not os.path.exists (lilypond_binary):
105 lilypond_binary = 'lilypond'
111 latex_filter_cmd = 'latex "\\nonstopmode \input /dev/stdin"'
114 default_ly_options = {}
117 # is this pythonic? Personally, I find this rather #define-nesque. --hwn
121 BOOKPAPER = 'bookpaper'
122 EXAMPLEINDENT = 'exampleindent'
124 FRAGMENT = 'fragment'
128 LINEWIDTH = 'linewidth'
129 NOFRAGMENT = 'nofragment'
130 NOINDENT = 'noindent'
135 PREAMBLE = 'preamble'
136 PRINTFILENAME = 'printfilename'
138 RAGGEDRIGHT = 'raggedright'
139 RELATIVE = 'relative'
140 STAFFSIZE = 'staffsize'
143 VERBATIM = 'verbatim'
145 # Recognize special sequences in the input
147 # (?P<name>regex) -- assign result of REGEX to NAME
148 # *? -- match non-greedily.
149 # (?m) -- multiline regex: make ^ and $ match at each line
150 # (?s) -- make the dot match all characters including newline
155 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
156 'lilypond_block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
157 'lilypond_file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
158 'multiline_comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
159 'singleline_comment': no_match,
160 'verb': r'''(?P<code><pre>.*?</pre>)''',
161 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
165 'include': r'(?m)^[^%\n]*?(?P<match>\\input{(?P<filename>[^}]+)})',
166 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
167 'lilypond_block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
168 'lilypond_file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
169 'multiline_comment': no_match,
170 'singleline_comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
171 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
172 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
176 'include': '(?m)^[^%\n]*?(?P<match>@include\s+(?P<filename>\S+))',
177 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
178 'lilypond_block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
179 'lilypond_file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
180 'multiline_comment': r'(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end\s+ignore)\s',
181 'singleline_comment': r'(?m)^.*(?P<match>(?P<code>@c([ \t][^\n]*|)\n))',
183 # don't do this: fucks up with @code{@{}
184 # 'verb': r'''(?P<code>@code{.*?})''',
185 'verbatim': r'''(?s)(?P<code>@example\s.*?@end\s+example\s)''',
191 'option-sep' : '\s*',
192 'intertext': r',?\s*intertext=\".*?\"',
195 'intertext': r',?\s*intertext=\".*?\"',
196 'option-sep' : ',\s*',
199 'intertext': r',?\s*intertext=\".*?\"',
200 'option-sep' : ',\s*',
206 RELATIVE: r'''\relative c%(relative_quotes)s''',
210 indent = %(indent)s''',
212 linewidth = %(linewidth)s''',
216 linewidth = %(linewidth)s - 2.0 * %(exampleindent)s
220 raggedright = ##t''',
230 \remove Time_signature_engraver
237 #(set-global-staff-size %(staffsize)s)''',
243 FILTER: r'''<lilypond %(options)s>
253 <a href="%(base)s.ly">''',
255 <img align="center" valign="center"
256 border="0" src="%(image)s" alt="[image of music]">''',
257 PRINTFILENAME:'<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
258 QUOTE: r'''<blockquote>
269 OUTPUT: r'''{\parindent 0pt
271 \ifx\preLilyPondExample\undefined\relax\else\preLilyPondExample\fi
274 \ifx\postLilyPondExample\undefined\relax\else\postLilyPondExample\fi
276 PRINTFILENAME: '''\\texttt{%(filename)s}
279 QUOTE: r'''\begin{quotation}
283 VERBATIM: r'''\noindent
285 %(verb)s\end{verbatim}
287 FILTER: r'''\begin{lilypond}[%(options)s]
293 FILTER: r'''@lilypond[%(options)s]
298 OUTPUT: r'''@noindent
299 @image{%(base)s,,,[image of music],%(ext)s}
301 PRINTFILENAME: '''@file{%(filename)s}
304 QUOTE: r'''@quotation
308 # FIXME: @exampleindent 5 is the default...
309 VERBATIM: r'''@exampleindent 0
317 PREAMBLE_LY = r'''%%%% Generated by %(program_name)s
318 %%%% Options: [%(option_string)s]
319 #(set! toplevel-score-handler ly:parser-print-score)
320 #(set! toplevel-music-handler (lambda (p m)
321 (ly:parser-print-score
322 p (ly:music-scorify m p))
325 \bookpaper {%(bookpaper_string)s
327 \paper { %(paper_string)s
338 texinfo_linewidths = {
339 '@afourpaper': '160 \\mm',
340 '@afourwide': '6.5 \\in',
341 '@afourlatex': '150 \\mm',
342 '@smallbook': '5 \\in' ,
343 '@letterpaper': '6\\in',
346 def classic_lilypond_book_compatibility (o):
347 if o == 'singleline':
349 m = re.search ('relative\s*([-0-9])', o)
351 return 'relative=%s' % m.group (1)
352 m = re.match ('([0-9]+)pt', o)
354 return 'staffsize=%s' % m.group (1)
355 m = re.match ('indent=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
357 f = float (m.group (1))
358 return 'indent=%f\\%s' % (f, m.group (2))
359 m = re.match ('linewidth=([-.0-9]+)(cm|in|mm|pt|staffspace)', o)
361 f = float (m.group (1))
362 return 'linewidth=%f\\%s' % (f, m.group (2))
365 def compose_ly (code, options):
367 for i in default_ly_options.keys ():
372 if QUOTE in options and LINEWIDTH in options:
373 options.remove (LINEWIDTH)
375 if FRAGMENT in options:
376 if RAGGEDRIGHT not in options:
377 options.append (RAGGEDRIGHT)
386 override.update (default_ly_options)
387 #FIXME: where to get sane value for exampleindent?
388 override[EXAMPLEINDENT] = r'9.0 \mm'
390 option_string = string.join (options, ',')
393 option_types = [NOTES, PREAMBLE, PAPER, BOOKPAPER]
394 for a in option_types:
398 c = classic_lilypond_book_compatibility (i)
400 ly.warning (_ ("deprecated ly-option used: %s" % i))
401 ly.warning (_ ("compatibility mode translation: %s" \
405 if string.find (i, '=') > 0:
406 key, value = string.split (i, '=')
407 override[key] = value
410 if not override.has_key (i):
414 for type in option_types:
415 if ly_options[type].has_key (key):
417 options_dict[type].append (ly_options[type][key])
421 if not found and key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
422 RELATIVE, VERBATIM, TEXIDOC):
423 ly.warning (_("ignoring unknown ly option: %s") % i)
426 if RELATIVE in override.keys () and override[RELATIVE]:
427 relative = string.atoi (override[RELATIVE])
433 relative_quotes += ',' * (- relative)
435 relative_quotes += "'" * relative
437 program_name = __main__.program_name
439 paper_string = string.join (options_dict[PAPER], '\n ') % override
440 bookpaper_string = string.join (options_dict[BOOKPAPER], '\n ') % override
441 notes_string = string.join (options_dict[NOTES], '\n ') % vars ()
442 preamble_string = string.join (options_dict[PREAMBLE], '\n ') % override
443 return (PREAMBLE_LY + body) % vars ()
447 # use lilypond for latex (.lytex) books,
448 # and lilypond --preview for html, texinfo books?
450 cmd = r'latex "\nonstopmode \input %s"' % file
451 # Ugh. (La)TeX writes progress and error messages on stdout
453 cmd = '(( %s >&2 ) >&- )' % cmd
455 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
459 # check if it really is EPS.
460 # Otherwise music glyphs disappear from 2nd and following pages.
462 # TODO: should run dvips -pp -E per page, then we get proper
465 f = open ('%s.eps' % file)
466 for x in range(0,10) :
467 if re.search ("^%%Pages: ", f.readline ()):
470 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
475 def find_file (name):
476 for i in include_path:
477 full = os.path.join (i, name)
478 if os.path.exists (full):
480 ly.error (_ ('file not found: %s') % name + '\n')
484 def verbatim_html (s):
485 return re.sub ('>', '>',
487 re.sub ('&', '&', s)))
489 def verbatim_texinfo (s):
490 return re.sub ('{', '@{',
492 re.sub ('@', '@@', s)))
494 def split_options (option_string):
495 return re.split (format_res[format]['option-sep'], option_string)
499 def replacement_text (self):
502 def filter_text (self):
503 return self.replacement_text ()
506 def ly_is_outdated (self):
509 def png_is_outdated (self):
512 class Substring (Chunk):
513 def __init__ (self, source, start, end):
518 def replacement_text (self):
519 return self.source [self.start:self.end]
521 class Snippet (Chunk):
522 def __init__ (self, type, match, format):
529 def replacement_text (self):
530 return self.match.group (0)
532 def substring (self, s):
533 return self.match.group (s)
536 return `self.__class__` + " type = " + self.type
538 class Include_snippet (Snippet):
539 def processed_filename (self):
540 f = self.substring ('filename')
541 return os.path.splitext (f)[0] + format2ext[format]
543 def replacement_text (self):
544 s = self.match.group (0)
545 f = self.substring ('filename')
547 return re.sub (f, self.processed_filename (), s)
549 class Lilypond_snippet (Snippet):
550 def __init__ (self, type, match, format):
551 Snippet.__init__ (self, type, match, format)
552 os = match.group ('options')
554 self.options = split_options (os)
557 return self.substring ('code')
562 return compose_ly (s, self.options)
568 self.hash = abs (hash (self.full_ly ()))
573 return 'lily-%d' % self.get_hash ()
577 outf = open (self.basename () + '.ly', 'w')
578 outf.write (self.full_ly ())
580 open (self.basename() + '.txt', 'w').write("image of music")
583 def ly_is_outdated (self):
584 base = self.basename ()
586 tex_file = '%s.tex' % base
587 ly_file = '%s.ly' % base
588 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
589 and os.stat (tex_file)[stat.ST_SIZE] \
590 and open (tex_file).readlines ()[-1][1:-1] \
593 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
594 # TODO: something smart with target formats
595 # (ps, png) and m/ctimes
599 def png_is_outdated (self):
600 base = self.basename ()
601 ok = self.ly_is_outdated ()
602 if format == HTML or format == TEXINFO:
603 ok = ok and (os.path.exists (base + '.png')
604 or glob.glob (base + '-page*.png'))
607 def filter_text (self):
608 code = self.substring ('code')
609 s = run_filter (code)
611 'options': self.match.group ('options')
614 return output[self.format][FILTER] % d
616 def replacement_text (self):
617 func = Lilypond_snippet.__dict__ ['output_' + self.format]
620 def get_images (self):
621 base = self.basename ()
623 single = '%(base)s.png' % vars ()
624 multiple = '%(base)s-page1.png' % vars ()
626 if os.path.exists (multiple) \
627 and (not os.path.exists (single)\
628 or (os.stat (multiple)[stat.ST_MTIME] \
629 > os.stat (single)[stat.ST_MTIME])):
630 images = glob.glob ('%(base)s-page*.png' % vars ())
633 def output_html (self):
635 base = self.basename ()
637 str += self.output_print_filename (HTML)
638 if VERBATIM in self.options:
639 verb = verbatim_html (self.substring ('code'))
640 str += write (output[HTML][VERBATIM] % vars ())
641 if QUOTE in self.options:
642 str = output[HTML][QUOTE] % vars ()
644 str += output[HTML][BEFORE] % vars ()
645 for image in self.get_images ():
646 base, ext = os.path.splitext (image)
647 str += output[HTML][OUTPUT] % vars ()
648 str += output[HTML][AFTER] % vars ()
651 def output_info (self):
652 str = self.output_print_filename (HTML)
653 str = output[TEXINFO][BEFORE] % vars ()
654 for image in self.get_images ():
655 base, ext = os.path.splitext (image)
657 # URG, makeinfo implicitely prepends dot to ext
658 # specifying no extension is most robust
660 str += output[TEXINFO][OUTPUT] % vars ()
661 str += output[TEXINFO][AFTER] % vars ()
664 def output_latex (self):
666 base = self.basename ()
668 str += self.output_print_filename (LATEX)
669 if VERBATIM in self.options:
670 verb = self.substring ('code')
671 str += (output[LATEX][VERBATIM] % vars ())
672 if QUOTE in self.options:
673 str = output[LATEX][QUOTE] % vars ()
675 str += (output[LATEX][BEFORE]
676 + (output[LATEX][OUTPUT] % vars ())
677 + output[LATEX][AFTER])
680 def output_print_filename (self,format):
682 if PRINTFILENAME in self.options:
683 base = self.basename ()
684 filename = self.substring ('filename')
685 str = output[format][PRINTFILENAME] % vars ()
688 def output_texinfo (self):
690 # self.output_print_filename (TEXINFO)
691 str += ('@html\n' + self.output_print_filename (HTML)
693 str += ('@tex\n' + self.output_print_filename (LATEX)
695 base = self.basename ()
696 if TEXIDOC in self.options:
697 texidoc = base + '.texidoc'
698 if os.path.exists (texidoc):
699 str += '@include %(texidoc)s\n\n' % vars ()
701 if VERBATIM in self.options:
702 verb = verbatim_texinfo (self.substring ('code'))
703 str += (output[TEXINFO][VERBATIM] % vars ())
705 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
706 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
707 str += ('@html\n' + self.output_html () + '\n@end html\n')
709 if QUOTE in self.options:
710 str = output[TEXINFO][QUOTE] % vars ()
712 # need par after image
717 class Lilypond_file_snippet (Lilypond_snippet):
719 name = self.substring ('filename')
720 return '\\renameinput \"%s\"\n%s' % (name, open (find_file (name)).read ())
722 snippet_type_to_class = {
723 'lilypond_file' : Lilypond_file_snippet,
724 'lilypond_block' : Lilypond_snippet,
725 'lilypond' : Lilypond_snippet,
726 'include' : Include_snippet,
729 def find_toplevel_snippets (s, types):
732 res[i] = ly.re.compile (snippet_res[format][i])
736 ## found = dict (map (lambda x: (x, None), types))
739 map (lambda x, f=found: f.setdefault (x, None), types)
741 # We want to search for multiple regexes, without searching
742 # the string multiple times for one regex.
743 # Hence, we use earlier results to limit the string portion
745 # Since every part of the string is traversed at most once for
746 # every type of snippet, this is linear.
752 if not found[type] or found[type][0] < index:
754 m = res[type].search (s[index:endex])
759 if snippet_type_to_class.has_key (type):
760 cl = snippet_type_to_class[type]
761 snip = cl (type, m, format)
762 start = index + m.start (0)
763 found[type] = (start, snip)
766 and (not first or found[type][0] < found[first][0]):
771 # Limiting the search space is a cute
772 # idea, but this *requires* to search
773 # for possible containing blocks
774 # first, at least long as we do not
775 # search for the start of blocks, but
776 # always/directly for the entire
777 # @block ... @end block.
779 endex = found[first][0]
782 snippets.append (Substring (s, index, len (s)))
785 (start , snip) = found[first]
786 snippets.append (Substring (s, index, start))
787 snippets.append (snip)
789 index = start + len (snip.match.group (0))
793 def filter_pipe (input, cmd):
795 ly.progress (_ ("Opening filter `%s\'") % cmd)
797 stdin, stdout, stderr = os.popen3 (cmd)
799 status = stdin.close ()
803 output = stdout.read ()
804 status = stdout.close ()
805 error = stderr.read ()
809 signal = 0x0f & status
810 if status or (not output and error):
811 exit_status = status >> 8
812 ly.error (_ ("`%s\' failed (%d)") % (cmd, exit_status))
813 ly.error (_ ("The error log is as follows:"))
814 sys.stderr.write (error)
815 sys.stderr.write (stderr.read ())
824 return filter_pipe (s, filter_cmd)
826 def is_derived_class (cl, baseclass):
829 for b in cl.__bases__:
830 if is_derived_class (b, baseclass):
835 def process_snippets (cmd, ly_snippets, png_snippets):
836 ly_names = filter (lambda x: x, map (Lilypond_snippet.basename, ly_snippets))
837 png_names = filter (lambda x: x, map (Lilypond_snippet.basename, png_snippets))
840 ly.system (string.join ([cmd] + ly_names), progress_p = 1)
842 if format == HTML or format == TEXINFO:
844 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
846 ly.make_ps_images (i + '.eps', resolution=110)
848 # elif os.path.exists (i + '.ps'):
849 # ly.make_ps_images (i + '.ps', resolution=110)
852 LATEX_DOCUMENT = r'''
855 \typeout{textwidth=\the\textwidth}
856 \typeout{columnsep=\the\columnsep}
857 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
860 #need anything else besides textwidth?
861 def get_latex_textwidth (source):
862 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
863 preamble = source[:m.start (0)]
864 latex_document = LATEX_DOCUMENT % vars ()
865 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
868 m = re.search ('columns=([0-9.]*)', parameter_string)
870 columns = string.atoi (m.group (1))
873 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
875 columnsep = string.atof (m.group (1))
878 m = re.search('textwidth=([0-9.]*)pt', parameter_string)
880 textwidth = string.atof (m.group (1))
882 textwidth = (textwidth - columnsep) / columns
893 '.texinfo' : TEXINFO,
899 #TEXINFO: '.texinfo',
904 def do_file (input_filename):
908 e = os.path.splitext (input_filename)[1]
909 if e in ext2format.keys ():
911 format = ext2format[e]
913 ly.error (_ ("cannot determine format for: %s" \
916 if not input_filename or input_filename == '-':
917 in_handle = sys.stdin
918 input_fullname = '<stdin>'
920 if os.path.exists (input_filename):
921 input_fullname = input_filename
922 elif format == LATEX:
923 # urg python interface to libkpathsea?
924 input_fullname = ly.read_pipe ('kpsewhich '
925 + input_filename)[:-1]
927 input_fullname = find_file (input_filename)
928 in_handle = open (input_fullname)
930 if input_filename == '-':
933 input_base = os.path.basename \
934 (os.path.splitext (input_filename)[0])
936 # only default to stdout when filtering
937 if output_name == '-' or (not output_name and filter_cmd):
938 output_filename = '-'
939 output_file = sys.stdout
942 output_filename = input_base + format2ext[format]
944 if not os.path.isdir (output_name):
945 os.mkdir (output_name, 0777)
946 output_filename = (output_name
948 + format2ext[format])
951 if (os.path.exists (input_filename) and
952 os.path.exists (output_filename) and
953 os.path.samefile (output_filename, input_fullname)):
954 ly.error (_("Output would overwrite input file; use --output."))
957 output_file = open (output_filename, 'w')
959 os.chdir (output_name)
961 ly.progress (_ ("Reading %s...") % input_fullname)
962 source = in_handle.read ()
965 # FIXME: containing blocks must be first, see find_toplevel_snippets
971 'singleline_comment',
975 ly.progress (_ ("Dissecting..."))
976 chunks = find_toplevel_snippets (source, snippet_types)
979 global default_ly_options
981 if not default_ly_options.has_key (LINEWIDTH):
983 textwidth = get_latex_textwidth (source)
984 default_ly_options[LINEWIDTH] = '''%.0f\\pt''' \
986 elif format == TEXINFO:
987 for (k, v) in texinfo_linewidths.items ():
988 # FIXME: @paper is usually not in chunk #0:
989 # \input texinfo @c -*-texinfo-*-
990 # bluntly search first K of source
991 # s = chunks[0].replacement_text ()
992 if re.search (k, source[:1024]):
993 default_ly_options[LINEWIDTH] = v
997 output_file.writelines ([c.filter_text () for c in chunks])
1001 ly_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1002 and x.ly_is_outdated (), chunks)
1003 png_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1004 and x.png_is_outdated (), chunks)
1006 ly.progress (_ ("Writing snippets..."))
1007 map (Lilypond_snippet.write_ly, ly_outdated)
1011 ly.progress (_ ("Processing..."))
1012 process_snippets (process_cmd, ly_outdated, png_outdated)
1014 ly.progress (_ ("All snippets are up to date..."))
1017 ly.progress (_ ("Compiling %s...") % output_filename)
1018 output_file.writelines ([s.replacement_text () \
1022 def process_include (snippet):
1023 os.chdir (original_dir)
1024 name = snippet.substring ('filename')
1025 ly.progress (_ ('Processing include: %s') % name)
1029 map (process_include,
1030 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
1033 global format, output_name
1034 global filter_cmd, process_cmd, verbose_p
1036 (sh, long) = ly.getopt_args (option_definitions)
1038 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
1039 except getopt.error, s:
1040 sys.stderr.write ('\n')
1041 ly.error (_ ("getopt says: `%s\'" % s))
1042 sys.stderr.write ('\n')
1052 elif o == '--filter' or o == '-F':
1055 elif o == '--format' or o == '-f':
1057 if a == 'texi-html' or a == 'texi':
1059 elif o == '--help' or o == '-h':
1062 elif o == '--include' or o == '-I':
1063 include_path.append (os.path.join (original_dir,
1065 elif o == '--output' or o == '-o':
1067 elif o == '--outdir':
1069 elif o == '--process' or o == '-P':
1072 elif o == '--version' or o == '-v':
1073 ly.identify (sys.stdout)
1075 elif o == '--verbose' or o == '-V':
1077 elif o == '--warranty' or o == '-w':
1084 files = do_options ()
1086 if process_cmd == '':
1087 process_cmd = lilypond_binary + " -f tex "
1090 process_cmd += string.join ([(' -I %s' % p)
1091 for p in include_path])
1093 ly.identify (sys.stderr)
1094 ly.setup_environment ()
1098 if __name__ == '__main__':