]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
3a3e023ebe77e302b0c65341a7763cc7ce91cb65
[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--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;                 Han-Wen Nienhuys <hanwen@xs4all.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             dashed-slur
28             named-glyph
29             dashed-line
30             zigzag-line
31             comment
32             repeat-slash
33             placebox
34             bezier-sandwich
35             round-filled-box
36             text
37             setcolor
38             resetcolor
39             polygon
40             draw-line
41             no-origin
42             grob-cause))
43
44 (use-modules (ice-9 regex)
45              (ice-9 string-fun)
46              (ice-9 format)
47              (guile)
48              (srfi srfi-13)
49              (scm framework-tex)
50              (lily))
51
52
53
54 ;;;;;;;;
55 ;;;;;;;; DOCUMENT ME!
56 ;;;;;;;;
57
58
59 (define (char font i)
60   (string-append "\\" (tex-font-command font)
61                  "\\char" (ly:inexact->string i 10) " "))
62
63 (define (unknown) 
64   "%\n\\unknown\n")
65
66 (define (url-link url x y)
67   "")
68
69 (define (blank)
70   "")
71
72 (define (circle radius thick)
73   (embedded-ps (list 'circle radius thick)))
74
75 (define (dot x y radius)
76   (embedded-ps (list 'dot x y radius)))
77
78 (define (embedded-ps string)
79   (embedded-ps (list 'embedded-ps string)))
80
81 (define (dashed-slur thick on off lst)
82   (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
83
84 (define (named-glyph font name)
85   (let* ((info (ly:otf-font-glyph-info font name))
86          (subfont (assoc-get 'subfont info))
87          (subidx  (assoc-get 'subfont-index info)))
88     
89     ;;(stderr "INFO: ~S\n" info)
90     ;;(stderr "FONT: ~S\n" font)
91     (if (and subfont subidx)
92         (string-append "\\" (tex-font-command-raw
93                              subfont
94                              (ly:font-magnification font))
95                        "\\char" (number->string subidx))
96
97         (begin
98           (ly:warning (_ "can't find ~a in ~a" name font))
99           ""))))
100
101 (define (dashed-line thick on off dx dy phase)
102   (embedded-ps (list 'dashed-line  thick on off dx dy phase)))
103
104 (define (zigzag-line centre? zzw zzh thick dx dy)
105   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
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 (define (repeat-slash w a t)
114   (embedded-ps (list 'repeat-slash  w a t)))
115
116 (define (number->dim x)
117   (string-append
118    ;;ugh ly:* in backend needs compatibility func for standalone output
119    (ly:number->string x) " \\output-scale "))
120
121 (define (placebox x y s) 
122   (string-append
123    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
124
125 (define (bezier-sandwich lst thick)
126   (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
127
128
129 (define (round-filled-box x y width height blotdiam)
130   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
131
132 (define (text font s)
133   (format
134    "\\hbox{\\~a{}~a}" (tex-font-command font)
135    (sanitize-tex-string s)))
136
137 (define (setcolor r g b)
138   (string-append "\\color[rgb]{"
139   (number->string r) ", "
140   (number->string g) ", "
141   (number->string b) "}"))
142
143 ;; FIXME
144 ;; The PostScript backend saves the current color
145 ;; during setcolor and restores it during resetcolor.
146 ;; We don't do that here.
147 (define (resetcolor)
148   (string-append "\\color[rgb]{0,0,0}\n"))
149
150 (define (polygon points blot-diameter fill)
151   (embedded-ps (list 'polygon `(quote ,points) blot-diameter fill)))
152
153 (define (draw-line thick fx fy tx ty)
154   (embedded-ps (list 'draw-line thick fx fy tx ty)))
155
156 ;; no-origin not yet supported by Xdvi
157 (define (no-origin) "")
158
159
160
161
162 (define-public (line-location  file line col)
163   "Print an input location, without column number ."
164   (string-append (number->string line) " " file))
165
166 (define-public point-and-click #f)
167
168 (define (grob-cause offset grob)
169   (define (line-column-location file line col)
170     "Print an input location, including column number ."
171     (string-append (number->string line) ":"
172                    (number->string col) " " file))
173
174   (if (procedure? point-and-click)
175       (let* ((cause (ly:grob-property grob 'cause))
176              (music-origin (if (ly:stream-event? cause)
177                                (ly:event-property cause 'origin)))
178              (location (if (ly:input-location? music-origin)
179                            (ly:input-file-line-column music-origin))))
180         (if (pair? location)
181              ;;; \\string ? 
182             (string-append "\\special{src:"
183                            (line-column-location location) "}")
184             ""))
185       ""))