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