]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
* lily/lookup.cc (triangle): rewrite, obviating symmetric_x_triangle().
[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              char
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              tuplet
46              polygon
47              draw-line
48              no-origin
49              grob-cause
50              ))
51
52 (use-modules (ice-9 regex)
53              (ice-9 string-fun)
54              (ice-9 format)
55              (guile)
56              (srfi srfi-13)
57              (scm framework-tex)
58              (lily))
59
60 ;;;;;;;;
61 ;;;;;;;; DOCUMENT ME!
62 ;;;;;;;;
63
64
65
66 (define (unknown) 
67   "%\n\\unknown\n")
68
69
70
71 (define (blank)
72   "")
73
74 (define (dot x y radius)
75   (embedded-ps (list 'dot x y radius)))
76
77
78 (define (embedded-ps string)
79   (embedded-ps (list 'embedded-ps string)))
80
81 (define (white-dot x y radius)
82   (embedded-ps (list 'white-dot x y radius)))
83
84 (define (beam width slope thick blot)
85   (embedded-ps (list 'beam  width slope thick blot)))
86
87 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
88   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
89
90 (define (dashed-slur thick dash l)
91   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
92
93 (define (char font i)
94   (string-append "\\" (tex-font-command font)
95                  "\\char" (ly:inexact->string i 10) " "))
96
97 (define (dashed-line thick on off dx dy)
98   (embedded-ps (list 'dashed-line  thick on off dx dy)))
99
100 (define (zigzag-line centre? zzw zzh thick dx dy)
101   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
102
103 (define (ez-ball c l b)
104   (embedded-ps (list 'ez-ball  c  l b)))
105
106
107
108 (define (embedded-ps expr)
109   (let ((ps-string
110          (with-output-to-string
111            (lambda () (ps-output-expression expr (current-output-port))))))
112     (string-append "\\embeddedps{" ps-string "}")))
113   
114
115 (define (repeat-slash w a t)
116   (embedded-ps (list 'repeat-slash  w a t)))
117
118
119
120 (define (number->dim x)
121   (string-append
122    ;;ugh ly:* in backend needs compatibility func for standalone output
123    (ly:number->string x) " \\outputscale "))
124
125 (define (placebox x y s) 
126   (string-append
127    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
128
129 (define (bezier-sandwich l thick)
130   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
131
132 ;; WTF is this in every backend?
133 (define (horizontal-line x1 x2 th)
134   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
135
136 (define (filledbox breapth width depth height)
137   (if (and #f (defined? 'ps-testing))
138       (embedded-ps
139        (string-append (ly:numbers->string (list breapth width depth height))
140                       " draw_box" ))
141       (string-append "\\lyvrule{"
142                      (ly:number->string (- breapth)) "}{"
143                      (ly:number->string (+ breapth width)) "}{"
144                      (ly:number->string depth) "}{"
145                      (ly:number->string height) "}")))
146
147 (define (round-filled-box x y width height blotdiam)
148   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
149
150 (define (text font s)
151   (let*
152       ((mapping #f)       ;; (assoc-get  'char-mapping (ly:font-encoding-alist font))))
153
154
155        ;; TODO: we'd better do this for PS only
156        ;; LaTeX gets in the way, and we need to remap
157        ;; nonprintable chars.
158        
159        (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
160        )
161
162     (string-append "\\hbox{\\" (tex-font-command font)
163                    (if (string? input-enc-name)
164                        (string-append "\\inputencoding{" input-enc-name "}")
165                        "{}")
166                    (sanitize-tex-string
167                     (if (vector? mapping)
168                         (reencode-string mapping s)
169                         s))
170                    "}")))
171
172 (define (white-text scale s)
173    (embedded-ps (list 'white-text scale s)))
174    
175 (define (tuplet ht gapx dx dy thick dir)
176   (embedded-ps (list 'tuplet  ht gapx dx dy thick dir)))
177
178 (define (polygon points blotdiameter)
179   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
180
181 (define (draw-line thick fx fy tx ty)
182   (embedded-ps (list 'draw-line thick fx fy tx ty)))
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       (let* ((cause (ly:grob-property grob 'cause))
190              (music-origin (if (ly:music? cause)
191                                (ly:music-property cause 'origin)))
192              (location (if (ly:input-location? music-origin)
193                            (ly:input-location music-origin))))
194         (if (pair? location)
195              ;;; \\string ? 
196             (string-append "\\special{src:"
197                            (apply point-and-click location) "}")
198             ""))
199       ""))