]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
* mf/GNUmakefile: Genereate combined aybabtu info.
[lilypond.git] / scm / output-tex.scm
1 ;;;; tex.scm -- implement Scheme output routines for TeX
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9 ;; (debug-enable 'backtrace)
10
11 ;; The public interface is tight.
12 ;; It has to be, because user-code is evalled with this module.
13
14 ;; ***It should also be clean, well defined, documented and reviewed***
15
16 ;; To be reasonably safe, you probably do not want to use the TeX
17 ;; backend anyway, but rather the PostScript backend.  You may want
18 ;; to run gs in a uml sandbox too.
19
20
21 (define-module (scm output-tex)
22   #:re-export (quote)
23
24   ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
25   #:export (unknown
26              blank
27              dot
28              white-dot
29              beam
30              bracket
31              dashed-slur
32              named-glyph
33              dashed-line
34              zigzag-line
35              ez-ball
36              comment
37              repeat-slash
38              placebox
39              bezier-sandwich
40              horizontal-line
41              filledbox
42              round-filled-box
43              text
44              white-text
45              polygon
46              draw-line
47              no-origin
48              grob-cause
49              ))
50
51 (use-modules (ice-9 regex)
52              (ice-9 string-fun)
53              (ice-9 format)
54              (guile)
55              (srfi srfi-13)
56              (scm framework-tex)
57              (lily))
58
59 ;; helper functions
60 (define (stderr string . rest)
61   (apply format (cons (current-error-port) (cons string rest)))
62   (force-output (current-error-port)))
63
64
65 ;;;;;;;;
66 ;;;;;;;; DOCUMENT ME!
67 ;;;;;;;;
68
69
70
71 (define (unknown) 
72   "%\n\\unknown\n")
73
74
75
76 (define (blank)
77   "")
78
79 (define (dot x y radius)
80   (embedded-ps (list 'dot x y radius)))
81
82
83 (define (embedded-ps string)
84   (embedded-ps (list 'embedded-ps string)))
85
86 (define (white-dot x y radius)
87   (embedded-ps (list 'white-dot x y radius)))
88
89 (define (beam width slope thick blot)
90   (embedded-ps (list 'beam  width slope thick blot)))
91
92 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
93   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
94
95 (define (dashed-slur thick dash l)
96   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
97
98 (define (named-glyph font name)
99   (let* ((info (ly:otf-font-glyph-info font name)))
100     ;;(stderr "INFO: ~S\n" info)
101     ;;(stderr "FONT: ~S\n" font)
102     (string-append "\\" (tex-font-command-raw
103                          (assoc-get 'subfont info)
104                          (ly:font-magnification font))
105                    "\\char" (number->string (assoc-get 'subfont-index info)))))
106
107 (define (dashed-line thick on off dx dy)
108   (embedded-ps (list 'dashed-line  thick on off dx dy)))
109
110 (define (zigzag-line centre? zzw zzh thick dx dy)
111   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
112
113 (define (ez-ball c l b)
114   (embedded-ps (list 'ez-ball c l b)))
115
116 (define (embedded-ps expr)
117   (let ((ps-string
118          (with-output-to-string
119            (lambda () (ps-output-expression expr (current-output-port))))))
120     (string-append "\\embeddedps{" ps-string "}")))
121
122 (define (repeat-slash w a t)
123   (embedded-ps (list 'repeat-slash  w a t)))
124
125 (define (number->dim x)
126   (string-append
127    ;;ugh ly:* in backend needs compatibility func for standalone output
128    (ly:number->string x) " \\outputscale "))
129
130 (define (placebox x y s) 
131   (string-append
132    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
133
134 (define (bezier-sandwich l thick)
135   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
136
137 ;; WTF is this in every backend?
138 (define (horizontal-line x1 x2 th)
139   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
140
141 (define (filledbox breapth width depth height)
142   (if (and #f (defined? 'ps-testing))
143       (embedded-ps
144        (string-append (ly:numbers->string (list breapth width depth height))
145                       " draw_box" ))
146       (string-append "\\lyvrule{"
147                      (ly:number->string (- breapth)) "}{"
148                      (ly:number->string (+ breapth width)) "}{"
149                      (ly:number->string depth) "}{"
150                      (ly:number->string height) "}")))
151
152 (define (round-filled-box x y width height blotdiam)
153   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
154
155 (define (text font s)
156   (let*
157       ((mapping #f)       ;; (assoc-get  'char-mapping (ly:font-encoding-alist font))))
158
159
160        ;; TODO: we'd better do this for PS only
161        ;; LaTeX gets in the way, and we need to remap
162        ;; nonprintable chars.
163        
164        (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
165        )
166
167     (string-append "\\hbox{\\" (tex-font-command font)
168                    (if (string? input-enc-name)
169                        (string-append "\\inputencoding{" input-enc-name "}")
170                        "{}")
171                    (sanitize-tex-string
172                     (if (vector? mapping)
173                         (reencode-string mapping s)
174                         s))
175                    "}")))
176
177 (define (white-text scale s)
178    (embedded-ps (list 'white-text scale s)))
179    
180 (define (polygon points blotdiameter)
181   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
182
183 (define (draw-line thick fx fy tx ty)
184   (embedded-ps (list 'draw-line thick fx fy tx ty)))
185
186 ;; no-origin not yet supported by Xdvi
187 (define (no-origin) "")
188
189 (define (grob-cause grob)
190   (if (procedure? point-and-click)
191       (let* ((cause (ly:grob-property grob 'cause))
192              (music-origin (if (ly:music? cause)
193                                (ly:music-property cause 'origin)))
194              (location (if (ly:input-location? music-origin)
195                            (ly:input-location music-origin))))
196         (if (pair? location)
197              ;;; \\string ? 
198             (string-append "\\special{src:"
199                            (apply point-and-click location) "}")
200             ""))
201       ""))