]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
* buildscripts/gen-bigcheese-scripts.py (i): load .subfonts table.
[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 ;;;;;;;;
60 ;;;;;;;; DOCUMENT ME!
61 ;;;;;;;;
62
63
64
65 (define (unknown) 
66   "%\n\\unknown\n")
67
68
69
70 (define (blank)
71   "")
72
73 (define (dot x y radius)
74   (embedded-ps (list 'dot x y radius)))
75
76
77 (define (embedded-ps string)
78   (embedded-ps (list 'embedded-ps string)))
79
80 (define (white-dot x y radius)
81   (embedded-ps (list 'white-dot x y radius)))
82
83 (define (beam width slope thick blot)
84   (embedded-ps (list 'beam  width slope thick blot)))
85
86 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
87   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
88
89 (define (dashed-slur thick dash l)
90   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
91
92 (define (digits->letters str)
93     (regexp-substitute/global
94      #f "([0-9])" str
95      'pre
96      (lambda (match)
97        (make-string
98         1
99         (integer->char
100          (+ (char->integer #\A)
101             (- (char->integer #\0))
102             (char->integer (string-ref (match:substring match 1) 0)))
103          )))
104      'post))
105
106 (define (named-glyph font name)
107   (string-append "\\" (tex-font-command font)
108                  "\\"
109                  (string-append
110 ;                 (digits->letters (ly:font-name font))
111                   (regexp-substitute/global
112                    #f "[\\._]"
113                    (digits->letters name)
114                    'pre ""
115                    'post))))
116
117 (define (dashed-line thick on off dx dy)
118   (embedded-ps (list 'dashed-line  thick on off dx dy)))
119
120 (define (zigzag-line centre? zzw zzh thick dx dy)
121   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
122
123 (define (ez-ball c l b)
124   (embedded-ps (list 'ez-ball  c  l b)))
125
126
127
128 (define (embedded-ps expr)
129   (let ((ps-string
130          (with-output-to-string
131            (lambda () (ps-output-expression expr (current-output-port))))))
132     (string-append "\\embeddedps{" ps-string "}")))
133   
134
135 (define (repeat-slash w a t)
136   (embedded-ps (list 'repeat-slash  w a t)))
137
138
139
140 (define (number->dim x)
141   (string-append
142    ;;ugh ly:* in backend needs compatibility func for standalone output
143    (ly:number->string x) " \\outputscale "))
144
145 (define (placebox x y s) 
146   (string-append
147    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
148
149 (define (bezier-sandwich l thick)
150   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
151
152 ;; WTF is this in every backend?
153 (define (horizontal-line x1 x2 th)
154   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
155
156 (define (filledbox breapth width depth height)
157   (if (and #f (defined? 'ps-testing))
158       (embedded-ps
159        (string-append (ly:numbers->string (list breapth width depth height))
160                       " draw_box" ))
161       (string-append "\\lyvrule{"
162                      (ly:number->string (- breapth)) "}{"
163                      (ly:number->string (+ breapth width)) "}{"
164                      (ly:number->string depth) "}{"
165                      (ly:number->string height) "}")))
166
167 (define (round-filled-box x y width height blotdiam)
168   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
169
170 (define (text font s)
171   (let*
172       ((mapping #f)       ;; (assoc-get  'char-mapping (ly:font-encoding-alist font))))
173
174
175        ;; TODO: we'd better do this for PS only
176        ;; LaTeX gets in the way, and we need to remap
177        ;; nonprintable chars.
178        
179        (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
180        )
181
182     (string-append "\\hbox{\\" (tex-font-command font)
183                    (if (string? input-enc-name)
184                        (string-append "\\inputencoding{" input-enc-name "}")
185                        "{}")
186                    (sanitize-tex-string
187                     (if (vector? mapping)
188                         (reencode-string mapping s)
189                         s))
190                    "}")))
191
192 (define (white-text scale s)
193    (embedded-ps (list 'white-text scale s)))
194    
195 (define (polygon points blotdiameter)
196   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
197
198 (define (draw-line thick fx fy tx ty)
199   (embedded-ps (list 'draw-line thick fx fy tx ty)))
200
201 ;; no-origin not yet supported by Xdvi
202 (define (no-origin) "")
203
204 (define (grob-cause grob)
205   (if (procedure? point-and-click)
206       (let* ((cause (ly:grob-property grob 'cause))
207              (music-origin (if (ly:music? cause)
208                                (ly:music-property cause 'origin)))
209              (location (if (ly:input-location? music-origin)
210                            (ly:input-location music-origin))))
211         (if (pair? location)
212              ;;; \\string ? 
213             (string-append "\\special{src:"
214                            (apply point-and-click location) "}")
215             ""))
216       ""))