[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lilypond-bug
Subject:    Re: [PATCH] Reduce size of *TeX generated pdfs, Version 2
From:       Knut Petersen <Knut_Petersen () t-online ! de>
Date:       2015-01-09 11:23:16
Message-ID: 54AFBA24.9050809 () t-online ! de
[Download RAW message or body]

Hi James!

Attached is a small *.tex document that can be translated by xelatex or lualatex,
one page including four small snippets.

It demonstrates that also small documents with only a few snippets benefit from
the --bigpdf patch. lualatex must be called with the --shell-escape parameter to
allow it to execute lilypond and pdfcrop (obviously that needs to be installed).

Be aware of the fact that translation will also generate (or overwrite !) some aux
files named tmplilytail.ly, tmplilyhead.ly, tmplilypaper.ly, tmplily.ly, tmplilyfrag1.pdf,
tmplilyfrag3.pdf, tmplilyfrag2.pdf, tmplilyfrag4.pdf.

Edit line 22 to contain the path to your lilypond test executable (dont delete the
space after lilypond) and line 23 to either contain nothing or --bigpdf.

Then translate test.tex to pdf with

    lualatex --shell-escape test
    gs -sDEVICE=pdfwrite -o testtmp.pdf test.pdf
    pdfsizeopt.py --use-multivalent=no testtmp.pdf testfinal.pdf
    dir test*pdf --sort=time | tac

With  line 23 "\def\lilyparms{  }" I get

-rw-r--r-- 1 knut users   173538  9. Jan 11:53 test.pdf
-rw-r--r-- 1 knut users   157303  9. Jan 11:53 testtmp.pdf
-rw-r--r-- 1 knut users   149945  9. Jan 11:53 testfinal.pdf

With line 23 "\def\lilyparms{ --bigpdf }" I get

-rw-r--r-- 1 knut users   879441  9. Jan 11:55 test.pdf
-rw-r--r-- 1 knut users    63359  9. Jan 11:55 testtmp.pdf
-rw-r--r-- 1 knut users    59437  9. Jan 11:55 testfinal.pdf

cu,
  Knut

["test.tex" (text/x-tex)]

\NeedsTeXFormat{LaTeX2e}
\documentclass[10pt]{letter}
\usepackage{geometry}
\geometry{a4paper,noheadfoot,nomarginpar,left=1.5cm,right=1.5cm,top=1.5cm,bottom=1.5cm}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=old]{german}
\setmainfont{CMU Serif}
\setsansfont{CMU Sans Serif}
\setmonofont{CMU Typewriter Text}
\usepackage{graphicx}

\def\tmpNameFull{tmplily.ly}       \newwrite\tmpFileFull
\def\tmpNameHead{tmplilyhead.ly}   \newwrite\tmpFileHead
\def\tmpNameTail{tmplilytail.ly}   \newwrite\tmpFileTail
\def\tmpNamePaper{tmplilypaper.ly} \newwrite\tmpFilePaper
\def\tmpNamePdf{tmplily.pdf }

\def\tmpfragprefix{tmplilyfrag}

\def\lilycommand{/mypath/to/lilypond }
\def\lilyparms{ --bigpdf }

\newcount\fragcount

