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 override[EXAMPLEINDENT] = r'9.0\mm'
592 override[LINEWIDTH] = None
593 override.update (default_ly_options)
596 for (key, value) in option_dict.items ():
598 option_list.append (key)
600 option_list.append (key + '=' + value)
601 option_string = string.join (option_list, ',')
604 compose_types = [NOTES, PREAMBLE, LAYOUT, PAPER]
605 for a in compose_types:
608 for (key, value) in option_dict.items():
610 classic_lilypond_book_compatibility (key, value)
614 (_ ("deprecated ly-option used: %s=%s" \
617 (_ ("compatibility mode translation: %s=%s" \
621 (_ ("deprecated ly-option used: %s" \
624 (_ ("compatibility mode translation: %s" \
627 (key, value) = (c_key, c_value)
630 override[key] = value
632 if not override.has_key (key):
636 for type in compose_types:
637 if ly_options[type].has_key (key):
638 compose_dict[type].append (ly_options[type][key])
642 if not found and key not in (FRAGMENT, NOFRAGMENT, PRINTFILENAME,
643 RELATIVE, VERBATIM, TEXIDOC):
644 ly.warning (_ ("ignoring unknown ly option: %s") % i)
647 if RELATIVE in override.keys () and override[RELATIVE]:
648 relative = string.atoi (override[RELATIVE])
654 relative_quotes += ',' * (- relative)
656 relative_quotes += "'" * relative
658 program_name = __main__.program_name
661 string.join (compose_dict[PAPER], '\n ') % override
663 string.join (compose_dict[LAYOUT], '\n ') % override
665 string.join (compose_dict[NOTES], '\n ') % vars ()
667 string.join (compose_dict[PREAMBLE], '\n ') % override
669 return (PREAMBLE_LY + body) % vars ()
672 # use lilypond for latex (.lytex) books,
673 # and lilypond --preview for html, texinfo books?
675 cmd = r'latex "\nonstopmode \input %s"' % file
676 # Ugh. (La)TeX writes progress and error messages on stdout
678 cmd = '(( %s >&2 ) >&- )' % cmd
680 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -E -o %s.eps %s' \
683 # check if it really is EPS.
684 # Otherwise music glyphs disappear from 2nd and following pages.
686 # TODO: should run dvips -pp -E per page, then we get proper
689 f = open ('%s.eps' % file)
690 for x in range (0, 10):
691 if re.search ("^%%Pages: ", f.readline ()):
693 ly.system ('dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map -o %s.eps %s' \
697 def find_file (name):
698 for i in include_path:
699 full = os.path.join (i, name)
700 if os.path.exists (full):
702 ly.error (_ ("file not found: %s") % name + '\n')
706 def verbatim_html (s):
707 return re.sub ('>', '>',
709 re.sub ('&', '&', s)))
711 def verbatim_texinfo (s):
712 return re.sub ('{', '@{',
714 re.sub ('@', '@@', s)))
716 def split_options (option_string):
717 return re.split (format_res[format]['option_sep'], option_string)
720 def replacement_text (self):
723 def filter_text (self):
724 return self.replacement_text ()
726 def ly_is_outdated (self):
729 def png_is_outdated (self):
732 class Substring (Chunk):
733 def __init__ (self, source, start, end):
738 def replacement_text (self):
739 return self.source [self.start:self.end]
741 class Snippet (Chunk):
742 def __init__ (self, type, match, format):
749 def replacement_text (self):
750 return self.match.group ('match')
752 def substring (self, s):
753 return self.match.group (s)
756 return `self.__class__` + " type = " + self.type
758 class Include_snippet (Snippet):
759 def processed_filename (self):
760 f = self.substring ('filename')
761 return os.path.splitext (f)[0] + format2ext[format]
763 def replacement_text (self):
764 s = self.match.group ('match')
765 f = self.substring ('filename')
767 return re.sub (f, self.processed_filename (), s)
769 class Lilypond_snippet (Snippet):
770 def __init__ (self, type, match, format):
771 Snippet.__init__ (self, type, match, format)
772 os = match.group ('options')
774 self.options = split_options (os)
777 return self.substring ('code')
782 return compose_ly (s, self.options, self.type)
788 self.hash = abs (hash (self.full_ly ()))
793 return 'lily-%d' % self.get_hash ()
797 outf = open (self.basename () + '.ly', 'w')
798 outf.write (self.full_ly ())
800 open (self.basename () + '.txt', 'w').write ("image of music")
802 def ly_is_outdated (self):
803 base = self.basename ()
805 tex_file = '%s.tex' % base
806 ly_file = '%s.ly' % base
807 ok = os.path.exists (ly_file) and os.path.exists (tex_file)\
808 and os.stat (tex_file)[stat.ST_SIZE] \
809 and open (tex_file).readlines ()[-1][1:-1] \
812 if ok and (use_hash_p or self.ly () == open (ly_file).read ()):
813 # TODO: something smart with target formats
814 # (ps, png) and m/ctimes
818 def png_is_outdated (self):
819 base = self.basename ()
820 ok = self.ly_is_outdated ()
821 if format == HTML or format == TEXINFO:
822 ok = ok and (os.path.exists (base + '.png')
823 or glob.glob (base + '-page*.png'))
826 def filter_text (self):
827 code = self.substring ('code')
828 s = run_filter (code)
831 'options': self.match.group ('options')
834 return output[self.format][FILTER] % d
836 def replacement_text (self):
837 func = Lilypond_snippet.__dict__ ['output_' + self.format]
840 def get_images (self):
841 base = self.basename ()
843 single = '%(base)s.png' % vars ()
844 multiple = '%(base)s-page1.png' % vars ()
846 if os.path.exists (multiple) \
847 and (not os.path.exists (single) \
848 or (os.stat (multiple)[stat.ST_MTIME] \
849 > os.stat (single)[stat.ST_MTIME])):
850 images = glob.glob ('%(base)s-page*.png' % vars ())
853 def output_html (self):
855 base = self.basename ()
857 str += self.output_print_filename (HTML)
858 if VERBATIM in self.options:
859 verb = verbatim_html (self.substring ('code'))
860 str += write (output[HTML][VERBATIM] % vars ())
861 if QUOTE in self.options:
862 str = output[HTML][QUOTE] % vars ()
864 str += output[HTML][BEFORE] % vars ()
865 for image in self.get_images ():
866 (base, ext) = os.path.splitext (image)
867 str += output[HTML][OUTPUT] % vars ()
868 str += output[HTML][AFTER] % vars ()
871 def output_info (self):
872 str = self.output_print_filename (HTML)
873 str = output[TEXINFO][BEFORE] % vars ()
874 for image in self.get_images ():
875 (base, ext) = os.path.splitext (image)
877 # URG, makeinfo implicitely prepends dot to ext
878 # specifying no extension is most robust
880 str += output[TEXINFO][OUTPUT] % vars ()
881 str += output[TEXINFO][AFTER] % vars ()
884 def output_latex (self):
886 base = self.basename ()
888 str += self.output_print_filename (LATEX)
889 if VERBATIM in self.options:
890 verb = self.substring ('code')
891 str += (output[LATEX][VERBATIM] % vars ())
892 if QUOTE in self.options:
893 str = output[LATEX][QUOTE] % vars ()
895 str += (output[LATEX][BEFORE]
896 + (output[LATEX][OUTPUT] % vars ())
897 + output[LATEX][AFTER])
900 def output_print_filename (self,format):
902 if PRINTFILENAME in self.options:
903 base = self.basename ()
904 filename = self.substring ('filename')
905 str = output[format][PRINTFILENAME] % vars ()
908 def output_texinfo (self):
910 if self.output_print_filename (TEXINFO):
911 str += ('@html\n' + self.output_print_filename (HTML)
913 str += ('@tex\n' + self.output_print_filename (LATEX)
915 base = self.basename ()
916 if TEXIDOC in self.options:
917 texidoc = base + '.texidoc'
918 if os.path.exists (texidoc):
919 str += '@include %(texidoc)s\n\n' % vars ()
921 if VERBATIM in self.options:
922 verb = verbatim_texinfo (self.substring ('code'))
923 str += (output[TEXINFO][VERBATIM] % vars ())
925 str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
926 str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
927 str += ('@html\n' + self.output_html () + '\n@end html\n')
929 if QUOTE in self.options:
930 str = output[TEXINFO][QUOTE] % vars ()
932 # need par after image
937 class Lilypond_file_snippet (Lilypond_snippet):
939 name = self.substring ('filename')
940 return '\\renameinput \"%s\"\n%s' % (name, open (find_file (name)).read ())
942 snippet_type_to_class = {
943 'lilypond_file': Lilypond_file_snippet,
944 'lilypond_block': Lilypond_snippet,
945 'lilypond': Lilypond_snippet,
946 'include': Include_snippet,
949 def find_toplevel_snippets (s, types):
952 res[i] = ly.re.compile (snippet_res[format][i])
956 ## found = dict (map (lambda x: (x, None), types))
959 map (lambda x, f = found: f.setdefault (x, None), types)
961 # We want to search for multiple regexes, without searching
962 # the string multiple times for one regex.
963 # Hence, we use earlier results to limit the string portion
965 # Since every part of the string is traversed at most once for
966 # every type of snippet, this is linear.
972 if not found[type] or found[type][0] < index:
974 m = res[type].search (s[index:endex])
979 if snippet_type_to_class.has_key (type):
980 cl = snippet_type_to_class[type]
981 snip = cl (type, m, format)
982 start = index + m.start ('match')
983 found[type] = (start, snip)
986 and (not first or found[type][0] < found[first][0]):
991 # Limiting the search space is a cute
992 # idea, but this *requires* to search
993 # for possible containing blocks
994 # first, at least as long as we do not
995 # search for the start of blocks, but
996 # always/directly for the entire
997 # @block ... @end block.
999 endex = found[first][0]
1002 snippets.append (Substring (s, index, len (s)))
1005 (start, snip) = found[first]
1006 snippets.append (Substring (s, index, start))
1007 snippets.append (snip)
1009 index = start + len (snip.match.group ('match'))
1013 def filter_pipe (input, cmd):
1015 ly.progress (_ ("Opening filter `%s'") % cmd)
1017 (stdin, stdout, stderr) = os.popen3 (cmd)
1019 status = stdin.close ()
1023 output = stdout.read ()
1024 status = stdout.close ()
1025 error = stderr.read ()
1029 signal = 0x0f & status
1030 if status or (not output and error):
1031 exit_status = status >> 8
1032 ly.error (_ ("`%s' failed (%d)") % (cmd, exit_status))
1033 ly.error (_ ("The error log is as follows:"))
1034 sys.stderr.write (error)
1035 sys.stderr.write (stderr.read ())
1044 return filter_pipe (s, filter_cmd)
1046 def is_derived_class (cl, baseclass):
1049 for b in cl.__bases__:
1050 if is_derived_class (b, baseclass):
1054 def process_snippets (cmd, ly_snippets, png_snippets):
1055 ly_names = filter (lambda x: x, map (Lilypond_snippet.basename, ly_snippets))
1056 png_names = filter (lambda x: x, map (Lilypond_snippet.basename, png_snippets))
1060 status = ly.system (string.join ([cmd] + ly_names),
1061 ignore_error = 1, progress_p = 1)
1064 ly.error ('Process %s exited unsuccessfully.' % cmd)
1067 if format == HTML or format == TEXINFO:
1069 if not os.path.exists (i + '.eps') and os.path.exists (i + '.tex'):
1071 ly.make_ps_images (i + '.eps', resolution = 110)
1073 # elif os.path.exists (i + '.ps'):
1074 # ly.make_ps_images (i + '.ps', resolution = 110)
1076 LATEX_DOCUMENT = r'''
1079 \typeout{textwidth=\the\textwidth}
1080 \typeout{columnsep=\the\columnsep}
1081 \makeatletter\if@twocolumn\typeout{columns=2}\fi\makeatother
1084 #need anything else besides textwidth?
1085 def get_latex_textwidth (source):
1086 m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
1087 preamble = source[:m.start (0)]
1088 latex_document = LATEX_DOCUMENT % vars ()
1089 parameter_string = filter_pipe (latex_document, latex_filter_cmd)
1092 m = re.search ('columns=([0-9.]*)', parameter_string)
1094 columns = string.atoi (m.group (1))
1097 m = re.search ('columnsep=([0-9.]*)pt', parameter_string)
1099 columnsep = string.atof (m.group (1))
1102 m = re.search ('textwidth=([0-9.]*)pt', parameter_string)
1104 textwidth = string.atof (m.group (1))
1106 textwidth = (textwidth - columnsep) / columns
1118 '.texinfo': TEXINFO,
1124 #TEXINFO: '.texinfo',
1129 class Compile_error:
1132 def do_process_cmd (chunks):
1133 ly_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1134 and x.ly_is_outdated (), chunks)
1135 png_outdated = filter (lambda x: is_derived_class (x.__class__, Lilypond_snippet) \
1136 and x.png_is_outdated (), chunks)
1138 ly.progress (_ ("Writing snippets..."))
1139 map (Lilypond_snippet.write_ly, ly_outdated)
1143 ly.progress (_ ("Processing...\n"))
1144 process_snippets (process_cmd, ly_outdated, png_outdated)
1146 ly.progress (_ ("All snippets are up to date..."))
1149 def do_file (input_filename):
1153 e = os.path.splitext (input_filename)[1]
1154 if e in ext2format.keys ():
1156 format = ext2format[e]
1158 ly.error (_ ("cannot determine format for: %s" \
1162 if not input_filename or input_filename == '-':
1163 in_handle = sys.stdin
1164 input_fullname = '<stdin>'
1166 if os.path.exists (input_filename):
1167 input_fullname = input_filename
1168 elif format == LATEX:
1169 # urg python interface to libkpathsea?
1170 input_fullname = ly.read_pipe ('kpsewhich '
1171 + input_filename)[:-1]
1173 input_fullname = find_file (input_filename)
1174 in_handle = open (input_fullname)
1176 if input_filename == '-':
1177 input_base = 'stdin'
1179 input_base = os.path.basename \
1180 (os.path.splitext (input_filename)[0])
1182 # only default to stdout when filtering
1183 if output_name == '-' or (not output_name and filter_cmd):
1184 output_filename = '-'
1185 output_file = sys.stdout
1188 output_filename = input_base + format2ext[format]
1190 if not os.path.isdir (output_name):
1191 os.mkdir (output_name, 0777)
1192 output_filename = (output_name
1194 + format2ext[format])
1196 if (os.path.exists (input_filename) and
1197 os.path.exists (output_filename) and
1198 os.path.samefile (output_filename, input_fullname)):
1199 ly.error (_ ("Output would overwrite input file; use --output."))
1202 output_file = open (output_filename, 'w')
1204 os.chdir (output_name)
1206 ly.progress (_ ("Reading %s...") % input_fullname)
1207 source = in_handle.read ()
1210 # FIXME: containing blocks must be first, see find_toplevel_snippets
1212 'multiline_comment',
1216 'singleline_comment',
1220 ly.progress (_ ("Dissecting..."))
1221 chunks = find_toplevel_snippets (source, snippet_types)
1224 global default_ly_options
1226 if not default_ly_options.has_key (LINEWIDTH):
1228 textwidth = get_latex_textwidth (source)
1229 default_ly_options[LINEWIDTH] = \
1230 '''%.0f\\pt''' % textwidth
1231 elif format == TEXINFO:
1232 for (k, v) in texinfo_linewidths.items ():
1233 # FIXME: @layout is usually not in chunk #0:
1234 # \input texinfo @c -*-texinfo-*-
1235 # bluntly search first K of source
1236 # s = chunks[0].replacement_text ()
1237 if re.search (k, source[:1024]):
1238 default_ly_options[LINEWIDTH] = v
1242 output_file.writelines ([c.filter_text () for c in chunks])
1245 do_process_cmd (chunks)
1246 ly.progress (_ ("Compiling %s...") % output_filename)
1247 output_file.writelines ([s.replacement_text () \
1251 def process_include (snippet):
1252 os.chdir (original_dir)
1253 name = snippet.substring ('filename')
1254 ly.progress (_ ("Processing include: %s") % name)
1258 map (process_include,
1259 filter (lambda x: is_derived_class (x.__class__, Include_snippet), chunks))
1260 except Compile_error:
1261 os.chdir (original_dir)
1262 ly.progress (_ ("Removing `%s'") % output_filename)
1265 os.unlink (output_filename)
1269 global format, output_name
1270 global filter_cmd, process_cmd, verbose_p
1272 (sh, long) = ly.getopt_args (option_definitions)
1274 (options, files) = getopt.getopt (sys.argv[1:], sh, long)
1275 except getopt.error, s:
1276 sys.stderr.write ('\n')
1277 ly.error (_ ("getopt says: `%s'" % s))
1278 sys.stderr.write ('\n')
1288 elif o == '--filter' or o == '-F':
1291 elif o == '--format' or o == '-f':
1293 if a == 'texi-html' or a == 'texi':
1295 elif o == '--help' or o == '-h':
1298 elif o == '--include' or o == '-I':
1299 include_path.append (os.path.join (original_dir,
1301 elif o == '--output' or o == '-o':
1303 elif o == '--outdir':
1305 elif o == '--process' or o == '-P':
1308 elif o == '--version' or o == '-v':
1309 ly.identify (sys.stdout)
1311 elif o == '--verbose' or o == '-V':
1313 elif o == '--warranty' or o == '-w':
1320 files = do_options ()
1322 if process_cmd == '':
1323 process_cmd = lilypond_binary + " -f tex "
1326 process_cmd += string.join ([(' -I %s' % p)
1327 for p in include_path])
1329 ly.identify (sys.stderr)
1330 ly.setup_environment ()
1334 except Compile_error:
1337 if __name__ == '__main__':