From dc2461349cb87896acc687a1e7e652c79ec36115 Mon Sep 17 00:00:00 2001
From: wl <wl>
Date: Sat, 23 Oct 2004 19:45:40 +0000
Subject: [PATCH] * scm/framework-tex.scm (dump-page): Add width to \lybox
 call. Remove first two parameters of \lybox. Don't emit \vbox around \lybox.
 (dump-line): Add width to \lybox call. Remove first two parameters of \lybox.

* tex/lilyponddefs.tex (\topalign, \leftalign): Removed.
(\lyitem): Updated.
(\lybox): Only take three parameters.
Create box which has zero depth, only height.
Center box vertically along the x-height of current font.
---
 ChangeLog             | 14 +++++++
 scm/framework-tex.scm | 93 ++++++++++++++++++++-----------------------
 tex/lilyponddefs.tex  | 61 ++++++++++------------------
 3 files changed, 78 insertions(+), 90 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 83e6d21d53..ea244126a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-10-23  Werner Lemberg  <wl@gnu.org>
+
+	* scm/framework-tex.scm (dump-page): Add width to \lybox call.
+	Remove first two parameters of \lybox.
+	Don't emit \vbox around \lybox.
+	(dump-line): Add width to \lybox call.
+	Remove first two parameters of \lybox.
+
+	* tex/lilyponddefs.tex (\topalign, \leftalign): Removed.
+	(\lyitem): Updated.
+	(\lybox): Only take three parameters.
+	Create box which has zero depth, only height.
+	Center box vertically along the x-height of current font.
+
 2004-10-23  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
 	* scm/framework-tex.scm (convert-to-ps): add -E if filename
diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm
index 24cffa36f8..c119578c52 100644
--- a/scm/framework-tex.scm
+++ b/scm/framework-tex.scm
@@ -5,9 +5,8 @@
 ;;;; (c)  2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
 (define-module (scm framework-tex)
-  #:export (output-framework-tex	    
-	    output-classic-framework-tex
-))
+  #:export (output-framework-tex	
+	    output-classic-framework-tex))
 
 (use-modules (ice-9 regex)
 	     (ice-9 string-fun)
@@ -23,11 +22,11 @@
 ;; \lyitem{089.5557}{-15.3109}{\hbox{\magfontUGQLomTVo{}bla$\backslash${$\backslash$}}}%
 ;; --jcn
 (define-public (sanitize-tex-string s)
-   (if (ly:get-option 'safe)
-      (regexp-substitute/global #f "\\\\"
-				(regexp-substitute/global #f "([{}])" "bla{}" 'pre  "\\" 1 'post )
-				'pre "$\\backslash$" 'post)
-      
+  (if (ly:get-option 'safe)
+      (regexp-substitute/global
+       #f "\\\\"
+       (regexp-substitute/global #f "([{}])" "bla{}" 'pre  "\\" 1 'post )
+       'pre "$\\backslash$" 'post)
       s))
 
 (define (symbol->tex-key sym)
@@ -50,7 +49,6 @@
 (define (font-load-command paper font)
   (let* ((coding-alist (ly:font-encoding-alist font))
 	 (font-encoding (assoc-get 'output-name coding-alist)))
-    
     (string-append
      "\\font\\lilypond" (tex-font-command font) "="
      (ly:font-filename font)
@@ -66,13 +64,11 @@
 	 "  \\lilypondfontencoding{T1}"
 	 "  ")
      "\\lilypond" (tex-font-command font)
-     "}%\n"
-     )))
-
+     "}%\n")))
 
 (define (define-fonts paper)
   (string-append
-   ;; UGH. FIXME.   
+   ;; UGH. FIXME.
    "\\def\\lilypondpaperunit{mm}%\n"
    (tex-number-def "lilypondpaper" 'outputscale
 		   (number->string (exact->inexact
@@ -102,15 +98,13 @@
   (newline (current-error-port))
   "")
 
-(define (output-scopes  scopes fields basename)
+(define (output-scopes scopes fields basename)
   (define (output-scope scope)
     (apply
      string-append
      (module-map
       (lambda (sym var)
-	(let ((val (if (variable-bound? var) (variable-ref var) ""))
-	      )
-	  
+	(let ((val (if (variable-bound? var) (variable-ref var) "")))
 	  (if (and (memq sym fields) (string? val))
 	      (header-to-file basename sym val))
 	  ""))
@@ -129,7 +123,6 @@
 		   (ly:output-def-lookup paper 'papersizename)
 		   "paper"))
 	(landscape? (eq? #t (ly:output-def-lookup paper 'landscape))))
-    
     (string-append
      "% Generated by LilyPond "
      (lilypond-version) "\n"
@@ -147,8 +140,8 @@
       (ly:number->string (* scale (ly:output-def-lookup paper 'linewidth))))
      "\\def\\lilyponddocumentclassoptions{"
      texpaper
-     (if  landscape? ",landscape" "")
-      "}%\n"
+     (if landscape? ",landscape" "")
+     "}%\n"
      (tex-string-def
       "lilypondpaper" 'interscoreline
       (ly:number->string
@@ -172,25 +165,26 @@
 (define (dump-page putter page last? with-extents?)
   (ly:outputter-dump-string
    putter
-   (format "\\vbox to ~a\\outputscale{%\n\\leavevmode\n\\lybox{0}{0}{0}{0}{%\n"
+   (format "\\lybox{~a}{~a}{%\n"
+	   (if with-extents?
+	       (interval-start (ly:stencil-extent page X))
+	       0.0)
 	   (if with-extents?
 	       (- (interval-start (ly:stencil-extent page Y)))
-	       	       0.0
-	       )))
+	       0.0)))
   (ly:outputter-dump-stencil putter page)
   (ly:outputter-dump-string
    putter
    (if last?
-       "}\\vss\n}\n\\vfill\n"
-       "}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
+       "}%\n\\vfill\n"
+       "}%\n\\vfill\n\\lilypondpagebreak\n")))
 
 (define-public (output-framework outputter book scopes fields basename )
   (let* ((paper (ly:paper-book-paper book))
 	 (pages (ly:paper-book-pages book))
 	 (last-page (car (last-pair pages)))
 	 (with-extents
-	  (eq? #t (ly:output-def-lookup paper 'dump-extents)))
-	 )
+	  (eq? #t (ly:output-def-lookup paper 'dump-extents))))
     (for-each
      (lambda (x)
        (ly:outputter-dump-string outputter x))
@@ -198,17 +192,22 @@
       (header paper (length pages) #f)
       (define-fonts paper)
       (header-end)))
-    (ly:outputter-dump-string outputter "\\lilypondnopagebreak")
+    (ly:outputter-dump-string outputter "\\lilypondnopagebreak\n")
     (for-each
-     (lambda (page) (dump-page outputter page (eq? last-page page) with-extents))
+     (lambda (page)
+       (dump-page outputter page (eq? last-page page) with-extents))
      pages)
     (ly:outputter-dump-string outputter "\\lilypondend\n")))
 
 (define (dump-line putter line last?)
   (ly:outputter-dump-string
    putter
-   (string-append "\\leavevmode\n\\lybox{0}{0}{0}{"
-		  (ly:number->string (interval-length (ly:paper-system-extent line Y)))
+   (string-append "\\lybox{"
+		  (ly:number->string
+		   (interval-length (ly:paper-system-extent line X)))
+		  "}{"
+		  (ly:number->string
+		   (interval-length (ly:paper-system-extent line Y)))
 		  "}{%\n"))
 
   (ly:outputter-dump-stencil putter (ly:paper-system-stencil line))
@@ -238,7 +237,6 @@
      (lambda (line) (dump-line outputter line (eq? line last-line))) lines)
     (ly:outputter-dump-string outputter "\\lilypondend\n")))
 
-
 (define-public (output-preview-framework
 		outputter book scopes fields basename )
   (let* ((paper (ly:paper-book-paper book))
@@ -257,18 +255,17 @@
     (dump-line outputter (car lines) #t)
     (ly:outputter-dump-string outputter "\\lilypondend\n")))
 
-
 (define-public (convert-to-pdf book name)
   (let* ((defs (ly:paper-book-paper book))
 	 (papersizename (ly:output-def-lookup defs 'papersizename)))
-
     (postscript->pdf (if (string? papersizename) papersizename "a4")
-		     (string-append (basename name ".tex") ".ps"))))
+		     (string-append
+		      (basename name ".tex")
+		      ".ps"))))
 
 (define-public (convert-to-png book name)
   (let* ((defs (ly:paper-book-paper book))
 	 (resolution (ly:output-def-lookup defs 'pngresolution)))
-
     (postscript->png
      (if (number? resolution) resolution 90)
      (string-append (basename name ".tex") ".ps"))))
@@ -279,27 +276,26 @@
 	 (papersizename (ly:output-def-lookup paper 'papersizename))
 	 (landscape? (eq? #t (ly:output-def-lookup paper 'landscape)))
 	 (cmd (string-append "dvips "
-			     
 			     (if preview?
 				 " -E "
 				 (string-append " -t " papersizename))
-
-			     (if landscape? " -t landscape " " ")
+			     (if landscape?
+				 " -t landscape "
+				 " ")
 			     "  -u+ec-mftrace.map -u+lilypond.map -Ppdf "
 			     (basename name ".tex"))))
-    
     (display (format #f (_ "Invoking ~S") cmd) (current-error-port))
     (newline (current-error-port))
     (system cmd)))
 
 (define-public (convert-to-dvi book name)
-  (let* ((curr-extra-mem (string->number
-			  (regexp-substitute/global
-			   #f " *%.*\n?"
-			   (ly:kpathsea-expand-variable "$extra_mem_top")
-			   'pre "" 'post)))
-       (cmd (string-append "latex \\\\nonstopmode \\\\input " name)))
-
+  (let* ((curr-extra-mem
+	  (string->number
+	   (regexp-substitute/global
+	    #f " *%.*\n?"
+	    (ly:kpathsea-expand-variable "$extra_mem_top")
+	    'pre "" 'post)))
+	 (cmd (string-append "latex \\\\nonstopmode \\\\input " name)))
     (setenv "extra_mem_top" (number->string (max curr-extra-mem 1024000)))
     (newline (current-error-port))
     (display (format #f (_ "Invoking ~S") cmd) (current-error-port))
@@ -308,9 +304,8 @@
     ;; fixme: set in environment?
     (if (ly:get-option 'safe)
 	(set! cmd (string-append "openout_any=p " cmd)))
-    
+
     (system cmd)))
 
 (define-public (convert-to-tex book name)
   #t)
-
diff --git a/tex/lilyponddefs.tex b/tex/lilyponddefs.tex
index 0c5a87ea15..06d99b8200 100644
--- a/tex/lilyponddefs.tex
+++ b/tex/lilyponddefs.tex
@@ -254,53 +254,32 @@
   \special{header=music-drawing-routines.ps}
   \gdef\lilypondspecial{}}
 
-
-
-
-%% Put the argument into a box which has zero height and depth (the
-%% \vss forces the latter -- TeXbook, page 80).
-%%
-\gdef\topalign#1{
-  \vbox to 0pt{
-    \hbox{#1}
-    \vss}}
-
-%% Put the argument into a box which has zero width.
-%%
-\gdef\leftalign#1{
-  \hbox to 0pt{
-    #1
-    \hss}}
-
 %% The most used macro in LilyPond output.  Put #3 into a zero-width box
 %% which is moved to the right by #1 (scaled by \outputscale) and moved
-%% up by #2 (also scaled by \outputscale).  Note that negative values for
-%% #2 change the depth of the box defined by \leftalign, not the height.
+%% up by #2 (also scaled by \outputscale).
 %%
 \gdef\lyitem#1#2#3{
-  \raise#2\outputscale \leftalign{
-    \kern#1\outputscale
-    #3}}
-
-%% All LilyPond music data is enclosed in this macro (as fifth argument).
-%% The data is first put into a box with zero height and depth which is
-%% then moved to the right by #1 and moved down by #2.  After this, it is
-%% put into a zero-width box, giving it a height #4 (and depth zero).
-%% Finally, the box is raised so that its true height is exactly the
-%% distance from one baseline to the next.
+  \raise #2\outputscale \hbox to 0pt {
+    \kern #1\outputscale
+    #3
+    \hss}}
+
+%% All LilyPond music data is enclosed in this macro (as third argument).
+%% The data (which consists of boxes with zero width) gets an artificial
+%% width of #1 and a height of #2.  The resulting box is then centered
+%% vertically along the x-height of the current font.
 %%
-%% Parameters #1 to #4 are scaled by \outputscale.
+%% Parameters #1 and #2 are scaled by \outputscale.
 %%
-\gdef\lybox#1#2#3#4#5{
-  \lytempdim\baselineskip
-  \advance\lytempdim -#4\outputscale
-  \raise\lytempdim
-  \vbox to #4\outputscale{
-    \leftalign{
-      \kern #1\outputscale
-      \lower #2\outputscale \topalign{
-        #5}}
-    \vss}}
+\gdef\lybox#1#2#3{
+  \lytempdim #2\outputscale
+  \lytempdim -0.5\lytempdim
+  \advance\lytempdim 1ex
+  \leavevmode
+  \raise \lytempdim \hbox to #1\outputscale {
+    %% Convert depth of #3 into height only.
+    \vbox to #2\outputscale {\hbox{#3}\vss}
+    \hss}}
 
 %% Produce a black bar (width #2, depth #3, height #4) with a vertical
 %% offset #1.  Everything is scaled by \outputscale.
-- 
2.39.5