1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 ;; The public interface is tight.
10 ;; It has to be, because user-code is evalled with this module.
12 ;; ***It should also be clean, well defined, documented and reviewed***
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.
19 (define-module (scm output-tex)
22 ;; JUNK this -- see lily.scm: ly:all-output-backend-commands
45 (use-modules (ice-9 regex)
61 (string-append "\\" (tex-font-command font)
62 "\\char" (ly:inexact->string i 10) " "))
67 (define (url-link url x y)
73 (define (circle radius thick)
74 (embedded-ps (list 'circle radius thick)))
76 (define (dot x y radius)
77 (embedded-ps (list 'dot x y radius)))
79 (define (embedded-ps string)
80 (embedded-ps (list 'embedded-ps string)))
82 (define (beam width slope thick blot)
83 (embedded-ps (list 'beam width slope thick blot)))
85 (define (dashed-slur thick on off lst)
86 (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
88 (define (named-glyph font name)
89 (let* ((info (ly:otf-font-glyph-info font name))
90 (subfont (assoc-get 'subfont info))
91 (subidx (assoc-get 'subfont-index info)))
93 ;;(stderr "INFO: ~S\n" info)
94 ;;(stderr "FONT: ~S\n" font)
95 (if (and subfont subidx)
96 (string-append "\\" (tex-font-command-raw
98 (ly:font-magnification font))
99 "\\char" (number->string subidx))
102 (ly:warning (_ "can't find ~a in ~a" name font))
105 (define (dashed-line thick on off dx dy)
106 (embedded-ps (list 'dashed-line thick on off dx dy)))
108 (define (zigzag-line centre? zzw zzh thick dx dy)
109 (embedded-ps (list 'zigzag-line centre? zzw zzh thick dx dy)))
111 (define (embedded-ps expr)
113 (with-output-to-string
114 (lambda () (ps-output-expression expr (current-output-port))))))
115 (string-append "\\embeddedps{" ps-string "}")))
117 (define (repeat-slash w a t)
118 (embedded-ps (list 'repeat-slash w a t)))
120 (define (number->dim x)
122 ;;ugh ly:* in backend needs compatibility func for standalone output
123 (ly:number->string x) " \\outputscale "))
125 (define (placebox x y s)
127 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
129 (define (bezier-sandwich lst thick)
130 (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
133 (define (round-filled-box x y width height blotdiam)
134 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
136 (define (text font s)
138 "\\hbox{\\~a{}~a}" (tex-font-command font)
139 (sanitize-tex-string s)))
141 (define (setcolor r g b)
142 (string-append "\\color[rgb]{"
143 (number->string r) ", "
144 (number->string g) ", "
145 (number->string b) "}"))
148 ;; The PostScript backend saves the current color
149 ;; during setcolor and restores it during resetcolor.
150 ;; We don't do that here.
152 (string-append "\\color[rgb]{0,0,0}\n"))
154 (define (polygon points blotdiameter fill)
155 (embedded-ps (list 'polygon `(quote ,points) blotdiameter fill)))
157 (define (draw-line thick fx fy tx ty)
158 (embedded-ps (list 'draw-line thick fx fy tx ty)))
160 ;; no-origin not yet supported by Xdvi
161 (define (no-origin) "")
166 (define-public (line-location file line col)
167 "Print an input location, without column number ."
168 (string-append (number->string line) " " file))
170 (define-public point-and-click #f)
172 (define (grob-cause offset grob)
173 (define (line-column-location file line col)
174 "Print an input location, including column number ."
175 (string-append (number->string line) ":"
176 (number->string col) " " file))
178 (if (procedure? point-and-click)
179 (let* ((cause (ly:grob-property grob 'cause))
180 (music-origin (if (ly:music? cause)
181 (ly:music-property cause 'origin)))
182 (location (if (ly:input-location? music-origin)
183 (ly:input-file-line-column music-origin))))
186 (string-append "\\special{src:"
187 (line-column-location location) "}")