]> git.donarmstrong.com Git - lilypond.git/commitdiff
Merge branch 'master' of ssh+git://git.sv.gnu.org/srv/git/lilypond
authorWerner Lemberg <wl@gnu.org>
Thu, 1 Jan 2009 18:10:10 +0000 (19:10 +0100)
committerWerner Lemberg <wl@gnu.org>
Thu, 1 Jan 2009 18:10:10 +0000 (19:10 +0100)
scm/framework-eps.scm
scm/framework-ps.scm
scripts/lilypond-book.py
tex/GNUmakefile

index 4983874048c50485fdfc199859dff280f49be967..097e7c414ef06491d68d6cf76487843a3b4bbdae 100644 (file)
             (srfi srfi-13)
             (lily))
 
-(define format ergonomic-simple-format)
-
-(define framework-eps-module (current-module))
+(define format
+  ergonomic-simple-format)
 
+(define framework-eps-module
+  (current-module))
 
 (define (widen-left-stencil-edges stencils)
   "Change STENCILS to use the union for the left extents in every
-stencil, so LaTeX includegraphics doesn't fuck up the alignment."
-
+stencil so that LaTeX's \\includegraphics command doesn't modify the
+alignment."
   (define left
     (if (pair? stencils)
-
        (apply min
               (map (lambda (stc)
                      (interval-start (ly:stencil-extent stc X)))
                    stencils))
        0.0))
-    
+
   (map (lambda (stil)
-        
         (ly:make-stencil
          (ly:stencil-expr stil)
-         (cons
-          left
-          (cdr (ly:stencil-extent stil X)))
-         (ly:stencil-extent stil Y)
-         ))
+         (cons left
+               (cdr (ly:stencil-extent stil X)))
+         (ly:stencil-extent stil Y)))
        stencils))
 
 (define (dump-stencils-as-EPSes stencils book basename)
-  (define do-pdf (member  "pdf" (ly:output-formats)))
-  (define paper (ly:paper-book-paper book))
+  (define do-pdf
+    (member  "pdf" (ly:output-formats)))
+
+  (define paper
+    (ly:paper-book-paper book))
+
   (define (dump-infinite-stack-EPS stencils)
     (let* ((dump-me (stack-stencils Y DOWN 2.0 stencils)))
       (dump-stencil-as-EPS paper dump-me basename #t)))
 
   (define (dump-counted-stencil stencil-count-pair)
-    "Return EPS filename" 
-    (let*
-       ((stencil (car stencil-count-pair))
-        (number (cdr stencil-count-pair))
-        (name (format "~a-~a" basename number)))
-
-      (dump-stencil-as-EPS
-       paper stencil name
-       (ly:get-option 'include-eps-fonts))
-
+    "Return EPS filename."
+    (let* ((stencil (car stencil-count-pair))
+          (number (cdr stencil-count-pair))
+          (name (format "~a-~a" basename number)))
+      (dump-stencil-as-EPS paper stencil name
+                          (ly:get-option 'include-eps-fonts))
       (string-append name ".eps")))
-  
+
   (define (dump-stencils-as-separate-EPS stencils count)
     (if (pair? stencils)
        (let* ((line (car stencils))
               (rest (cdr stencils))
-              (system-base-name (format "~a-~a" basename count))
-              )
-
-         (dump-stencil-as-EPS
-          paper line system-base-name)
-
+              (system-base-name (format "~a-~a" basename count)))
+         (dump-stencil-as-EPS paper line system-base-name)
          (if do-pdf
-             (postscript->pdf  0 0  (string-append system-base-name ".eps")))
+             (postscript->pdf 0 0
+                              (string-append system-base-name ".eps")))
          (dump-stencils-as-separate-EPS rest (1+ count)))))
 
-  ;; main body 
+  ;; main body
   (let* ((write-file (lambda (str-port ext)
-                      (let*
-                          ((name (format "~a-systems.~a" basename ext))
-                           (port (open-output-file name)))
+                      (let* ((name (format "~a-systems.~a" basename ext))
+                             (port (open-output-file name)))
                         (ly:message (_ "Writing ~a...") name)
                         (display (get-output-string str-port) port)
-                        (close-output-port port)
-                        )))
-        
+                        (close-output-port port))))
         (tex-system-port (open-output-string))
         (texi-system-port (open-output-string))
         (count-system-port (open-output-string))
         (widened-stencils (widen-left-stencil-edges stencils))
         (counted-systems  (count-list widened-stencils))
-        (eps-files (map dump-counted-stencil  counted-systems))
-        )
-    
+        (eps-files (map dump-counted-stencil counted-systems)))
     (if do-pdf
-
-       ;; par-for-each: a bit faster ...  
-       (for-each
-        (lambda (y)
-          (postscript->pdf 0 0 y))
-        eps-files))
-
+       ;; par-for-each: a bit faster ...
+       (for-each (lambda (y)
+                   (postscript->pdf 0 0 y))
+                 eps-files))
     (for-each (lambda (c)
                (if (< 0 c)
-                   (display (format "\\ifx\\betweenLilyPondSystem \\undefined
+                   (display (format
+                             "\\ifx\\betweenLilyPondSystem \\undefined
   \\linebreak
 \\else
   \\betweenLilyPondSystem{~a}
 \\fi
-" c) tex-system-port))
+" c)
+                            tex-system-port))
                (display (format "\\includegraphics{~a-~a}\n"
                                 basename (1+ c)) tex-system-port)
                (display (format "@image{~a-~a}\n"
                                 basename (1+ c)) texi-system-port))
              (iota (length stencils)))
-    
     (display "@c eof." texi-system-port)
     (display "% eof. " tex-system-port)
     (display (format "~a" (length stencils)) count-system-port)
     (dump-infinite-stack-EPS stencils)
     (postprocess-output book framework-eps-module
                        (format "~a.eps" basename) (ly:output-formats))
-
     (write-file texi-system-port "texi")
     (write-file tex-system-port "tex")
-
     ;; do this as the last action so we know the rest is complete if
     ;; this file is present.
-    (write-file count-system-port "count")
-    ))
-
-
+    (write-file count-system-port "count")))
 
 (define-public (output-classic-framework basename book scopes fields)
   (output-scopes scopes fields basename)
-
   (if (ly:get-option 'dump-signatures)
       (write-system-signatures basename (ly:paper-book-systems book) 1))
-  
-  (dump-stencils-as-EPSes
-   (map paper-system-stencil (ly:paper-book-systems book))
-   book
-   basename))
+  (dump-stencils-as-EPSes (map paper-system-stencil
+                              (ly:paper-book-systems book))
+                         book
+                         basename))
 
 (define-public (output-framework basename book scopes fields)
   (output-scopes scopes fields basename)
   (if (ly:get-option 'clip-systems)
       (clip-system-EPSes basename book))
-
-  (dump-stencils-as-EPSes
-   (map page-stencil (ly:paper-book-pages book)) book basename))
-  
+  (dump-stencils-as-EPSes (map page-stencil
+                              (ly:paper-book-pages book))
+                         book
+                         basename))
 
 ; redefine to imports from framework-ps
-(define convert-to-pdf convert-to-pdf)
-(define convert-to-ps convert-to-ps)
-(define convert-to-png convert-to-png)
+(define convert-to-pdf
+  convert-to-pdf)
+
+(define convert-to-ps
+  convert-to-ps)
+
+(define convert-to-png
+  convert-to-png)
index cfd72cf041be283e68984afdca24bcc1f7f549a1..8ccd3c04ed423797f0cb3e198f944ad975aca2df 100644 (file)
         (paper (ly:paper-book-paper book))
         (systems (ly:paper-book-systems book))
         (page-stencils (map page-stencil (ly:paper-book-pages book)))
-       
         (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t))
         (page-number (1- (ly:output-def-lookup paper 'first-page-number)))
         (page-count (length page-stencils))
         (port (ly:outputter-port outputter)))
-
-
     (if (ly:get-option 'clip-systems)
        (clip-system-EPSes basename book))
-
     (if (ly:get-option 'dump-signatures)
        (write-system-signatures basename (ly:paper-book-systems book) 1))
-
     (output-scopes scopes fields basename)
     (display (file-header paper page-count #t) port)
-
     ;; don't do BeginDefaults PageMedia: A4
     ;; not necessary and wrong
-
     (write-preamble paper #t port)
-
     (for-each
      (lambda (page)
        (set! page-number (1+ page-number))
        (dump-page outputter page page-number page-count landscape?))
      page-stencils)
-
     (display "%%Trailer\n%%EOF\n" port)
     (ly:outputter-close outputter)
     (postprocess-output book framework-ps-module filename
-                        (ly:output-formats))))
+                       (ly:output-formats))))
 
 (define-public (dump-stencil-as-EPS paper dump-me filename
                                    load-fonts)
-
-  (let*
-      ((xext (ly:stencil-extent dump-me X))
-       (yext (ly:stencil-extent dump-me Y))
-       (padding (ly:get-option 'eps-box-padding))
-       (left-overshoot (if (number? padding)
-                          (* -1 padding (ly:output-def-lookup paper 'mm))
-                          #f))
-       (bbox
-       (map
-        (lambda (x)
-          (if (or (nan? x) (inf? x)
+  (let* ((xext (ly:stencil-extent dump-me X))
+        (yext (ly:stencil-extent dump-me Y))
+        (padding (ly:get-option 'eps-box-padding))
+        (left-overshoot (if (number? padding)
+                            (* -1 padding (ly:output-def-lookup paper 'mm))
+                            #f))
+        (bbox
+         (map
+          (lambda (x)
+            (if (or (nan? x) (inf? x)
                     ;; FIXME: huh?
-                  (equal? (format #f "~S" x) "+#.#")
-                  (equal? (format #f "~S" x) "-#.#"))
-              0.0 x))
+                    (equal? (format #f "~S" x) "+#.#")
+                    (equal? (format #f "~S" x) "-#.#"))
+                0.0 x))
 
           ;; the left-overshoot is to make sure that
           ;; bar numbers stick out of margin uniformly.
           ;;
           (list
-       
            (if (number? left-overshoot)
                (min left-overshoot (car xext))
                (car xext))
            (car yext) (cdr xext) (cdr yext)))))
+    (dump-stencil-as-EPS-with-bbox paper dump-me filename load-fonts bbox)))
 
-       (dump-stencil-as-EPS-with-bbox paper dump-me filename load-fonts bbox)
-       ))
-       
-       
 (define-public (dump-stencil-as-EPS-with-bbox paper dump-me filename
                                              load-fonts
                                              bbox)
-  "Create an EPS file from stencil DUMP-ME to FILENAME. BBOX has format
-   (left-x, lower-y, right x, up-y).  If LOAD-FONTS set, include fonts inline."
-
+  "Create an EPS file from stencil DUMP-ME to FILENAME. BBOX has
+format (left-x, lower-y, right x, up-y).  If LOAD-FONTS set, include
+fonts inline."
   (define (to-rounded-bp-box box)
     "Convert box to 1/72 inch with rounding to enlarge the box."
     (let* ((scale (ly:output-def-lookup paper 'output-scale))
           (strip-non-number (lambda (x)
-                              (if (or (nan? x) (inf? x)) 0.0 x)))
+                              (if (or (nan? x)
+                                      (inf? x))
+                                  0.0
+                                  x)))
           (directed-round (lambda (x rounder)
                             (inexact->exact
                              (rounder (/ (* (strip-non-number x) scale)
       (list (directed-round (car box) floor)
            (directed-round (cadr box) floor)
            (directed-round (max (1+ (car box)) (caddr box)) ceiling)
-           (directed-round (max (1+ (cadr box)) (cadddr box)) ceiling)
-         )))
+           (directed-round (max (1+ (cadr box)) (cadddr box)) ceiling))))
 
   (let* ((outputter (ly:make-paper-outputter
                     ;; FIXME: better wrap open/open-file,
                     ;; MINGW hack: need to have "b"inary for embedding CFFs
                     (open-file (format "~a.eps" filename) "wb")
                     'ps))
-
         (port (ly:outputter-port outputter))
         (rounded-bbox (to-rounded-bp-box bbox))
         (port (ly:outputter-port outputter))
         (header (eps-header paper rounded-bbox load-fonts)))
-
     (display header port)
     (write-preamble paper load-fonts port)
     (display "gsave set-ps-scale-to-lily-scale\n" port)
     (display "stroke grestore\n%%Trailer\n%%EOF\n" port)
     (ly:outputter-close outputter)))
 
-
-
-(define (clip-systems-to-region
-        basename paper systems region
-        do-pdf)
-
-  (let*
-      ((extents-system-pairs
-       (filtered-map
-        (lambda (paper-system)
-          (let*
-              ((x-ext (system-clipped-x-extent
-                       (paper-system-system-grob paper-system)
-                       region)))
-
-            (if x-ext
-                (cons x-ext paper-system)
-                #f)))
-       
-        systems))
-       (count 0))
-
+(define (clip-systems-to-region basename paper systems region do-pdf)
+  (let* ((extents-system-pairs
+         (filtered-map (lambda (paper-system)
+                         (let* ((x-ext (system-clipped-x-extent
+                                        (paper-system-system-grob paper-system)
+                                        region)))
+                           (if x-ext
+                               (cons x-ext paper-system)
+                               #f)))
+                       systems))
+        (count 0))
     (for-each
      (lambda (ext-system-pair)
-       (let*
-          ((xext (car ext-system-pair))
-           (paper-system (cdr ext-system-pair))
-           (yext (paper-system-extent paper-system Y))
-           (bbox (list (car xext) (car yext)
-                       (cdr xext) (cdr yext)))
-           (filename (if (< 0 count)
-                         (format "~a-~a" basename count)
-                         basename)))
-
+       (let* ((xext (car ext-system-pair))
+             (paper-system (cdr ext-system-pair))
+             (yext (paper-system-extent paper-system Y))
+             (bbox (list (car xext) (car yext)
+                         (cdr xext) (cdr yext)))
+             (filename (if (< 0 count)
+                           (format "~a-~a" basename count)
+                           basename)))
         (set! count (1+ count))
-        (dump-stencil-as-EPS-with-bbox
-         paper
-         (paper-system-stencil paper-system)
-         filename
-         (ly:get-option 'include-eps-fonts)
-         bbox)
-
+        (dump-stencil-as-EPS-with-bbox paper
+                                       (paper-system-stencil paper-system)
+                                       filename
+                                       (ly:get-option 'include-eps-fonts)
+                                       bbox)
         (if do-pdf
-            (postscript->pdf 0 0 (format "~a.eps" filename)))
-        ))
-
-     extents-system-pairs)
-    ))
-
+            (postscript->pdf 0 0 (format "~a.eps" filename)))))
+     extents-system-pairs)))
 
 (define-public (clip-system-EPSes basename paper-book)
-  (define do-pdf (member "pdf" (ly:output-formats)))
+  (define do-pdf
+    (member "pdf" (ly:output-formats)))
 
   (define (clip-score-systems basename systems)
-    (let*
-       ((layout (ly:grob-layout (paper-system-system-grob (car systems))))
-        (regions (ly:output-def-lookup layout 'clip-regions)))
-
+    (let* ((layout (ly:grob-layout (paper-system-system-grob (car systems))))
+          (regions (ly:output-def-lookup layout 'clip-regions)))
       (for-each
        (lambda (region)
         (clip-systems-to-region
                  (rhythmic-location->file-string (cdr region)))
          layout systems region
          do-pdf))
-
        regions)))
 
-
   ;; partition in system lists sharing their layout blocks
-  (let*
-      ((systems (ly:paper-book-systems paper-book))
-       (count 0)
-       (score-system-list '()))
-
+  (let* ((systems (ly:paper-book-systems paper-book))
+        (count 0)
+        (score-system-list '()))
     (fold
      (lambda (system last-system)
-
-
        (if (not (and last-system
                     (equal? (paper-system-layout last-system)
                             (paper-system-layout system))))
           (set! score-system-list (cons '() score-system-list)))
-
        (if (paper-system-layout system)
           (set-car! score-system-list (cons system (car score-system-list))))
-
        ;; pass value.
        system)
-
      #f
      systems)
-
-    (for-each
-     (lambda (system-list)
-       (clip-score-systems
-       (if (> count 0)
-           (format "~a-~a" basename count)
-           basename)
-       system-list))
-
-     score-system-list)))
-
+    (for-each (lambda (system-list)
+               (clip-score-systems
+                (if (> count 0)
+                    (format "~a-~a" basename count)
+                    basename)
+                system-list))
+             score-system-list)))
 
 (define-public (output-preview-framework basename book scopes fields)
   (let* ((paper (ly:paper-book-paper book))
         (systems (ly:paper-book-systems book))
         (scale (ly:output-def-lookup paper 'output-scale))
         (to-dump-systems '()))
-
     ;; skip booktitles.
-    (if (and
-        (not (ly:get-option 'include-book-title-preview))
-        (pair? systems)
-        (ly:prob-property (car systems) 'is-book-title #f))
-
+    (if (and (not (ly:get-option 'include-book-title-preview))
+            (pair? systems)
+            (ly:prob-property (car systems) 'is-book-title #f))
        (set! systems (cdr systems)))
-
     (for-each
      (lambda (sys)
-       (if (or
-           (paper-system-title? sys)
-           (not (pair? to-dump-systems))
-           (paper-system-title? (car to-dump-systems)))
+       (if (or (paper-system-title? sys)
+              (not (pair? to-dump-systems))
+              (paper-system-title? (car to-dump-systems)))
           (set! to-dump-systems (cons sys to-dump-systems))))
      systems)
-
-    (dump-stencil-as-EPS
-     paper
-     (stack-stencils Y DOWN 0.0
-                    (map paper-system-stencil (reverse to-dump-systems)))
-     (format "~a.preview" basename)
-     #t)
-
+    (dump-stencil-as-EPS paper
+                        (stack-stencils Y DOWN 0.0
+                                        (map paper-system-stencil
+                                             (reverse to-dump-systems)))
+                        (format "~a.preview" basename)
+                        #t)
     (postprocess-output book framework-ps-module
                        (format "~a.preview.eps" basename)
                        (cons "png" (ly:output-formats)))))
 
 (if #f
     (define-public (output-preview-framework basename book scopes fields)
-
       (let* ((paper (ly:paper-book-paper book))
             (systems (ly:paper-book-systems book))
             (scale (ly:output-def-lookup paper 'output-scale))
        (dump-stencil-as-EPS paper dump-me
                             (format "~a.preview" basename)
                             #t)
-
        (postprocess-output book framework-ps-module
                            (format "~a.preview.eps" basename)
-                            (ly:output-formats)))))
+                           (ly:output-formats)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
   (let* ((defs (ly:paper-book-paper book))
         (landscape (ly:output-def-lookup defs 'landscape))
         (output-scale (ly:output-def-lookup defs 'output-scale))
-        (convert (lambda (x) (* x output-scale (/ (ly:bp 1)))))
-       
+        (convert (lambda (x)
+                   (* x output-scale (/ (ly:bp 1)))))
         (paper-width (convert (ly:output-def-lookup defs 'paper-width)))
         (paper-height (convert (ly:output-def-lookup defs 'paper-height)))
-
         (w (if landscape paper-height paper-width))
-        (h (if landscape paper-width paper-height))
-        )
-
+        (h (if landscape paper-width paper-height)))
     (if (equal? (basename name ".ps") "-")
        (ly:warning (_ "cannot convert <stdout> to ~S" "PDF"))
        (postscript->pdf w h name))))
         (paper-width (ly:output-def-lookup defs 'paper-width))
         (paper-height (ly:output-def-lookup defs 'paper-height))
         (output-scale (ly:output-def-lookup defs 'output-scale)))
-
     (postscript->png resolution
                     (* paper-width output-scale (/ (ly:bp 1)))
                     (* paper-height output-scale (/ (ly:bp 1)))
   #t)
 
 (define-public (output-classic-framework basename book scopes fields)
-
-  (ly:error (_ "\nThe PostScript backend does not support the system-by-system
-output.  For that, use the EPS backend instead,
+  (ly:error (_ "\nThe PostScript backend does not support the
+system-by-system output.  For that, use the EPS backend instead,
 
   lilypond -dbackend=eps FILE
 
index 655ea9888e6945ea7a2d3fe25048460cd293249a..2564aea75ffb98e0b50fc5ceb60c7c5325e6f50e 100644 (file)
@@ -15,7 +15,7 @@ classic lilypond-book:
 TODO:
 
   *  this script is too complex. Modularize.
-  
+
   *  ly-options: intertext?
   *  --line-width?
   *  eps in latex / eps by lilypond -b ps?
@@ -53,7 +53,7 @@ program_name = os.path.basename (sys.argv[0])
 
 # Check if program_version contains @ characters. This will be the case if
 # the .py file is called directly while building the lilypond documentation.
-# If so, try to check for the env var LILYPOND_VERSION, which is set by our 
+# If so, try to check for the env var LILYPOND_VERSION, which is set by our
 # makefiles and use its value.
 at_re = re.compile (r'@')
 if at_re.match (program_version):
@@ -155,18 +155,18 @@ def get_option_parser ():
                   action='store', dest='latex_program',
                   default='latex')
 
-    p.add_option ('--left-padding', 
+    p.add_option ('--left-padding',
                   metavar=_ ("PAD"),
                   dest="padding_mm",
                   help=_ ("pad left side of music to align music inspite of uneven bar numbers (in mm)"),
                   type="float",
                   default=3.0)
-    
+
     p.add_option ("-o", '--output', help=_ ("write output to DIR"),
                   metavar=_ ("DIR"),
                   action='store', dest='output_dir',
                   default='')
-    
+
     p.add_option ('--skip-lily-check',
                   help=_ ("do not fail if no lilypond output is found"),
                   metavar=_ ("DIR"),
@@ -178,16 +178,16 @@ def get_option_parser ():
                   metavar=_ ("DIR"),
                   action='store_true', dest='skip_png_check',
                   default=False)
-    
+
     p.add_option ('--lily-output-dir',
                   help=_ ("write lily-XXX files to DIR, link into --output dir"),
                   metavar=_ ("DIR"),
                   action='store', dest='lily_output_dir',
                   default=None)
-    
+
     p.add_option ('-P', '--process', metavar=_ ("COMMAND"),
                   help = _ ("process ly_files using COMMAND FILE..."),
-                  action='store', 
+                  action='store',
                   dest='process_cmd', default='')
 
     p.add_option ('--pdf',
@@ -290,6 +290,9 @@ no_options = {
 #
 #   (?P<name>regex) -- Assign result of REGEX to NAME.
 #   *? -- Match non-greedily.
+#   (?!...) -- Match if `...' doesn't match next (without consuming
+#              the string).
+#
 #   (?m) -- Multiline regex: Make ^ and $ match at each line.
 #   (?s) -- Make the dot match all characters including newline.
 #   (?x) -- Ignore whitespace in patterns.
@@ -303,17 +306,36 @@ snippet_res = {
         'lilypond':
          r'''(?smx)
           (?P<match>
-          <(?P<inline>(inline)?)mediaobject>\s*<textobject.*?>\s*<programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>(?P<code>.*?)</programlisting\s*>\s*</textobject\s*>\s*</(inline)?mediaobject>)''',
+          <(?P<inline>(inline)?)mediaobject>\s*
+          <textobject.*?>\s*
+          <programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>
+          (?P<code>.*?)
+          </programlisting\s*>\s*
+          </textobject\s*>\s*
+          </(inline)?mediaobject>)''',
 
         'lilypond_block':
          r'''(?smx)
           (?P<match>
-          <(?P<inline>(inline)?)mediaobject>\s*<textobject.*?>\s*<programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>(?P<code>.*?)</programlisting\s*>\s*</textobject\s*>\s*</(inline)?mediaobject>)''',
+          <(?P<inline>(inline)?)mediaobject>\s*
+          <textobject.*?>\s*
+          <programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>
+          (?P<code>.*?)
+          </programlisting\s*>\s*
+          </textobject\s*>\s*
+          </(inline)?mediaobject>)''',
 
         'lilypond_file':
          r'''(?smx)
           (?P<match>
-          <(?P<inline>(inline)?)mediaobject>\s*<imageobject.*?>\s*<imagedata\s+fileref="(?P<filename>.*?\.ly)"\s*(role="(?P<options>.*?)")?\s*(/>|>\s*</imagedata>)\s*</imageobject>\s*</(inline)?mediaobject>)''',
+          <(?P<inline>(inline)?)mediaobject>\s*
+          <imageobject.*?>\s*
+          <imagedata\s+
+           fileref="(?P<filename>.*?\.ly)"\s*
+           (role="(?P<options>.*?)")?\s*
+           (/>|>\s*</imagedata>)\s*
+          </imageobject>\s*
+          </(inline)?mediaobject>)''',
 
         'multiline_comment':
          r'''(?smx)
@@ -329,11 +351,11 @@ snippet_res = {
          no_match,
 
         'verbatim':
-       no_match,
+         no_match,
 
         'lilypondversion':
          no_match,
-    }, 
+    },
     ##
     HTML: {
         'include':
@@ -545,13 +567,11 @@ snippet_res = {
 }
 
 
-
-
 format_res = {
-    DOCBOOK: {        
-       'intertext': r',?\s*intertext=\".*?\"',
+    DOCBOOK: {
+        'intertext': r',?\s*intertext=\".*?\"',
         'option_sep': '\s*',
-    }, 
+    },
     HTML: {
         'intertext': r',?\s*intertext=\".*?\"',
         'option_sep': '\s*',
@@ -568,6 +588,7 @@ format_res = {
     },
 }
 
+
 # Options without a pattern in ly_options.
 simple_options = [
     EXAMPLEINDENT,
@@ -628,21 +649,37 @@ ly_options = {
 
 output = {
     ##
-    DOCBOOK: {                 
-        FILTER: r'''<mediaobject><textobject><programlisting language="lilypond" role="%(options)s">%(code)s</programlisting></textobject></mediaobject>''', 
-    
-        OUTPUT: r'''
-        <imageobject role="latex">
-               <imagedata fileref="%(base)s.pdf" format="PDF"/>
-               </imageobject>
-               <imageobject role="html">
-               <imagedata fileref="%(base)s.png" format="PNG"/></imageobject>''',
-    
-        VERBATIM: r'''<programlisting>%(verb)s</programlisting>''',
-        
+    DOCBOOK: {
+        FILTER: r'''<mediaobject>
+  <textobject>
+    <programlisting language="lilypond"
+                    role="%(options)s">
+%(code)s
+    </programlisting>
+  </textobject>
+</mediaobject>''',
+
+        OUTPUT: r'''<imageobject role="latex">
+  <imagedata fileref="%(base)s.pdf" format="PDF"/>
+</imageobject>
+<imageobject role="html">
+  <imagedata fileref="%(base)s.png" format="PNG"/>
+</imageobject>''',
+
+        VERBATIM: r'''<programlisting>
+%(verb)s</programlisting>''',
+
         VERSION: program_version,
-    
-        PRINTFILENAME: '<textobject><simpara><ulink url="%(base)s.ly"><filename>%(filename)s</filename></ulink></simpara></textobject>'
+
+        PRINTFILENAME: r'''<textobject>
+  <simpara>
+    <ulink url="%(base)s.ly">
+      <filename>
+        %(filename)s
+      </filename>
+    </ulink>
+  </simpara>
+</textobject>'''
     },
     ##
     HTML: {
@@ -659,8 +696,10 @@ output = {
  <a href="%(base)s.ly">''',
 
         OUTPUT: r'''
-  <img align="middle" 
-    border="0" src="%(image)s" alt="%(alt)s">''',
+  <img align="middle"
+       border="0"
+       src="%(image)s"
+       alt="%(alt)s">''',
 
         PRINTFILENAME: '<p><tt><a href="%(base)s.ly">%(filename)s</a></tt></p>',
 
@@ -678,23 +717,23 @@ output = {
     ##
     LATEX: {
         OUTPUT: r'''{%%
-\parindent 0pt%%
-\ifx\preLilyPondExample \undefined%%
- \relax%%
-\else%%
- \preLilyPondExample%%
-\fi%%
+\parindent 0pt
+\ifx\preLilyPondExample \undefined
+ \relax
+\else
+ \preLilyPondExample
+\fi
 \def\lilypondbook{}%%
-\input %(base)s-systems.tex%%
-\ifx\postLilyPondExample \undefined%%
- \relax%%
-\else%%
- \postLilyPondExample%%
-\fi%%
+\input %(base)s-systems.tex
+\ifx\postLilyPondExample \undefined
+ \relax
+\else
+ \postLilyPondExample
+\fi
 }''',
 
         PRINTFILENAME: '''\\texttt{%(filename)s}
-    ''',
+''',
 
         QUOTE: r'''\begin{quotation}%(str)s
 \end{quotation}''',
@@ -729,7 +768,9 @@ output = {
 <p>
  <a href="%(base)s.ly">
   <img align="middle"
-    border="0" src="%(image)s" alt="%(alt)s">
+       border="0"
+       src="%(image)s"
+       alt="%(alt)s">
  </a>
 </p>
 @end html
@@ -784,7 +825,7 @@ PREAMBLE_LY = '''%%%% Generated by %(program_name)s
 
 
 %% ****************************************************************
-%% Start cut-&-pastable-section 
+%% Start cut-&-pastable-section
 %% ****************************************************************
 
 %(preamble_string)s
@@ -866,7 +907,7 @@ def find_file (name, raise_error=True):
         full = os.path.join (i, name)
         if os.path.exists (full):
             return full
-        
+
     if raise_error:
         error (_ ("file not found: %s") % name + '\n')
         exit (1)
@@ -894,7 +935,7 @@ def verb_ly_gettext (s):
         return s
 
     s = ly_comment_re.sub (lambda m: ly_comment_gettext (t, m), s)
-    
+
     for v in ly_var_def_re.findall (s):
         s = re.sub (r"(?m)(^|[' \\#])%s([^a-zA-Z])" % v,
                     "\\1" + t (v) + "\\2",
@@ -940,7 +981,7 @@ class Chunk:
 
     def is_plain (self):
         return False
-    
+
 class Substring (Chunk):
     """A string that does not require extra memory."""
     def __init__ (self, source, start, end, line_number):
@@ -949,7 +990,7 @@ class Substring (Chunk):
         self.end = end
         self.line_number = line_number
         self.override_text = None
-        
+
     def is_plain (self):
         return True
 
@@ -1197,7 +1238,7 @@ class LilypondSnippet (Snippet):
 
             ## let's not create too long names.
             self.checksum = hash.hexdigest ()[:10]
-            
+
         return self.checksum
 
     def basename (self):
@@ -1237,7 +1278,7 @@ class LilypondSnippet (Snippet):
                 os.makedirs (dst_path)
             os.link (src, dst)
 
-        
+
     def all_output_files (self, output_dir, output_dir_files):
         """Return all files generated in lily_output_dir, a set.
 
@@ -1250,7 +1291,7 @@ class LilypondSnippet (Snippet):
         def consider_file (name):
             if name in output_dir_files:
                 result.add (name)
-             
+
         def require_file (name):
             if name in output_dir_files:
                 result.add (name)
@@ -1305,14 +1346,14 @@ class LilypondSnippet (Snippet):
             # markups do not output a signature.
             if 'ddump-signature' in global_options.process_cmd:
                 consider_file (systemfile + '.signature')
-             
-       
+
+
         return (result, missing)
-    
+
     def is_outdated (self, output_dir, current_files):
         found, missing = self.all_output_files (output_dir, current_files)
         return missing
-    
+
     def filter_text (self):
         """Run snippet bodies through a command (say: convert-ly).
 
@@ -1337,14 +1378,14 @@ class LilypondSnippet (Snippet):
         single = '%(base)s.png' % vars ()
         multiple = '%(base)s-page1.png' % vars ()
         images = (single,)
-        if (os.path.exists (multiple) 
+        if (os.path.exists (multiple)
             and (not os.path.exists (single)
                  or (os.stat (multiple)[stat.ST_MTIME]
                      > os.stat (single)[stat.ST_MTIME]))):
             count = ps_page_count ('%(base)s.eps' % vars ())
             images = ['%s-page%d.png' % (base, page) for page in range (1, count+1)]
             images = tuple (images)
-            
+
         return images
 
     def output_docbook (self):
@@ -1353,8 +1394,8 @@ class LilypondSnippet (Snippet):
         for image in self.get_images ():
             (base, ext) = os.path.splitext (image)
             str += output[DOCBOOK][OUTPUT] % vars ()
-           str += self.output_print_filename (DOCBOOK)
-            if (self.substring('inline') == 'inline'): 
+            str += self.output_print_filename (DOCBOOK)
+            if (self.substring('inline') == 'inline'):
                 str = '<inlinemediaobject>' + str + '</inlinemediaobject>'
             else:
                 str = '<mediaobject>' + str + '</mediaobject>'
@@ -1362,7 +1403,7 @@ class LilypondSnippet (Snippet):
                 verb = verbatim_html (self.verb_ly ())
                 str = output[DOCBOOK][VERBATIM] % vars () + str
         return str
-       
+
     def output_html (self):
         str = ''
         base = self.basename ()
@@ -1413,7 +1454,7 @@ class LilypondSnippet (Snippet):
         if 0:
             breaks = self.ly ().count ("\n")
             str += "".ljust (breaks, "\n").replace ("\n","%\n")
-        
+
         if QUOTE in self.option_dict:
             str = output[LATEX][QUOTE] % vars ()
         return str
@@ -1546,7 +1587,7 @@ def find_toplevel_snippets (input_string, format, types):
         for type in types:
             if not found[type] or found[type][0] < index:
                 found[type] = None
-                
+
                 m = res[type].search (input_string[index:endex])
                 if not m:
                     continue
@@ -1565,8 +1606,8 @@ def find_toplevel_snippets (input_string, format, types):
 
                 found[type] = (start, snip)
 
-            if (found[type] 
-                and (not first 
+            if (found[type]
+                and (not first
                      or found[type][0] < found[first][0])):
                 first = type
 
@@ -1599,7 +1640,7 @@ def find_toplevel_snippets (input_string, format, types):
 
 def filter_pipe (input, cmd):
     """Pass input through cmd, and return the result."""
-    
+
     if global_options.verbose:
         progress (_ ("Opening filter `%s'") % cmd)
 
@@ -1634,13 +1675,13 @@ def system_in_directory (cmd, directory):
 
     Because of win32 compatibility, we can't simply use subprocess.
     """
-    
+
     current = os.getcwd()
     os.chdir (directory)
-    ly.system(cmd, be_verbose=global_options.verbose, 
+    ly.system(cmd, be_verbose=global_options.verbose,
               progress_p=1)
     os.chdir (current)
-    
+
 
 def process_snippets (cmd, snippets,
                       format, lily_output_dir):
@@ -1648,14 +1689,14 @@ def process_snippets (cmd, snippets,
 
     if not snippets:
         return
-    
+
     if format in (HTML, TEXINFO) and '--formats' not in cmd:
         cmd += ' --formats=png '
     elif format in (DOCBOOK) and '--formats' not in cmd:
         cmd += ' --formats=png,pdf '
 
     checksum = snippet_list_checksum (snippets)
-    contents = '\n'.join (['snippet-map-%d.ly' % checksum] 
+    contents = '\n'.join (['snippet-map-%d.ly' % checksum]
                           + [snip.basename() + '.ly' for snip in snippets])
     name = os.path.join (lily_output_dir,
                          'snippet-names-%d.ly' % checksum)
@@ -1663,8 +1704,8 @@ def process_snippets (cmd, snippets,
 
     system_in_directory (' '.join ([cmd, ly.mkarg (name)]),
                          lily_output_dir)
-            
-        
+
+
 ###
 # Retrieve dimensions from LaTeX
 LATEX_INSPECTION_DOCUMENT = r'''
@@ -1682,13 +1723,13 @@ def get_latex_textwidth (source):
     m = re.search (r'''(?P<preamble>\\begin\s*{document})''', source)
     if m == None:
         warning (_ ("cannot find \\begin{document} in LaTeX document"))
-        
+
         ## what's a sensible default?
         return 550.0
-    
+
     preamble = source[:m.start (0)]
     latex_document = LATEX_INSPECTION_DOCUMENT % vars ()
-    
+
     (handle, tmpfile) = tempfile.mkstemp('.tex')
     logfile = os.path.splitext (tmpfile)[0] + '.log'
     logfile = os.path.split (logfile)[1]
@@ -1696,11 +1737,11 @@ def get_latex_textwidth (source):
     tmp_handle = os.fdopen (handle,'w')
     tmp_handle.write (latex_document)
     tmp_handle.close ()
-    
+
     ly.system ('%s %s' % (global_options.latex_program, tmpfile),
                be_verbose=global_options.verbose)
     parameter_string = file (logfile).read()
-    
+
     os.unlink (tmpfile)
     os.unlink (logfile)
 
@@ -1731,7 +1772,7 @@ def modify_preamble (chunk):
                r"\\usepackage{graphics}" + '\n'
                + r"\\begin{document}",
                str)
-        chunk.override_text = str 
+        chunk.override_text = str
 
 
 format2ext = {
@@ -1779,8 +1820,8 @@ def do_process_cmd (chunks, input_name, options):
 
     output_files = split_output_files (options.lily_output_dir)
     outdated = [c for c in snippets if c.is_outdated (options.lily_output_dir, output_files)]
-    
-    write_file_map (outdated, input_name)    
+
+    write_file_map (outdated, input_name)
     progress (_ ("Writing snippets..."))
     for snippet in outdated:
         snippet.write_ly()
@@ -1899,15 +1940,15 @@ def do_file (input_filename, included=False):
         global_options.output_dir = os.getcwd()
     else:
         global_options.output_dir = os.path.abspath(global_options.output_dir)
-        
+
         if not os.path.isdir (global_options.output_dir):
             os.mkdir (global_options.output_dir, 0777)
         os.chdir (global_options.output_dir)
 
     output_filename = os.path.join(global_options.output_dir,
                                    input_base + format2ext[global_options.format])
-    if (os.path.exists (input_filename) 
-        and os.path.exists (output_filename) 
+    if (os.path.exists (input_filename)
+        and os.path.exists (output_filename)
         and samefile (output_filename, input_fullname)):
      error (
      _ ("Output would overwrite input file; use --output."))
@@ -1955,7 +1996,7 @@ def do_file (input_filename, included=False):
             write_if_updated (output_filename,
                      [s.replacement_text ()
                      for s in chunks])
-        
+
         def process_include (snippet):
             os.chdir (original_dir)
             name = snippet.substring ('filename')
@@ -1968,7 +2009,7 @@ def do_file (input_filename, included=False):
                                       chunks))
 
         return chunks + reduce (lambda x, y: x + y, include_chunks, [])
-        
+
     except CompileError:
         os.chdir (original_dir)
         progress (_ ("Removing `%s'") % output_filename)
@@ -1984,14 +2025,14 @@ def do_options ():
         global_options.format = TEXINFO
 
     global_options.include_path =  map (os.path.abspath, global_options.include_path)
-    
+
     if global_options.warranty:
         warranty ()
         exit (0)
     if not args or len (args) > 1:
         opt_parser.print_help ()
         exit (2)
-        
+
     return args
 
 def main ():
@@ -2000,7 +2041,7 @@ def main ():
 
     basename = os.path.splitext (files[0])[0]
     basename = os.path.split (basename)[1]
-    
+
     if not global_options.format:
         global_options.format = guess_format (files[0])
 
@@ -2009,7 +2050,7 @@ def main ():
         formats += ',png'
 
     if global_options.process_cmd == '':
-        global_options.process_cmd = (lilypond_binary 
+        global_options.process_cmd = (lilypond_binary
                                       + ' --formats=%s -dbackend=eps ' % formats)
 
     if global_options.process_cmd:
@@ -2026,13 +2067,13 @@ def main ():
         global_options.process_cmd += ' --formats=eps '
         if global_options.create_pdf:
             global_options.process_cmd += "--pdf -dinclude-eps-fonts -dgs-load-fonts "
-    
+
     if global_options.verbose:
         global_options.process_cmd += " --verbose "
 
     if global_options.padding_mm:
         global_options.process_cmd += " -deps-box-padding=%f " % global_options.padding_mm
-        
+
     global_options.process_cmd += " -dread-file-list -dno-strip-output-dir"
 
     if global_options.lily_output_dir:
@@ -2041,7 +2082,7 @@ def main ():
             os.makedirs (global_options.lily_output_dir)
     else:
         global_options.lily_output_dir = os.path.abspath(global_options.output_dir)
-        
+
 
     identify ()
     try:
@@ -2057,7 +2098,7 @@ def main ():
     final_output_file = os.path.join (global_options.output_dir,
                      base_file_name
                      + '.%s' % global_options.format)
-    
+
     os.chdir (original_dir)
     file (dep_file, 'w').write ('%s: %s'
                                 % (final_output_file, ' '.join (inputs)))
index bc9dcc9201355f15d5eb99b3a87b78ebfba0d633..9f275d7041dafd07eff9077712c43975dc4f382b 100644 (file)
@@ -1,7 +1,8 @@
 depth = ..
 
-TEX_FILES = $(filter-out texinfo.tex, $(call src-wildcard,*.tex))
-EXTRA_DIST_FILES = $(TEX_FILES) texinfo.tex
+TEXINFO_FILES = texinfo.tex $(call src-wildcard,txi-*.tex)
+TEX_FILES = $(filter-out $TEXINFO_FILES,$(call src-wildcard,*.tex))
+EXTRA_DIST_FILES = $(TEX_FILES) $(TEXINFO_FILES)
 STEPMAKE_TEMPLATES = install install-out
 
 INSTALLATION_DIR = $(local_lilypond_datadir)/tex/