1 ;;;; tex.scm -- implement Scheme output routines for TeX
3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 1998--2007 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)
58 (string-append "\\" (tex-font-command font)
59 "\\char" (ly:inexact->string i 10) " "))
64 (define (url-link url x y)
70 (define (circle radius thick)
71 (embedded-ps (list 'circle radius thick)))
73 (define (dot x y radius)
74 (embedded-ps (list 'dot x y radius)))
76 (define (embedded-ps string)
77 (embedded-ps (list 'embedded-ps string)))
79 (define (dashed-slur thick on off lst)
80 (embedded-ps (list 'dashed-slur thick on off `(quote ,lst))))
82 (define (named-glyph font name)
83 (let* ((info (ly:otf-font-glyph-info font name))
84 (subfont (assoc-get 'subfont info))
85 (subidx (assoc-get 'subfont-index info)))
87 ;;(stderr "INFO: ~S\n" info)
88 ;;(stderr "FONT: ~S\n" font)
89 (if (and subfont subidx)
90 (string-append "\\" (tex-font-command-raw
92 (ly:font-magnification font))
93 "\\char" (number->string subidx))
96 (ly:warning (_ "cannot find ~a in ~a" name font))
99 (define (dashed-line thick on off dx dy phase)
100 (embedded-ps (list 'dashed-line thick on off dx dy phase)))
102 (define (embedded-ps expr)
104 (with-output-to-string
105 (lambda () (ps-output-expression expr (current-output-port))))))
106 (string-append "\\embeddedps{" ps-string "}")))
108 (define (repeat-slash w a t)
109 (embedded-ps (list 'repeat-slash w a t)))
111 (define (number->dim x)
113 ;;ugh ly:* in backend needs compatibility func for standalone output
114 (ly:number->string x) " \\output-scale "))
116 (define (placebox x y s)
118 "\\lyitem{" (ly:number->string x) "}{" (ly:number->string y) "}{" s "}%\n"))
120 (define (bezier-sandwich lst thick)
121 (embedded-ps (list 'bezier-sandwich `(quote ,lst) thick)))
124 (define (round-filled-box x y width height blotdiam)
125 (embedded-ps (list 'round-filled-box x y width height blotdiam)))
127 (define (text font s)
129 "\\hbox{\\~a{}~a}" (tex-font-command font)
130 (sanitize-tex-string s)))
132 (define (setcolor r g b)
133 (string-append "\\color[rgb]{"
134 (number->string r) ", "
135 (number->string g) ", "
136 (number->string b) "}"))
139 ;; The PostScript backend saves the current color
140 ;; during setcolor and restores it during resetcolor.
141 ;; We don't do that here.
143 (string-append "\\color[rgb]{0,0,0}\n"))
145 (define (polygon points blot-diameter fill)
146 (embedded-ps (list 'polygon `(quote ,points) blot-diameter fill)))
148 (define (draw-line thick fx fy tx ty)
149 (embedded-ps (list 'draw-line thick fx fy tx ty)))
151 ;; no-origin not yet supported by Xdvi
152 (define (no-origin) "")
155 (define-public (line-location file line col)
156 "Print an input location, without column number ."
157 (string-append (number->string line) " " file))
159 (define-public point-and-click #f)
161 (define (grob-cause offset grob)
162 (define (line-column-location file line col)
163 "Print an input location, including column number ."
164 (string-append (number->string line) ":"
165 (number->string col) " " file))
167 (if (procedure? point-and-click)
168 (let* ((cause (ly:grob-property grob 'cause))
169 (music-origin (if (ly:stream-event? cause)
170 (ly:event-property cause 'origin)))
171 (location (if (ly:input-location? music-origin)
172 (ly:input-file-line-column music-origin))))
175 (string-append "\\special{src:"
176 (line-column-location location) "}")