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