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