]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
* Documentation/user/instrument-notation.itely (String number
[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 ;; (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 (use-modules (ice-9 regex)
51              (ice-9 string-fun)
52              (ice-9 format)
53              (guile)
54              (srfi srfi-13)
55              (scm framework-tex)
56              (lily))
57
58
59
60 ;;;;;;;;
61 ;;;;;;;; DOCUMENT ME!
62 ;;;;;;;;
63
64
65 (define (char font i)
66   (string-append "\\" (tex-font-command font)
67                  "\\char" (ly:inexact->string i 10) " "))
68
69 (define (unknown) 
70   "%\n\\unknown\n")
71
72 (define (url-link url x y)
73   "")
74
75
76 (define (blank)
77   "")
78
79 (define (dot x y radius)
80   (embedded-ps (list 'dot x y radius)))
81
82 (define (circle radius thick)
83   (embedded-ps (list 'circle radius thick)))
84
85
86 (define (embedded-ps string)
87   (embedded-ps (list 'embedded-ps string)))
88
89 (define (white-dot x y radius)
90   (embedded-ps (list 'white-dot x y radius)))
91
92 (define (beam width slope thick blot)
93   (embedded-ps (list 'beam  width slope thick blot)))
94
95 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
96   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
97
98 (define (dashed-slur thick on off lst)
99   (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
100
101 (define (named-glyph font name)
102   (let* ((info (ly:otf-font-glyph-info font name))
103          (subfont (assoc-get 'subfont info))
104          (subidx  (assoc-get 'subfont-index info)))
105     
106     ;;(stderr "INFO: ~S\n" info)
107     ;;(stderr "FONT: ~S\n" font)
108     (if (and subfont subidx)
109         (string-append "\\" (tex-font-command-raw
110                              subfont
111                              (ly:font-magnification font))
112                        "\\char" (number->string subidx))
113
114         (begin
115           (ly:warn "Can't find ~a in ~a" name font)
116           ""))))
117
118 (define (dashed-line thick on off dx dy)
119   (embedded-ps (list 'dashed-line  thick on off dx dy)))
120
121 (define (zigzag-line centre? zzw zzh thick dx dy)
122   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
123
124 (define (ez-ball c lst b)
125   (embedded-ps (list 'ez-ball c lst b)))
126
127 (define (embedded-ps expr)
128   (let ((ps-string
129          (with-output-to-string
130            (lambda () (ps-output-expression expr (current-output-port))))))
131     (string-append "\\embeddedps{" ps-string "}")))
132
133 (define (repeat-slash w a t)
134   (embedded-ps (list 'repeat-slash  w a t)))
135
136 (define (number->dim x)
137   (string-append
138    ;;ugh ly:* in backend needs compatibility func for standalone output
139    (ly:number->string x) " \\outputscale "))
140
141 (define (placebox x y s) 
142   (string-append
143    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
144
145 (define (bezier-sandwich lst thick)
146   (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
147
148 ;; WTF is this in every backend?
149 (define (horizontal-line x1 x2 th)
150   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
151
152 (define (filledbox breapth width depth height)
153   (if (and #f (defined? 'ps-testing))
154       (embedded-ps
155        (string-append (ly:numbers->string (list breapth width depth height))
156                       " draw_box" ))
157       (string-append "\\lyvrule{"
158                      (ly:number->string (- breapth)) "}{"
159                      (ly:number->string (+ breapth width)) "}{"
160                      (ly:number->string depth) "}{"
161                      (ly:number->string height) "}")))
162
163 (define (round-filled-box x y width height blotdiam)
164   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
165
166 (define (text font s)
167   (format
168    "\\hbox{\\~a{}~a}" (tex-font-command font)
169    (sanitize-tex-string s)))
170
171 (define (white-text scale s)
172   (embedded-ps (list 'white-text scale s)))
173
174 (define (polygon points blotdiameter)
175   (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
176
177 (define (draw-line thick fx fy tx ty)
178   (embedded-ps (list 'draw-line thick fx fy tx ty)))
179
180 ;; no-origin not yet supported by Xdvi
181 (define (no-origin) "")
182
183 (define (grob-cause offset grob)
184   (if (procedure? point-and-click)
185       (let* ((cause (ly:grob-property grob 'cause))
186              (music-origin (if (ly:music? cause)
187                                (ly:music-property cause 'origin)))
188              (location (if (ly:input-location? music-origin)
189                            (ly:input-file-line-column music-origin))))
190         (if (pair? location)
191              ;;; \\string ? 
192             (string-append "\\special{src:"
193                            (apply point-and-click location) "}")
194             ""))
195       ""))