]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
* lily/stencil.cc (interpret_stencil_expression): add grob-cause
[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   #:export (unknown
24              blank
25              dot
26              white-dot
27              beam
28              bracket
29              dashed-slur
30              char
31              dashed-line
32              zigzag-line
33              symmetric-x-triangle
34              ez-ball
35              comment
36              repeat-slash
37              placebox
38              bezier-sandwich
39              horizontal-line
40              filledbox
41              round-filled-box
42              text
43              tuplet
44              polygon
45              draw-line
46              define-origin
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 (define (white-dot x y radius)
77   (embedded-ps (list 'white-dot x y radius)))
78
79 (define (beam width slope thick blot)
80   (embedded-ps (list 'beam  width slope thick blot)))
81
82 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
83   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
84
85 (define (dashed-slur thick dash l)
86   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
87
88 (define (char font i)
89   (string-append "\\" (tex-font-command font)
90                  "\\char" (ly:inexact->string i 10) " "))
91
92 (define (dashed-line thick on off dx dy)
93   (embedded-ps (list 'dashed-line  thick on off dx dy)))
94
95 (define (zigzag-line centre? zzw zzh thick dx dy)
96   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
97
98 (define (symmetric-x-triangle t w h)
99   (embedded-ps (list 'symmetric-x-triangle t w h)))
100
101
102 (define (ez-ball c l b)
103   (embedded-ps (list 'ez-ball  c  l b)))
104
105
106
107 (define (embedded-ps expr)
108   (let ((ps-string
109          (with-output-to-string
110            (lambda () (ps-output-expression expr (current-output-port))))))
111     (string-append "\\embeddedps{" ps-string "}")))
112   
113
114 (define (repeat-slash w a t)
115   (embedded-ps (list 'repeat-slash  w a t)))
116
117
118
119 (define (number->dim x)
120   (string-append
121    ;;ugh ly:* in backend needs compatibility func for standalone output
122    (ly:number->string x) " \\outputscale "))
123
124 (define (placebox x y s) 
125   (string-append
126    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
127
128 (define (bezier-sandwich l thick)
129   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
130
131 ;; WTF is this in every backend?
132 (define (horizontal-line x1 x2 th)
133   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
134
135 (define (filledbox breapth width depth height)
136   (if (and #f (defined? 'ps-testing))
137       (embedded-ps
138        (string-append (ly:numbers->string (list breapth width depth height))
139                       " draw_box" ))
140       (string-append "\\lyvrule{"
141                      (ly:number->string (- breapth)) "}{"
142                      (ly:number->string (+ breapth width)) "}{"
143                      (ly:number->string depth) "}{"
144                      (ly:number->string height) "}")))
145
146 (define (round-filled-box x y width height blotdiam)
147   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
148
149 (define (text font s)
150   (let*
151       ((mapping #f)       ;; (assoc-get  'char-mapping (ly:font-encoding-alist font))))
152
153
154        ;; TODO: we'd better do this for PS only
155        ;; LaTeX gets in the way, and we need to remap
156        ;; nonprintable chars.
157        
158        (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
159        )
160
161     (string-append "\\hbox{\\" (tex-font-command font)
162                    (if (string? input-enc-name)
163                        (string-append "\\inputencoding{" input-enc-name "}")
164                        "{}")
165                    (sanitize-tex-string
166                     (if (vector? mapping)
167                         (reencode-string mapping s)
168                         s))
169                    "}")))
170
171
172 (define (tuplet ht gapx dx dy thick dir)
173   (embedded-ps (list 'tuplet  ht gapx dx dy thick dir)))
174
175 (define (polygon points blotdiameter)
176   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
177
178 (define (draw-line thick fx fy tx ty)
179   (embedded-ps (list 'draw-line thick fx fy tx ty)))
180
181 (define (define-origin file line col)
182   "")
183
184 ;; no-origin not yet supported by Xdvi
185 (define (no-origin) "")
186
187 (define (grob-cause grob)
188   (if (procedure? point-and-click)
189   
190   (let*
191       ((cause (ly:grob-property grob 'cause))
192        (music-origin (if (ly:music? cause)
193                          (ly:music-property cause 'origin)
194                           #f))
195        (location (if (ly:input-location? music-origin)
196                      (ly:input-location music-origin)
197                      #f)))
198
199     (if (pair? location)
200         (string-append "\\special{src:" ;;; \\string ? 
201                        (apply point-and-click location) "}")
202         ""))
203   ""))