Hello lists,

I made up a markup command, to include latex-formatted text. Well, I don't want to "get rid of lilypond-book" like some people wrote on this list, but I want the oppertunity, to include a well formatted text on my first page of a book with several pieces of music. I used to take http://lsr.dsi.unimi.it/LSR/Snippet?id=586 for making paragraphs. But that one lacks hyphenation (in this example, hyphenation fails in some lines, but thats a xelatex issue) and doesn't look as balanced as latex generated output. And I haven't found a way, to produce two column output with markup-lines (did I overlook something?).

So here is what I do:
- create a temporary tex-file from a markup with paper size set with the geometry package
- process it with xelatex (from texlive 2009 on ubuntu lucid)
- convert it with pdftops (from texlive 2009 on ubuntu lucid)
- return the eps-stencil

Now this is just a proof of concept, trial or whatever.
Problems for now:
- The paragraph command is able to pagebreak, this include variant isn't - right now.
- The height of the resulting text-box has to be found by trial and error.
- Dependency on unrelated software
TBD: error checks

Does anybody has quick answer to the following questions?
- How can I determine the page height in staff-space or cm?
Not lilypond-related, but probably someone knows ;-)
- How can I crop an EPS to the actually visual size

If I have answers to these questions, I could detetermine the page-count of the temporary pdf and create <basename>-[1...].eps files and create a markup-list-command.

Well, probably one should use lilypond-book, produce the lilypdf and include that in another PDF with an external tool or use the snippet mentioned above. But I also thought about using this technique to improve e.g. footnote-markups (with hyphenation etc...).

What do you think? Suggestions welcome.
Cheers, Jan-Peter

\version "2.14.2"

% This example assumes an environment with xelatex and pdftops available in PATH

% if set later, paperScale is not updated!
#(set-global-staff-size 16)

% how is the staff-scaling
#(define-public paperScale 1.0)
\paper {
  #(set! paperScale (/ (* 1 cm) staff-space))
}

% get a string from a markup
% TBD convert bold, italic, etc. to latex-commands
% (snippet taken from the list)
#(define (markup->string mup conc)
        (let ((result ""))
             (map (lambda (x)
                          (begin
                            ;; if this is a concat-markup, do not insert blanks between string
                            (if (eq? x concat-markup)(set! conc #t))
                            (if (list? x)
                                (set! result 
                                  ;; if we are concatenating or we start with an empty result, don't add a blank
                                  (if (or conc (string=? result ""))
                                      (string-append result (markup->string x conc))
                                      (string-append result " " (markup->string x conc)))))
                            (if (string? x)
                                (set! result 
                                  ;; if we are concatenating or we start with an empty result, don't add a blank
                                  (if (or conc (string=? result ""))
                                      (string-append result x)
                                      (string-append result " " x))))
                            result))
                  mup)
             result)
)
% xetex markup command (could also be done with pdflatex)
#(define-markup-command (xetex layout props size m)(number? markup-list?)
  (let (
         ; width of our box in cm
         (width (/ (chain-assoc-get 'line-width props 0) paperScale))
         ; height of our box in cm
         (height (/ size paperScale))
         ; the text to fill into template.tex
         (text (markup->string m #f))
         ; basename of working files
         (basename (strftime "xelatex-%Y%m%d%H%M%S" (localtime (current-time))))
         ; result of each command
         (result 0)
         ; stencil to return
         (text-stencil empty-stencil))
       ; write <basename>.tex
       (with-output-to-file (format "~A.tex" basename) (lambda ()
                 (display (format "\\documentclass{scrartcl}
\\usepackage[paperwidth=~Acm,paperheight=~Acm,margin=1mm]{geometry}
\\usepackage[ngerman]{babel}
\\usepackage{fontspec}
\\setmainfont{DejaVu Sans}
\\begin{document}
~A
\\end{document}
" width height text))))
       ; produce pdf
       (set! result (system (format "xelatex \"~A.tex\"" basename)))
       ; convert first page to EPS
       (set! result (system (format "pdftops -eps -f 1 -l 1 \"~A.pdf\"" basename)))
       
       ; include EPS
       (set! text-stencil (eps-file->stencil Y size (format "~A.eps" basename)))
       ; remove working files
       (system (format "rm -v \"~A\".*" basename))
       ; return eps-stencil
       text-stencil
))

%%%%%%%%%%%%%%%%%%%%%%% Test
\markup \column {
  \box \xetex #45 {
    Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
    Aenean commodo ligula eget dolor. Aenean massa. 
    Cum sociis natoque penatibus et magnis dis parturient montes, 
    nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. 
    Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. 
    In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. 
    Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. 
    Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. 
    Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. 
    Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. 
    Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper 
    ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget 
    condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. 
    Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. 
    Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. 
    Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. 
  }
  \box {
    \override #'(line-width . 50)
    \xetex #90 {
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. 
      Aenean commodo ligula eget dolor. Aenean massa. 
      Cum sociis natoque penatibus et magnis dis parturient montes, 
      nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. 
      Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. 
      In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. 
      Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. 
      Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. 
      Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. 
      Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. 
      Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper 
      ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget 
      condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. 
      Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. 
      Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. 
      Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. 
    }
  }
}

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to