displayed. This option does not work well with @code{\lilypond@{@}} if
it is part of a paragraph.
+If @code{verbatim} is used in a @code{lilypondfile} command, it is
+possible to enclose verbatim only a part of the source file. If the
+source file contain a comment containing @samp{begin verbatim} (without
+quotes), quoting the source in the verbatim block will start after the
+last occurence of such a comment; similarly, quoting the source verbatim
+will stop just before the first occurence of a comment containing
+@samp{end verbatim}, it there is any. In the following source file
+example, the music will be interpreted in relative mode, but the
+verbatim quote will not show the @code{relative} block.
+
+@example
+\relative c' { % begin verbatim
+ c4 e2 g4
+ f2 e % end verbatim
+}
+@end example
+
@item texidoc
(Only for Texinfo output.) If @command{lilypond} is called with the
@option{--header=@/texidoc} option, and the file to be processed is
distribution) are small @file{.ly} files which look exactly like this.
@item lilyquote
-(Only for Texinfo output.) This is the same option as quote, but only
-the music snippet is put into a quotation block. This option is useful
-if you want to @code{quote} the music snippet but not the @code{texidoc}
-documentation block.
+(Only for Texinfo output.) This option is similar to quote, but only
+the music snippet (and the optional verbatim block implied by
+@code{verbatim} option) is put into a quotation block. This option is
+useful if you want to @code{quote} the music snippet but not the
+@code{texidoc} documentation block.
@item printfilename
If a LilyPond input file is included with @code{\lilypondfile}, print
os = match.group ('options')
self.do_options (os, self.type)
+ def verb_ly (self):
+ return self.substring ('code')
+
def ly (self):
contents = self.substring ('code')
return ('\\sourcefileline %d\n%s'
else:
str = '<mediaobject>' + str + '</mediaobject>'
if VERBATIM in self.option_dict:
- verb = verbatim_html (self.substring ('code'))
+ verb = verbatim_html (self.verb_ly ())
str = output[DOCBOOK][VERBATIM] % vars () + str
return str
if global_options.format == HTML:
str += self.output_print_filename (HTML)
if VERBATIM in self.option_dict:
- verb = verbatim_html (self.substring ('code'))
+ verb = verbatim_html (self.verb_ly ())
str += output[HTML][VERBATIM] % vars ()
if QUOTE in self.option_dict:
str = output[HTML][QUOTE] % vars ()
if global_options.format == LATEX:
str += self.output_print_filename (LATEX)
if VERBATIM in self.option_dict:
- verb = self.substring ('code')
+ verb = self.verb_ly ()
str += (output[LATEX][VERBATIM] % vars ())
str += (output[LATEX][OUTPUT] % vars ())
if os.path.exists (texidoc):
str += '@include %(texidoc)s\n\n' % vars ()
+ substr = ''
if VERBATIM in self.option_dict:
- verb = self.substring ('code')
- str += output[TEXINFO][VERBATIM] % vars ()
+ verb = self.verb_ly ()
+ substr += output[TEXINFO][VERBATIM] % vars ()
if not QUOTE in self.option_dict:
- str = output[TEXINFO][NOQUOTE] % vars ()
-
+ substr = output[TEXINFO][NOQUOTE] % {'str':substr}
+ substr += self.output_info ()
if LILYQUOTE in self.option_dict:
- str += output[TEXINFO][QUOTE] % {'str':self.output_info ()}
- else:
- str += self.output_info ()
+ substr = output[TEXINFO][QUOTE] % {'str':substr}
+ str += substr
# str += ('@ifinfo\n' + self.output_info () + '\n@end ifinfo\n')
# str += ('@tex\n' + self.output_latex () + '\n@end tex\n')
return str
+re_begin_verbatim = re.compile (r'\s+%.*?begin verbatim.*\n*', re.M)
+re_end_verbatim = re.compile (r'\s+%.*?end verbatim.*$', re.M)
+
class Lilypond_file_snippet (Lilypond_snippet):
+ def __init__ (self, type, match, format, line_number):
+ Lilypond_snippet.__init__ (self, type, match, format, line_number)
+ self.contents = open (find_file (self.substring ('filename'))).read ()
+
+ def verb_ly (self):
+ s = self.contents
+ s = re_begin_verbatim.split (s)[-1]
+ s = re_end_verbatim.split (s)[0]
+ return s
+
def ly (self):
name = self.substring ('filename')
- contents = open (find_file (name)).read ()
return ('\\sourcefilename \"%s\"\n\\sourcefileline 0\n%s'
- % (name, contents))
+ % (name, self.contents))
+
snippet_type_to_class = {
'lilypond_file': Lilypond_file_snippet,