]> git.donarmstrong.com Git - lilypond.git/blob - scm/output-tex.scm
6a0cebe77ec9f5372fe2b74c9b9febb8f3234f70
[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 (define-module (scm output-tex)
15   #:re-export (quote)
16   #:export (unknown
17              blank
18              dot
19              beam
20              bracket
21              dashed-slur
22              char
23              dashed-line
24              zigzag-line
25              symmetric-x-triangle
26              ez-ball
27              comment
28              repeat-slash
29              placebox
30              bezier-sandwich
31              horizontal-line
32              filledbox
33              round-filled-box
34              text
35              tuplet
36              polygon
37              draw-line
38              define-origin
39              no-origin
40              ))
41
42 (use-modules (ice-9 regex)
43              (ice-9 string-fun)
44              (ice-9 format)
45              (guile)
46              (srfi srfi-13)
47              (scm framework-tex)
48              (lily))
49
50 ;;;;;;;;
51 ;;;;;;;; DOCUMENT ME!
52 ;;;;;;;;
53
54
55
56 (define (unknown) 
57   "%\n\\unknown\n")
58
59
60
61 (define (blank)
62   "")
63
64 (define (dot x y radius)
65   (embedded-ps (list 'dot x y radius)))
66
67 (define (beam width slope thick blot)
68   (embedded-ps (list 'beam  width slope thick blot)))
69
70 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
71   (embedded-ps (list 'bracket  arch_angle arch_width arch_height height arch_thick thick)))
72
73 (define (dashed-slur thick dash l)
74   (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
75
76 (define (char font i)
77   (string-append "\\" (tex-font-command font)
78                  "\\char" (ly:inexact->string i 10) " "))
79
80 (define (dashed-line thick on off dx dy)
81   (embedded-ps (list 'dashed-line  thick on off dx dy)))
82
83 (define (zigzag-line centre? zzw zzh thick dx dy)
84   (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
85
86 (define (symmetric-x-triangle t w h)
87   (embedded-ps (list 'symmetric-x-triangle t w h)))
88
89
90 (define (ez-ball c l b)
91   (embedded-ps (list 'ez-ball  c  l b)))
92
93
94
95 (define (embedded-ps expr)
96   (let ((ps-string
97          (with-output-to-string
98            (lambda () (ps-output-expression expr (current-output-port))))))
99     (string-append "\\embeddedps{" ps-string "}")))
100   
101 (define (comment s)
102   (string-append "% " s "\n"))
103
104 (define (end-output)
105   (begin
106     ;; uncomment for some stats about lily memory         
107     ;; (display (gc-stats))
108     (string-append
109      "\\lilypondend\n"
110      ;; Put GC stats here.
111      )))
112
113 (define (repeat-slash w a t)
114   (embedded-ps (list 'repeat-slash  w a t)))
115
116
117
118 (define (number->dim x)
119   (string-append
120    ;;ugh ly:* in backend needs compatibility func for standalone output
121    (ly:number->string x) " \\outputscale "))
122
123 (define (placebox x y s) 
124   (string-append
125    "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
126
127 (define (bezier-sandwich l thick)
128   (embedded-ps (list 'bezier-sandwich  `(quote ,l) thick)))
129
130 ;; WTF is this in every backend?
131 (define (horizontal-line x1 x2 th)
132   (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
133
134 (define (filledbox breapth width depth height)
135   (if (and #f (defined? 'ps-testing))
136       (embedded-ps
137        (string-append (ly:numbers->string (list breapth width depth height))
138                       " draw_box" ))
139       (string-append "\\lyvrule{"
140                      (ly:number->string (- breapth)) "}{"
141                      (ly:number->string (+ breapth width)) "}{"
142                      (ly:number->string depth) "}{"
143                      (ly:number->string height) "}")))
144
145 (define (round-filled-box x y width height blotdiam)
146   (embedded-ps (list 'round-filled-box  x y width height blotdiam)))
147
148 (define (text font s)
149   (let*
150       ((mapping #f)       ;; (assoc-get  'char-mapping (ly:font-encoding-alist font))))
151
152
153        ;; TODO: we'd better do this for PS only
154        ;; LaTeX gets in the way, and we need to remap
155        ;; nonprintable chars.
156        
157        (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
158        )
159
160     (string-append "\\hbox{\\" (tex-font-command font)
161                    (if (string? input-enc-name)
162                        (string-append "\\inputencoding{" input-enc-name "}")
163                        "{}")
164                    (sanitize-tex-string
165                     (if (vector? mapping)
166                         (reencode-string mapping s)
167                         s))
168                    "}")))
169
170
171 (define (tuplet ht gapx dx dy thick dir)
172   (embedded-ps (list 'tuplet  ht gapx dx dy thick dir)))
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 (define (define-origin file line col)
181   (if (procedure? point-and-click)
182       (string-append "\\special{src:" ;;; \\string ? 
183                      (point-and-click line col file)
184                      "}" )
185       ""))
186
187 ;; no-origin not yet supported by Xdvi
188 (define (no-origin) "")
189