1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (scm framework-ps))
20 ;;; this is still too big a mess.
22 (use-modules (ice-9 string-fun)
31 (define format ergonomic-simple-format)
33 (define framework-ps-module (current-module))
35 ;;(define pdebug stderr)
36 (define (pdebug . rest) #f)
38 (define-public (ps-font-command font)
39 (let* ((name (ly:font-file-name font))
40 (magnify (ly:font-magnification font)))
49 "m" (string-encode-integer (inexact->exact (round (* 1000 magnify)))))))
51 (define (ps-define-pango-pf pango-pf font-name scaling)
54 (define (ps-define-font font font-name scaling)
57 "/" (ps-font-command font) "-N"
59 " " (ly:number->string scaling) " output-scale div selectfont }"
61 "/" (ps-font-command font) "-S"
63 " " (ly:number->string scaling) " output-scale div selectfont }"
65 "/" (ps-font-command font) "-O"
67 " " (ly:number->string scaling) " output-scale div selectfont }"
69 "/help" font-name " {\n gsave\n 1 setgray\n /"
71 " 0.001 selectfont 0 0 moveto <01> show\n /"
73 " 0.001 selectfont 0 0 moveto <01> show\n /"
75 " 0.001 selectfont 0 0 moveto <01> show\n grestore\n} def\n")
77 "/" (ps-font-command font)
79 " " (ly:number->string scaling) " output-scale div selectfont }"
82 ;; FIXME: duplicated in other output backends
83 ;; FIXME: silly interface name
84 (define (output-variables layout)
85 ;; FIXME: duplicates output-layout's scope-entry->string, mostly
86 (define (value->string val)
88 ((string? val) (string-append "(" val ")"))
89 ((symbol? val) (symbol->string val))
90 ((number? val) (number->string val))
93 (define (output-entry ps-key ly-key)
96 (value->string (ly:output-def-lookup layout ly-key)) " def\n"))
100 (number->string (/ (ly:bp 1))) " def %% millimeter\n"
101 (output-entry "staff-line-thickness" 'line-thickness)
102 (output-entry "line-width" 'line-width)
103 (output-entry "paper-size" 'papersizename)
104 (output-entry "staff-height" 'staff-height) ;junkme.
106 (number->string (ly:output-def-lookup layout 'output-scale)) " def\n"
107 (output-entry "page-height" 'paper-height)
108 (output-entry "page-width" 'paper-width)
109 (if (ly:get-option 'strokeadjust) "true setstrokeadjust\n" "")
112 (define (dump-page outputter page page-number page-count landscape?)
113 (ly:outputter-dump-string
116 (format #f "%%Page: ~a ~a\n" page-number page-number)
119 "page-width output-scale lily-output-units mul mul 0 translate 90 rotate\n"
123 "gsave 0 paper-height translate set-ps-scale-to-lily-scale\n"
124 "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n"
125 "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n"
126 "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n"
127 "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n"
128 "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n"
129 "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n"
130 "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n"
131 "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n"
132 "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n"))
133 (ly:outputter-dump-stencil outputter page)
134 (ly:outputter-dump-string outputter "stroke grestore\nshowpage\n"))
136 (define (supplies-or-needs paper load-fonts?)
137 (define (extract-names font)
138 (if (ly:pango-font? font)
139 (map car (ly:pango-font-physical-fonts font))
140 (list (ly:font-name font))))
142 (let* ((fonts (ly:paper-fonts paper))
143 (names (append-map extract-names fonts)))
148 "%%DocumentSuppliedResources: font ~a\n"
149 "%%DocumentNeededResources: font ~a\n")
151 (uniq-list (sort names string<?))))))
153 (define (eps-header paper bbox load-fonts?)
154 (string-append "%!PS-Adobe-2.0 EPSF-2.0\n"
155 "%%Creator: LilyPond " (lilypond-version) "\n"
157 (string-join (map ly:number->string bbox) " ") "\n"
159 (if (eq? (ly:output-def-lookup paper 'landscape) #t)
162 (supplies-or-needs paper load-fonts?)
165 (define (ps-document-media paper)
167 (ly:output-def-lookup paper 'output-scale)
168 (ly:output-def-lookup paper 'paper-width)) (ly:bp 1)))
170 (ly:output-def-lookup paper 'paper-height)
171 (ly:output-def-lookup paper 'output-scale))
173 (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t)))
174 (ly:format "%%DocumentMedia: ~a ~2f ~2f ~a ~a ~a\n"
175 (ly:output-def-lookup paper 'papersizename)
183 (define (file-header paper page-count load-fonts?)
184 (string-append "%!PS-Adobe-3.0\n"
185 "%%Creator: LilyPond " (lilypond-version) "\n"
186 "%%Pages: " (number->string page-count) "\n"
187 "%%PageOrder: Ascend\n"
189 (if (eq? (ly:output-def-lookup paper 'landscape) #t)
192 (ps-document-media paper)
193 (supplies-or-needs paper load-fonts?)
196 (define (procset file-name)
198 "%%BeginResource: procset (~a) 1 0
202 file-name (cached-file-contents file-name)))
204 (define (embed-document file-name)
205 (format #f "%%BeginDocument: ~a
209 file-name (cached-file-contents file-name)))
211 (define (setup-variables paper)
214 (define-fonts paper ps-define-font ps-define-pango-pf)
215 (output-variables paper)))
217 (define (cff-font? font)
218 (let* ((cff-string (ly:otf-font-table-data font "CFF ")))
219 (> (string-length cff-string) 0)))
221 (define-public (ps-embed-cff body font-set-name version)
224 (format #f "/~a ~s StartData " font-set-name (string-length body))
228 "%%BeginResource: font ~a
229 %!PS-Adobe-3.0 Resource-FontSet
230 %%DocumentNeededResources: ProcSet (FontSetInit)
231 %%Title: (FontSet/~a)
234 %%IncludeResource: ProcSet (FontSetInit)
235 %%BeginResource: FontSet (~a)
236 /FontSetInit /ProcSet findresource begin
237 %%BeginData: ~s Binary Bytes
239 font-set-name font-set-name version font-set-name
240 (string-length binary-data)))
244 (string-append header
248 (define (write-preamble paper load-fonts? port)
249 (define (internal-font? file-name)
250 (or (string-startswith file-name "Emmentaler")
251 (string-startswith file-name "emmentaler")
254 (define (load-font-via-GS font-name-filename)
255 (define (ps-load-file file-name)
256 (if (string? file-name)
257 (if (string-contains file-name (ly:get-option 'datadir))
259 (set! file-name (ly:string-substitute (ly:get-option 'datadir)
262 "lilypond-datadir (~a) concatstrings (r) file .loadfont\n"
264 (format #f "(~a) (r) file .loadfont\n" file-name))
265 (format #f "% cannot find font file: ~a\n" file-name)))
267 (let* ((font (car font-name-filename))
268 (name (cadr font-name-filename))
269 (file-name (caddr font-name-filename))
270 (bare-file-name (ly:find-file file-name)))
272 (if (mac-font? bare-file-name)
273 (handle-mac-font name bare-file-name)
275 ((internal-font? file-name)
276 (ps-load-file (ly:find-file
277 (format #f "~a.otf" file-name))))
278 ((string? bare-file-name)
279 (ps-load-file file-name))
281 (ly:warning (_ "cannot embed ~S=~S") name file-name)
284 (define (dir-join a b)
287 (string-append a "/" b)))
289 (define (dir-listing dir-name)
290 (define (dir-helper dir lst)
291 (let ((e (readdir dir)))
294 (dir-helper dir (cons e lst)))))
295 (reverse (dir-helper (opendir dir-name) '())))
297 (define (handle-mac-font name file-name)
298 (let* ((dir-name (tmpnam))
303 (mkdir dir-name #o700)
305 (set! status (ly:system (list "fondu" "-force" file-name)))
307 (set! files (dir-listing dir-name))
310 (let* ((full-name (dir-join dir-name f)))
312 (equal? 'regular (stat:type (stat full-name)))
313 (equal? name (ly:ttf-ps-name full-name)))
314 (set! embed (font-file-as-ps-string name full-name 0)))
315 (if (or (equal? "." f)
318 (delete-file full-name))))
323 (set! embed "% failed\n")
324 (ly:warning (_ "cannot extract file matching ~a from ~a")
328 (define (font-file-as-ps-string name file-name font-index)
329 (let* ((downcase-file-name (string-downcase file-name)))
331 ((and file-name (string-endswith downcase-file-name ".pfa"))
332 (embed-document file-name))
333 ((and file-name (string-endswith downcase-file-name ".pfb"))
334 (ly:pfb->pfa file-name))
335 ((and file-name (string-endswith downcase-file-name ".ttf"))
336 (ly:ttf->pfa file-name))
337 ((and file-name (string-endswith downcase-file-name ".ttc"))
338 (ly:ttf->pfa file-name font-index))
339 ((and file-name (string-endswith downcase-file-name ".otf"))
340 (ps-embed-cff (ly:otf->cff file-name) name 0))
342 (ly:warning (_ "do not know how to embed ~S=~S") name file-name)
345 (define (mac-font? bare-file-name)
346 (and (eq? PLATFORM 'darwin)
348 (or (string-endswith bare-file-name ".dfont")
349 (= (stat:size (stat bare-file-name)) 0))))
351 (define (load-font font-psname-filename-fontindex)
352 (let* ((font (list-ref font-psname-filename-fontindex 0))
353 (name (list-ref font-psname-filename-fontindex 1))
354 (file-name (list-ref font-psname-filename-fontindex 2))
355 (font-index (list-ref font-psname-filename-fontindex 3))
356 (bare-file-name (ly:find-file file-name)))
358 (cond ((mac-font? bare-file-name)
359 (handle-mac-font name bare-file-name))
360 ((and font (cff-font? font))
361 (ps-embed-cff (ly:otf-font-table-data font "CFF ")
364 (bare-file-name (font-file-as-ps-string
365 name bare-file-name font-index))
367 (ly:warning (_ "do not know how to embed font ~s ~s ~s")
368 name file-name font))))))
370 (define (load-fonts paper)
371 (let* ((fonts (ly:paper-fonts paper))
373 ;; todo - doc format of list.
377 (cond ((string? (ly:font-file-name font))
380 (ly:font-file-name font)
382 ((ly:pango-font? font)
383 (map (lambda (psname-filename-fontindex)
385 (list-ref psname-filename-fontindex 0)
386 (list-ref psname-filename-fontindex 1)
387 (list-ref psname-filename-fontindex 2)))
388 (ly:pango-font-physical-fonts font)))
390 (ly:font-sub-fonts font))))
392 (font-names (uniq-list
393 (sort (concatenate all-font-names)
394 (lambda (x y) (string<? (cadr x) (cadr y))))))
396 ;; slightly spaghetti-ish: deciding what to load where
400 (cond ((ly:get-option 'gs-load-fonts)
401 (load-font-via-GS name))
402 ((ly:get-option 'gs-load-lily-fonts)
403 (if (or (string-contains (caddr name)
404 (ly:get-option 'datadir))
405 (internal-font? (caddr name)))
406 (load-font-via-GS name)
410 (pfas (map font-loader font-names)))
414 (display "%%BeginProlog\n" port)
417 "/lilypond-datadir where {pop} {userdict /lilypond-datadir (~a) put } ifelse"
418 (ly:get-option 'datadir))
420 (for-each (lambda (f)
421 (format port "\n%%BeginFont: ~a\n" (car f))
422 (display (cdr f) port)
423 (display "%%EndFont\n" port))
426 (display (procset "encodingdefs.ps") port))
427 (display (setup-variables paper) port)
429 ;; adobe note 5002: should initialize variables before loading routines.
430 (display (procset "music-drawing-routines.ps") port)
431 (display (procset "lilyponddefs.ps") port)
432 (display "%%EndProlog\n" port)
433 (display "%%BeginSetup\ninit-lilypond-parameters\n%%EndSetup\n\n" port))
435 (define (ps-quote str)
437 (lambda (replacement-list result)
441 (car replacement-list))
442 (cadr replacement-list)))
444 '((#\\ "\\\\") (#\( "\\(") (#\) "\\)"))))
446 ;;; Create DOCINFO pdfmark containing metadata
447 ;;; header fields with pdf prefix override those without the prefix
448 (define (handle-metadata header port)
449 (define (metadata-encode val)
450 ;; First, call ly:encode-string-for-pdf to encode the string (latin1 or
451 ;; utf-16be), then escape all parentheses and backslashes
452 ;; FIXME guile-2.0: use (string->utf16 str 'big) instead
454 (ps-quote (ly:encode-string-for-pdf val)))
455 (define (metadata-lookup-output overridevar fallbackvar field)
456 (let* ((overrideval (ly:modules-lookup (list header) overridevar))
457 (fallbackval (ly:modules-lookup (list header) fallbackvar))
458 (val (if overrideval overrideval fallbackval)))
460 (format port "/~a (~a)\n" field (metadata-encode (markup->string val (list header)))))))
462 (metadata-lookup-output 'pdfcomposer 'composer "Author")
463 (format port "/Creator (LilyPond ~a)\n" (lilypond-version))
464 (metadata-lookup-output 'pdftitle 'title "Title")
465 (metadata-lookup-output 'pdfsubject 'subject "Subject")
466 (metadata-lookup-output 'pdfkeywords 'keywords "Keywords")
467 (metadata-lookup-output 'pdfmodDate 'modDate "ModDate")
468 (metadata-lookup-output 'pdfsubtitle 'subtitle "Subtitle")
469 (metadata-lookup-output 'pdfcomposer 'composer "Composer")
470 (metadata-lookup-output 'pdfarranger 'arranger "Arranger")
471 (metadata-lookup-output 'pdfpoet 'poet "Poet")
472 (metadata-lookup-output 'pdfcopyright 'copyright "Copyright")
473 (display "/DOCINFO pdfmark\n\n" port))
476 (define-public (output-framework basename book scopes fields)
477 (let* ((port-tmp (make-tmpfile))
478 (tmp-name (port-filename port-tmp))
479 (outputter (ly:make-paper-outputter
482 (paper (ly:paper-book-paper book))
483 (header (ly:paper-book-header book))
484 (systems (ly:paper-book-systems book))
485 (page-stencils (map page-stencil (ly:paper-book-pages book)))
486 (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t))
487 (page-number (1- (ly:output-def-lookup paper 'first-page-number)))
488 (page-count (length page-stencils))
489 (port (ly:outputter-port outputter)))
490 (if (ly:get-option 'clip-systems)
491 (clip-system-EPSes basename book))
492 (if (ly:get-option 'dump-signatures)
493 (write-system-signatures basename (ly:paper-book-systems book) 1))
494 (output-scopes scopes fields basename)
495 (display (file-header paper page-count #t) port)
496 ;; don't do BeginDefaults PageMedia: A4
497 ;; not necessary and wrong
498 (write-preamble paper #t port)
500 (handle-metadata header port))
503 (set! page-number (1+ page-number))
504 (dump-page outputter page page-number page-count landscape?))
506 (display "%%Trailer\n%%EOF\n" port)
507 (ly:outputter-close outputter)
508 (postprocess-output book framework-ps-module (ly:output-formats)
509 basename tmp-name #f)))
511 (define-public (dump-stencil-as-EPS paper dump-me filename
513 (let* ((xext (ly:stencil-extent dump-me X))
514 (yext (ly:stencil-extent dump-me Y))
515 (padding (ly:get-option 'eps-box-padding))
516 (left-overshoot (if (number? padding)
517 (* -1 padding (ly:output-def-lookup paper 'mm))
522 (if (or (nan? x) (inf? x)
524 (equal? (format #f "~S" x) "+#.#")
525 (equal? (format #f "~S" x) "-#.#"))
528 ;; the left-overshoot is to make sure that
529 ;; bar numbers stick out of margin uniformly.
532 (if (number? left-overshoot)
533 (min left-overshoot (car xext))
535 (car yext) (cdr xext) (cdr yext)))))
536 (dump-stencil-as-EPS-with-bbox paper dump-me filename load-fonts bbox)))
538 (define-public (dump-stencil-as-EPS-with-bbox paper dump-me filename
541 "Create an EPS file from stencil @var{dump-me} to @var{filename}.
542 @var{bbox} has format @code{(left-x, lower-y, right-x, upper-y)}. If
543 @var{load-fonts} set, include fonts inline."
544 (define (to-rounded-bp-box box)
545 "Convert box to 1/72 inch with rounding to enlarge the box."
546 (let* ((scale (ly:output-def-lookup paper 'output-scale))
547 (strip-non-number (lambda (x)
552 (directed-round (lambda (x rounder)
554 (rounder (/ (* (strip-non-number x) scale)
556 (list (directed-round (car box) floor)
557 (directed-round (cadr box) floor)
558 (directed-round (max (1+ (car box)) (caddr box)) ceiling)
559 (directed-round (max (1+ (cadr box)) (cadddr box)) ceiling))))
561 (let* ((outputter (ly:make-paper-outputter
562 ;; FIXME: better wrap open/open-file,
563 ;; content-mangling is always bad.
564 ;; MINGW hack: need to have "b"inary for embedding CFFs
565 (open-file (format #f "~a.eps" filename) "wb")
567 (port (ly:outputter-port outputter))
568 (rounded-bbox (to-rounded-bp-box bbox))
569 (port (ly:outputter-port outputter))
570 (header (eps-header paper rounded-bbox load-fonts)))
571 (display header port)
572 (write-preamble paper load-fonts port)
573 (display "/mark_page_link { pop pop pop pop pop } bind def\n" port)
574 (display "gsave set-ps-scale-to-lily-scale\n" port)
575 (display "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n" port)
576 (display "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n" port)
577 (display "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n" port)
578 (display "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n" port)
579 (display "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n" port)
580 (display "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n" port)
581 (display "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n" port)
582 (display "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n" port)
583 (display "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n" port)
584 (ly:outputter-dump-stencil outputter dump-me)
585 (display "stroke grestore\n%%Trailer\n%%EOF\n" port)
586 (ly:outputter-close outputter)))
588 (define (clip-systems-to-region basename paper systems region do-pdf do-png)
589 (let* ((extents-system-pairs
590 (filtered-map (lambda (paper-system)
591 (let* ((x-ext (system-clipped-x-extent
592 (paper-system-system-grob paper-system)
595 (cons x-ext paper-system)
600 (lambda (ext-system-pair)
601 (let* ((xext (car ext-system-pair))
602 (paper-system (cdr ext-system-pair))
603 (yext (paper-system-extent paper-system Y))
604 (bbox (list (car xext) (car yext)
605 (cdr xext) (cdr yext)))
606 (filename (if (< 0 count)
607 (format #f "~a-~a" basename count)
609 (set! count (1+ count))
610 (dump-stencil-as-EPS-with-bbox paper
611 (paper-system-stencil paper-system)
613 (ly:get-option 'include-eps-fonts)
616 (postscript->pdf 0 0 filename (format #f "~a.eps" filename) #t))
618 (postscript->png (ly:get-option 'resolution) 0 0
619 filename (format #f "~a.eps" filename) #t))))
620 extents-system-pairs)))
622 (define-public (clip-system-EPSes basename paper-book)
624 (member "pdf" (ly:output-formats)))
626 (member "png" (ly:output-formats)))
628 (define (clip-score-systems basename systems)
629 (let* ((layout (ly:grob-layout (paper-system-system-grob (car systems))))
630 (regions (ly:output-def-lookup layout 'clip-regions)))
633 (clip-systems-to-region
634 (format #f "~a-from-~a-to-~a-clip"
636 (rhythmic-location->file-string (car region))
637 (rhythmic-location->file-string (cdr region)))
638 layout systems region
642 ;; partition in system lists sharing their layout blocks
643 (let* ((systems (ly:paper-book-systems paper-book))
645 (score-system-list '()))
647 (lambda (system last-system)
648 (if (not (and last-system
649 (equal? (paper-system-layout last-system)
650 (paper-system-layout system))))
651 (set! score-system-list (cons '() score-system-list)))
652 (if (paper-system-layout system)
653 (set-car! score-system-list (cons system (car score-system-list))))
658 (for-each (lambda (system-list)
659 ;; filter out headers and top-level markup
660 (if (pair? system-list)
663 (format #f "~a-~a" basename count)
668 (define-public (output-preview-framework basename book scopes fields)
669 (let* ((paper (ly:paper-book-paper book))
670 (systems (relevant-book-systems book))
671 (to-dump-systems (relevant-dump-systems systems)))
672 (dump-stencil-as-EPS paper
673 (stack-stencils Y DOWN 0.0
674 (map paper-system-stencil
675 (reverse to-dump-systems)))
676 (format #f "~a.preview" basename)
678 (postprocess-output book framework-ps-module
679 (cons "png" (ly:output-formats))
680 (format #f "~a.preview" basename)
681 (format #f "~a.preview.eps" basename)
685 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
687 (define (output-width-height defs)
688 (let* ((landscape (ly:output-def-lookup defs 'landscape))
689 (output-scale (ly:output-def-lookup defs 'output-scale))
691 (* x output-scale (/ (ly:bp 1)))))
692 (paper-width (convert (ly:output-def-lookup defs 'paper-width)))
693 (paper-height (convert (ly:output-def-lookup defs 'paper-height)))
694 (w (if landscape paper-height paper-width))
695 (h (if landscape paper-width paper-height)))
698 (define (output-resolution defs)
699 (let ((defs-resolution (ly:output-def-lookup defs 'pngresolution)))
700 (if (number? defs-resolution)
702 (ly:get-option 'resolution))))
704 (define-public (convert-to-pdf book base-name tmp-name is-eps)
705 (let* ((defs (ly:paper-book-paper book))
706 (width-height (output-width-height defs))
707 (width (car width-height))
708 (height (cdr width-height)))
709 (postscript->pdf width height base-name tmp-name is-eps)))
711 (define-public (convert-to-png book base-name tmp-name is-eps)
712 (let* ((defs (ly:paper-book-paper book))
713 (resolution (output-resolution defs))
714 (width-height (output-width-height defs))
715 (width (car width-height))
716 (height (cdr width-height)))
717 (postscript->png resolution width height base-name tmp-name is-eps)))
719 (define-public (convert-to-ps book base-name tmp-name is-eps)
720 (postscript->ps base-name tmp-name is-eps))
722 (define-public (output-classic-framework basename book scopes fields)
723 (ly:error (_ "\nThe PostScript backend does not support the
724 system-by-system output. For that, use the EPS backend instead,
726 lilypond -dbackend=eps FILE
728 If have cut & pasted a lilypond fragment from a webpage, be sure
729 to only remove anything before
731 %% ****************************************************************
732 %% Start cut-&-pastable-section
733 %% ****************************************************************