]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add lilypond-book 'verbatim' option to 'lilypondfile' command
authorJohn Mandereau <john.mandereau@gmail.com>
Sat, 29 Dec 2007 22:49:07 +0000 (23:49 +0100)
committerJohn Mandereau <john.mandereau@gmail.com>
Sat, 29 Dec 2007 22:49:07 +0000 (23:49 +0100)
Documentation/user/lilypond-book.itely
scripts/lilypond-book.py

index ef1176d435c688e7d582a8d08aaf93dc3b768d87..f32e2d8844634b98dd9d7c7b43529f12bca4d512 100644 (file)
@@ -655,6 +655,23 @@ enclosed in a verbatim block, followed by any text given with the
 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
@@ -691,10 +708,11 @@ Most LilyPond test documents (in the @file{input} directory of the
 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
index 7084350d5ae668afa5142a1d609e099724bb6651..4e4c3077824008b296f638c6dd01a2b6022c738b 100644 (file)
@@ -875,6 +875,9 @@ class Lilypond_snippet (Snippet):
         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'
@@ -1169,7 +1172,7 @@ class Lilypond_snippet (Snippet):
             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
        
@@ -1179,7 +1182,7 @@ class Lilypond_snippet (Snippet):
         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 ()
@@ -1213,7 +1216,7 @@ class Lilypond_snippet (Snippet):
         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 ())
@@ -1251,16 +1254,16 @@ class Lilypond_snippet (Snippet):
             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')
@@ -1274,12 +1277,25 @@ class Lilypond_snippet (Snippet):
 
         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,