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