{
  \catcode`|=0 \catcode`[=1 \catcode`]=2 \catcode`\#=12
  \catcode`\{=12 \catcode`\}=12 \catcode`\\=12
  |gdef|eofull[\end{lilyfull}]
  |gdef|eohead[\end{lilyhead}]
  |gdef|eofrag[\end{lilyfrag}]
  |gdef|eotail[\end{lilytail}]
  |gdef|hashtag[#]
  |gdef|escape[\]
  |gdef|definepaper[\definepaper]
]

{
  \obeylines
  \gdef\doline#1
  {
    \def\oneline{#1}
    \ifx\oneline\eofull
       \def\next{\end{lilyfull}}
    \else
       \ifx\oneline\eohead
          \def\next{\end{lilyhead}}
       \else 
          \ifx\oneline\eofrag
             \def\next{\end{lilyfrag}}
          \else 
             \ifx\oneline\eotail
                \def\next{\end{lilytail}}
             \else 
                \ifx\oneline\definepaper
                   \immediate\write\tmpFile{\escape include "\tmpNamePaper"}
                   \let\next\doline
                \else
                   \immediate\write\tmpFile{\oneline}
                   \let\next\doline
                \fi
             \fi
          \fi
       \fi
    \fi
    \next%
  }
}

\makeatletter

\newenvironment{lilyfull}[2]{
  \global\advance\fragcount by 1
  \immediate\openout\tmpFileFull=\tmpNameFull
  \gdef\tmpFile{\tmpFileFull}
  \immediate\openout\tmpFilePaper=\tmpNamePaper
  \immediate\write\tmpFilePaper{\hashtag(set!
     paper-alist (cons '("mySize" . (cons (* #1) (* #2))) paper-alist))}
  \immediate\closeout\tmpFilePaper
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileFull
  \immediate\write18{\lilycommand \lilyparms \tmpNameFull}
  \immediate\write18{pdfcrop \tmpNamePdf \tmpfragprefix\the\fragcount.pdf}
  \begin{center}\includegraphics{\tmpfragprefix\the\fragcount.pdf}\end{center}
}

\newenvironment{lilyfrag}[2]{
  \global\advance\fragcount by 1
  \immediate\openout\tmpFileFull=\tmpNameFull
  \gdef\tmpFile{\tmpFileFull}
  \immediate\write\tmpFileFull{\escape include "\tmpNameHead"}
  \immediate\openout\tmpFilePaper=\tmpNamePaper
  \immediate\write\tmpFilePaper{\hashtag(set!
     paper-alist (cons '("mySize" . (cons (* #1) (* #2))) paper-alist))}
  \immediate\closeout\tmpFilePaper
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\write\tmpFileFull{\escape include "\tmpNameTail"}
  \immediate\closeout\tmpFileFull
  \immediate\write18{\lilycommand  \lilyparms \tmpNameFull}
  \immediate\write18{pdfcrop \tmpNamePdf \tmpfragprefix\the\fragcount.pdf}
  \begin{center}\includegraphics{\tmpfragprefix\the\fragcount.pdf}\end{center}
}

\newenvironment{lilyhead}{
  \immediate\openout\tmpFileHead=\tmpNameHead
  \gdef\tmpFile{\tmpFileHead}
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileHead
}

\newenvironment{lilytail}{
  \immediate\openout\tmpFileTail=\tmpNameTail
  \gdef\tmpFile{\tmpFileTail}
  \let\do=\@makeother\dospecials\obeylines\doline
}{
  \immediate\closeout\tmpFileTail
}

\makeatother

\def\lorem{
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
  labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco 
  laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in 
  voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat 
  non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
}

\begin{document}
\pagestyle{empty}

\begin{lilyhead}
\version "2.18.2"
\include "deutsch.ly"
\pointAndClickOff
\definepaper
\paper {
  #(set-paper-size "mySize") left-margin = 1\cm top-margin = 0\cm bottom-margin = 0\cm 
  line-width = #(- paper-width (* 1 cm) ) indent = 0 page-count = #1  ragged-right=##t
  ragged-bottom = ##t ragged-last-bottom = ##t annotate-spacing=##f
}
\header {
  tagline = ##f
}
#(set-global-staff-size 17)
allowGrobCallback = #(define-scheme-function (parser location syms) (symbol-list?)
  (let ((interface (car syms)) (sym (cadr syms))) #{ \with { \consists #(lambda (context)
  `((acknowledgers . ((,interface . ,(lambda (engraver grob source-engraver)
  (let ((prop (ly:grob-property grob sym))) (if (procedure? prop) 
  (ly:grob-set-property! grob sym (prop grob))))))))))}#}))
absFontSize = #(define-scheme-function (parser location pt)(number?)
  (lambda (grob) (let* ((layout (ly:grob-layout grob))
  (ref-size (ly:output-def-lookup (ly:grob-layout grob) 'text-font-size 12)))
  (magnification->font-size (/ pt ref-size))))) 
\score { <<
\end{lilyhead}

\begin{lilytail}
  >>
  \layout {
    \context {
      \Score
      \allowGrobCallback font-interface.font-size
      \omit BarNumber
    }
    \override Lyrics.LyricText  #'font-name = #"CMU Serif"
    \override LyricText.font-size = \absFontSize #10
    \override StanzaNumber.font-name = #"CMU Serif Extra"
    \override StanzaNumber.font-size = \absFontSize #10
    \override StanzaNumber.font-name = #"CMU Serif"
    \override StanzaNumber.font-size = \absFontSize #10
  }
}
\end{lilytail}

\lorem

\begin{lilyfrag}{15 cm}{10.0 cm}
\relative c'{\key c \major \time 4/4 \partial 8 c8^\p fis g4. ~ g4.  c,8^\mf  
\tuplet 3/2 {fis4 g a} \tuplet 3/2 {fis g a} fis8 g4. ~ g4.} 
 \addlyrics { Ma -- ri -- a, __ I've just met a girl named Ma -- ri a, __}
\new PianoStaff <<
\new Staff = "upper" {\skip8\skip1\skip1\skip2..}
\new Staff = "lower" {\clef bass \skip8\skip1\skip1\skip2..}
>>
\end{lilyfrag}

\lorem

\begin{lilyfrag}{15 cm}{4.0 cm}
 \relative c'{\key c \major \time 4/4 \autoBeamOff \partial 8 c8 a'4 a8 a [g] a b4 (g8) e4} 
 \addlyrics { In ei -- nem küh -- len Grun -- de, }
\end{lilyfrag}

\lorem

\begin{lilyfrag}{15 cm}{2.0 cm}
\relative c'{\key c \major \time 4/4 c2 b'2 a4. f8 d2}
 \addlyrics { There's a place for us }
\end{lilyfrag}

\lorem

\begin{lilyfrag}{15 cm}{2.0 cm}
\relative c'{\key c \major \time 4/4 c2 c'2 h4 g8 a h4 c}
\addlyrics { Some -- where o -- ver the rain -- bow }
\end{lilyfrag}

\lorem
\end{document}


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic