1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; Han-Wen Nienhuys <hanwen@xs4all.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
43 (use-modules (ice-9 regex)
59 (string-append "\\" (tex-font-command font)
60 "\\char" (ly:inexact->string i 10) " "))
65 (define (url-link url x y)
71 (define (circle radius thick)
72 (embedded-ps (list 'circle radius thick)))
74 (define (dot x y radius)
75 (embedded-ps (list 'dot x y radius)))
77 (define (embedded-ps string)
78 (embedded-ps (list 'embedded-ps string)))
80 (define (dashed-slur thick on off lst)
81 (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
83 (define (named-glyph font name)
84 (let* ((info (ly:otf-font-glyph-info font name))
85 (subfont (assoc-get 'subfont info))
86 (subidx (assoc-get 'subfont-index info)))
88 ;;(stderr "INFO: ~S\n" info)
89 ;;(stderr "FONT: ~S\n" font)
90 (if (and subfont subidx)
91 (string-append "\\" (tex-font-command-raw
93 (ly:font-magnification font))
94 "\\char" (number->string subidx))
97 (ly:warning (_ "cannot find ~a in ~a" name font))
100 (define (dashed-line thick on off dx dy phase)
101 (embedded-ps (list 'dashed-line thick on off dx dy phase)))
103 (define (embedded-ps expr)
105 (with-output-to-string
106 (lambda () (ps-output-expression expr (current-output-port))))))
107 (string-append "\\embeddedps{" ps-string "}")))
109 (define (repeat-slash w a t)
110 (embedded-ps (list 'repeat-slash w a t)))
112 (define (number->dim x)
114 ;;ugh ly:* in backend needs compatibility func for standalone output
115 (ly:number->string x) " \\output-scale "))
117 (define (placebox x y s)
119 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
121 (define (bezier-sandwich lst thick)
122 (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
125 (define (round-filled-box x y width height blotdiam)
126 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
128 (define (text font s)
130 "\\hbox{\\~a{}~a}" (tex-font-command font)
131 (sanitize-tex-string s)))
133 (define (setcolor r g b)
134 (string-append "\\color[rgb]{"
135 (number->string r) ", "
136 (number->string g) ", "
137 (number->string b) "}"))
140 ;; The PostScript backend saves the current color
141 ;; during setcolor and restores it during resetcolor.
142 ;; We don't do that here.
144 (string-append "\\color[rgb]{0,0,0}\n"))
146 (define (polygon points blot-diameter fill)
147 (embedded-ps (list 'polygon `(quote ,points) blot-diameter fill)))
149 (define (draw-line thick fx fy tx ty)
150 (embedded-ps (list 'draw-line thick fx fy tx ty)))
152 ;; no-origin not yet supported by Xdvi
153 (define (no-origin) "")
156 (define-public (line-location file line col)
157 "Print an input location, without column number ."
158 (string-append (number->string line) " " file))
160 (define-public point-and-click #f)
162 (define (grob-cause offset grob)
163 (define (line-column-location file line col)
164 "Print an input location, including column number ."
165 (string-append (number->string line) ":"
166 (number->string col) " " file))
168 (if (procedure? point-and-click)
169 (let* ((cause (ly:grob-property grob 'cause))
170 (music-origin (if (ly:stream-event? cause)
171 (ly:event-property cause 'origin)))
172 (location (if (ly:input-location? music-origin)
173 (ly:input-file-line-column music-origin))))
176 (string-append "\\special{src:"
177 (line-column-location location) "}")