1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;; (debug-enable 'backtrace)
11 ;; The public interface is tight.
12 ;; It has to be, because user-code is evalled with this module.
14 ;; ***It should also be clean, well defined, documented and reviewed***
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.
21 (define-module (scm output-tex)
50 (use-modules (ice-9 regex)
72 (define (dot x y radius)
73 (embedded-ps (list 'dot x y radius)))
75 (define (white-dot x y radius)
76 (embedded-ps (list 'white-dot x y radius)))
78 (define (beam width slope thick blot)
79 (embedded-ps (list 'beam width slope thick blot)))
81 (define (bracket arch_angle arch_width arch_height height arch_thick thick)
82 (embedded-ps (list 'bracket arch_angle arch_width arch_height height arch_thick thick)))
84 (define (dashed-slur thick dash l)
85 (embedded-ps (list 'dashed-slur thick dash `(quote ,l))))
88 (string-append "\\" (tex-font-command font)
89 "\\char" (ly:inexact->string i 10) " "))
91 (define (dashed-line thick on off dx dy)
92 (embedded-ps (list 'dashed-line thick on off dx dy)))
94 (define (zigzag-line centre? zzw zzh thick dx dy)
95 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
97 (define (symmetric-x-triangle t w h)
98 (embedded-ps (list 'symmetric-x-triangle t w h)))
101 (define (ez-ball c l b)
102 (embedded-ps (list 'ez-ball c l b)))
106 (define (embedded-ps expr)
108 (with-output-to-string
109 (lambda () (ps-output-expression expr (current-output-port))))))
110 (string-append "\\embeddedps{" ps-string "}")))
113 (define (repeat-slash w a t)
114 (embedded-ps (list 'repeat-slash w a t)))
118 (define (number->dim x)
120 ;;ugh ly:* in backend needs compatibility func for standalone output
121 (ly:number->string x) " \\outputscale "))
123 (define (placebox x y s)
125 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
127 (define (bezier-sandwich l thick)
128 (embedded-ps (list 'bezier-sandwich `(quote ,l) thick)))
130 ;; WTF is this in every backend?
131 (define (horizontal-line x1 x2 th)
132 (filledbox (- x1) (- x2 x1) (* .5 th) (* .5 th)))
134 (define (filledbox breapth width depth height)
135 (if (and #f (defined? 'ps-testing))
137 (string-append (ly:numbers->string (list breapth width depth height))
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) "}")))
145 (define (round-filled-box x y width height blotdiam)
146 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
148 (define (text font s)
150 ((mapping #f) ;; (assoc-get 'char-mapping (ly:font-encoding-alist font))))
153 ;; TODO: we'd better do this for PS only
154 ;; LaTeX gets in the way, and we need to remap
155 ;; nonprintable chars.
157 (input-enc-name #f) ;; (assoc-get 'input-name (ly:font-encoding-alist font) ))
160 (string-append "\\hbox{\\" (tex-font-command font)
161 (if (string? input-enc-name)
162 (string-append "\\inputencoding{" input-enc-name "}")
165 (if (vector? mapping)
166 (reencode-string mapping s)
171 (define (tuplet ht gapx dx dy thick dir)
172 (embedded-ps (list 'tuplet ht gapx dx dy thick dir)))
174 (define (polygon points blotdiameter)
175 (embedded-ps (list 'polygon `(quote ,points) blotdiameter)))
177 (define (draw-line thick fx fy tx ty)
178 (embedded-ps (list 'draw-line thick fx fy tx ty)))
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)
187 ;; no-origin not yet supported by Xdvi
188 (define (no-origin) "")