]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
Fix internalsrefs
[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--2004 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
73
74 (define (blank)
75   "")
76
77 (define (dot x y radius)
78   (embedded-ps (list 'dot x y radius)))
79
80
81 (define (embedded-ps string)
82   (embedded-ps (list 'embedded-ps string)))
83
84 (define (white-dot x y radius)
85   (embedded-ps (list 'white-dot x y radius)))
86
87 (define (beam width slope thick blot)
88   (embedded-ps (list 'beam  width slope thick blot)))
89
90 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
91   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
92
93 (define (dashed-slur thick dash l)
94   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
95
96 (define (named-glyph font name)
97   (let* ((info (ly:otf-font-glyph-info font name))
98          (subfont (assoc-get 'subfont info))
99          (subidx  (assoc-get 'subfont-index info)))
100     
101     ;;(stderr "INFO: ~S\n" info)
102     ;;(stderr "FONT: ~S\n" font)
103     (if (and subfont subidx)
104         (string-append "\\" (tex-font-command-raw
105                              subfont
106                              (ly:font-magnification font))
107                        "\\char" (number->string subidx))
108
109         (begin
110           (ly:warn "Can't find ~a in ~a" name font)
111           ""))))
112
113 (define (dashed-line thick on off dx dy)
114   (embedded-ps (list 'dashed-line  thick on off dx dy)))
115
116 (define (zigzag-line centre? zzw zzh thick dx dy)
117   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
118
119 (define (ez-ball c l b)
120   (embedded-ps (list 'ez-ball c l b)))
121
122 (define (embedded-ps expr)
123   (let ((ps-string
124          (with-output-to-string
125            (lambda () (ps-output-expression expr (current-output-port))))))
126     (string-append "\\embeddedps{" ps-string "}")))
127
128 (define (repeat-slash w a t)
129   (embedded-ps (list 'repeat-slash  w a t)))
130
131 (define (number->dim x)
132   (string-append
133    ;;ugh ly:* in backend needs compatibility func for standalone output
134    (ly:number->string x) " \\outputscale "))
135
136 (define (placebox x y s) 
137   (string-append
138    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
139
140 (define (bezier-sandwich l thick)
141   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
142
143 ;; WTF is this in every backend?
144 (define (horizontal-line x1 x2 th)
145   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
146
147 (define (filledbox breapth width depth height)
148   (if (and #f (defined? 'ps-testing))
149       (embedded-ps
150        (string-append (ly:numbers->string (list breapth width depth height))
151                       " draw_box" ))
152       (string-append "\\lyvrule{"
153                      (ly:number->string (- breapth)) "}{"
154                      (ly:number->string (+ breapth width)) "}{"
155                      (ly:number->string depth) "}{"
156                      (ly:number->string height) "}")))
157
158 (define (round-filled-box x y width height blotdiam)
159   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
160
161 (define (text font s)
162   ;; (assoc-get 'char-mapping (ly:font-encoding-alist font))))  
163   (let* ((mapping #f)
164
165          ;; TODO: we'd better do this for PS only
166          ;; LaTeX gets in the way, and we need to remap
167          ;; nonprintable chars.
168          
169          ;; (assoc-get 'input-name (ly:font-encoding-alist font)))
170          
171          (input-enc-name #f))
172
173     (string-append "\\hbox{\\" (tex-font-command font)
174                    (if (string? input-enc-name)
175                        (string-append "\\inputencoding{" input-enc-name "}")
176                        "{}")
177                    (sanitize-tex-string
178                     (if (vector? mapping)
179                         (reencode-string mapping s)
180                         s))
181                    "}")))
182
183 (define (white-text scale s)
184   (embedded-ps (list 'white-text scale s)))
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 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-location music-origin))))
202         (if (pair? location)
203              ;;; \\string ? 
204             (string-append "\\special{src:"
205                            (apply point-and-click location) "}")
206             ""))
207       ""))