]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
*** empty log message ***
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8
9 ;; The public interface is tight.
10 ;; It has to be, because user-code is evalled with this module.
11
12 ;; ***It should also be clean, well defined, documented and reviewed***
13
14 ;; To be reasonably safe, you probably do not want to use the TeX
15 ;; backend anyway, but rather the PostScript backend.  You may want
16 ;; to run gs in a uml sandbox too.
17
18
19 (define-module (scm output-tex)
20   #:re-export (quote)
21
22   ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
23   #:export (unknown
24             blank
25             circle
26             dot
27             white-dot
28             beam
29             bracket
30             dashed-slur
31             named-glyph
32             dashed-line
33             zigzag-line
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             white-text
44             setcolor
45             resetcolor
46             polygon
47             draw-line
48             no-origin
49             grob-cause))
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
61 ;;;;;;;;
62 ;;;;;;;; DOCUMENT ME!
63 ;;;;;;;;
64
65
66 (define (char font i)
67   (string-append "\\" (tex-font-command font)
68                  "\\char" (ly:inexact->string i 10) " "))
69
70 (define (unknown) 
71   "%\n\\unknown\n")
72
73 (define (url-link url x y)
74   "")
75
76 (define (blank)
77   "")
78
79 (define (circle radius thick)
80   (embedded-ps (list 'circle radius thick)))
81
82 (define (dot x y radius)
83   (embedded-ps (list 'dot x y radius)))
84
85 (define (embedded-ps string)
86   (embedded-ps (list 'embedded-ps string)))
87
88 (define (white-dot x y radius)
89   (embedded-ps (list 'white-dot x y radius)))
90
91 (define (beam width slope thick blot)
92   (embedded-ps (list 'beam  width slope thick blot)))
93
94 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
95   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
96
97 (define (dashed-slur thick on off lst)
98   (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
99
100 (define (named-glyph font name)
101   (let* ((info (ly:otf-font-glyph-info font name))
102          (subfont (assoc-get 'subfont info))
103          (subidx  (assoc-get 'subfont-index info)))
104     
105     ;;(stderr "INFO: ~S\n" info)
106     ;;(stderr "FONT: ~S\n" font)
107     (if (and subfont subidx)
108         (string-append "\\" (tex-font-command-raw
109                              subfont
110                              (ly:font-magnification font))
111                        "\\char" (number->string subidx))
112
113         (begin
114           (ly:warning (_ "can't find ~a in ~a" name font))
115           ""))))
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 lst b)
124   (embedded-ps (list 'ez-ball c lst b)))
125
126 (define (embedded-ps expr)
127   (let ((ps-string
128          (with-output-to-string
129            (lambda () (ps-output-expression expr (current-output-port))))))
130     (string-append "\\embeddedps{" ps-string "}")))
131
132 (define (repeat-slash w a t)
133   (embedded-ps (list 'repeat-slash  w a t)))
134
135 (define (number->dim x)
136   (string-append
137    ;;ugh ly:* in backend needs compatibility func for standalone output
138    (ly:number->string x) " \\outputscale "))
139
140 (define (placebox x y s) 
141   (string-append
142    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
143
144 (define (bezier-sandwich lst thick)
145   (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
146
147 ;; WTF is this in every backend?
148 (define (horizontal-line x1 x2 th)
149   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
150
151 (define (filledbox breapth width depth height)
152   (if (and #f (defined? 'ps-testing))
153       (embedded-ps
154        (string-append (ly:numbers->string (list breapth width depth height))
155                       " draw_box" ))
156       (string-append "\\lyvrule{"
157                      (ly:number->string (- breapth)) "}{"
158                      (ly:number->string (+ breapth width)) "}{"
159                      (ly:number->string depth) "}{"
160                      (ly:number->string height) "}")))
161
162 (define (round-filled-box x y width height blotdiam)
163   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
164
165 (define (text font s)
166   (format
167    "\\hbox{\\~a{}~a}" (tex-font-command font)
168    (sanitize-tex-string s)))
169
170 (define (white-text scale s)
171   (embedded-ps (list 'white-text scale s)))
172
173 (define (setcolor r g b)
174   (string-append "\\color[rgb]{"
175   (number->string r) ", "
176   (number->string g) ", "
177   (number->string b) "}"))
178
179 ;; FIXME
180 ;; The PostScript backend saves the current color
181 ;; during setcolor and restores it during resetcolor.
182 ;; We don't do that here.
183 (define (resetcolor)
184   (string-append "\\color[rgb]{0,0,0}\n"))
185
186 (define (polygon points blotdiameter)
187   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
188
189 (define (draw-line thick fx fy tx ty)
190   (embedded-ps (list 'draw-line thick fx fy tx ty)))
191
192 ;; no-origin not yet supported by Xdvi
193 (define (no-origin) "")
194
195 (define (grob-cause offset grob)
196   (if (procedure? point-and-click)
197       (let* ((cause (ly:grob-property grob 'cause))
198              (music-origin (if (ly:music? cause)
199                                (ly:music-property cause 'origin)))
200              (location (if (ly:input-location? music-origin)
201                            (ly:input-file-line-column music-origin))))
202         (if (pair? location)
203              ;;; \\string ? 
204             (string-append "\\special{src:"
205                            (apply point-and-click location) "}")
206             ""))
207       ""))