Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-svg.tex

raw
1 % $Id: tex4ht-svg.tex 472 2018-12-30 17:39:42Z karl $
2 % compile 3 times: latex tex4ht-svg
3 % or xhlatex tex4ht-svg "html,3,sections+"
4 %
5 % Copyright 2009-2018 TeX Users Group
6 % Copyright 2000-2009 Eitan M. Gurari
7 % Released under LPPL 1.3c+.
8 % See tex4ht-cpright.tex for license text.
9
10 %%%%%%%%%%%%%%%%%% load style files %%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \ifx \HTML\UnDef
13 \def\HTML{svg-option,html4-svg}
14 \def\CONFIG{\jobname}
15 \def\MAKETITLE{\author{Eitan M. Gurari}}
16 \def\next{\input mktex4ht.4ht \endinput}
17 \expandafter\next
18 \fi
19
20 \input{common.tex}
21 \input{tex4ht-cpright.tex}
22
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24 \chapter{Preamble}
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27 \<svg-option\><<<
28 % svg-option.4ht (|version), generated from |jobname.tex
29 % Copyright 2009-2018 TeX Users Group
30 % Copyright |CopyYear.2001. Eitan M. Gurari
31 |<TeX4ht copywrite|>
32 >>>
33
34 % 2017-05-05 Michal
35 % Change DTD and other stuff only for svg-inline
36 % this is legacy option which will hold the original `svg` option behaviour
37 \<configure svg-option tex4ht\><<<
38 \:CheckOption{svg-inline}\if:Option
39 \Configure{VERSION}
40 {\IgnorePar\HCode{<?xml version="1.0" |<xml encoding|> ?> \Hnewline}}
41 \Configure{DOCTYPE}{\HCode
42 {<!DOCTYPE html PUBLIC
43 "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//|<dtd lang|>"\Hnewline
44 "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">\Hnewline
45 <!--http://www.w3.org/TR/XHTMLplusMathMLplusSVG/-->\Hnewline
46 }}
47 >>>
48
49 \<xml encoding\><<<
50 encoding="\expandafter\ifx \csname a:charset\endcsname\relax
51 \expandafter\:encoding\A:charset
52 \else \expandafter\:encoding\a:charset\fi"
53 >>>
54
55 \<configure svg-option tex4ht\><<<
56 \Configure{@DOCTYPE}
57 {<!ENTITY \% svg.dtd PUBLIC "-//W3C//DTD SVG 20010719//|<dtd lang|>"\Hnewline
58 "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">\Hnewline
59 \%svg.dtd; \Hnewline}
60 >>>
61
62
63 \<configure html4-svg tex4ht\><<<
64 % hmtl-svg.4ht (|version), generated from |jobname.tex
65 % Copyright 2009-2018 TeX Users Group
66 % Copyright |CopyYear.2001. Eitan M. Gurari
67 |<TeX4ht copywrite|>
68 \Configure{@DOCTYPE}
69 {<!ENTITY \% misc "ins || del || script || noscript || svg">\Hnewline}
70 >>>
71
72
73 \<dtd lang\><<<
74 \expandafter
75 \ifx \csname a:dtd-lang\endcsname\relax EN\else
76 \csname a:dtd-lang\endcsname
77 \fi
78 >>>
79
80 \<configure svg-option tex4ht\><<<
81 \Configure{@HTML}
82 {\Hnewline xmlns:svg="http://www.w3.org/2000/svg"\Hnewline }
83 \fi
84 >>>
85
86
87
88 %%%%%%%%%%%%%%%%%%
89 \chapter{Code}
90 %%%%%%%%%%%%%%%%%%
91
92 %%%%%%%%%%%%%%%%%%
93 \section{DVI Images}
94 %%%%%%%%%%%%%%%%%%
95
96
97
98
99
100 \<configure svg-option tex4ht\><<<
101 \Configure{Picture}{.svg}
102 \:CheckOption{svg-obj} \if:Option
103 |<object svg-obj|>
104 \else \:CheckOption{svg-} \if:Option
105 |<object svg|>
106 \else
107 \Log:Note{for external SVG files
108 try the command line options `svg-obj' and 'svg-'}
109 \:CheckOption{svg-inline}\if:Option
110 |<internal svg|>
111 \fi
112 \fi\fi
113 >>>
114
115
116
117 \<object svg-obj\><<<
118 \Configure{IMG}
119 {\special{t4ht=<object type="image/svg+xml" data="}}
120 {\special{t4ht=" name="}}
121 {" }
122 {\special{t4ht=" }}
123 {\special{t4ht=></object>}}
124 >>>
125
126
127
128
129
130 \<object svg\><<<
131 \Configure{IMG}
132 {\special{t4ht=<object type="image/svg+xml"><img src="}}
133 {\special{t4ht=" alt="}}
134 {" }
135 {\special{t4ht=" }}
136 {\special{t4ht=/></object>}}
137 >>>
138
139
140 \<internal svg\><<<
141 \Configure{IMG}
142 {\special{t4ht=<!-- src="}}
143 {\special{t4ht=" alt="}}
144 {" }
145 {\special{t4ht=" }}
146 {\special{t4ht=-->}%
147 \openin15=\PictureFile \relax
148 \ifeof15 \:warning{\PictureFile\space is not available}%
149 \else \closein15 \special{t4ht*<\PictureFile}\fi
150 }
151 >>>
152
153
154
155
156 %%%%%%%%%%%%%%%%%%
157 \section{Include graphics}
158 %%%%%%%%%%%%%%%%%%
159
160 \<configure svg-option graphics\><<<
161 \Configure{graphics*}
162 {svg}
163 {{\Configure{Needs}{File: \csname Gin@base\endcsname.svg}\Needs{}}%
164 \special{t4ht=<object type="image/svg+xml"
165 data="\[email protected]"
166 name="picture \Gin@base"
167 class="graphics"></object><!--tex4ht:graphics |<graphics dim|>-->}}
168 >>>
169
170 \<graphics dim\><<<
171 \csname a:Gin-dim\endcsname
172 >>>
173
174 %%%%%%%%%%%%%%%%%%
175 \section{Support for th4:draw}
176 %%%%%%%%%%%%%%%%%%
177
178
179
180
181 \<configure svg-option th4\><<<
182 \:CheckOption{draw} \if:Option \:CheckOption{th4} \if:Option
183 \Configure{Fig}
184 {\Svg}
185 {\EndSvg}
186 \:CheckOption{svg-} \if:Option
187 |<embed svg draw|>
188 \else
189 |<internal svg draw|>
190 \fi
191 \fi \fi
192 >>>
193
194
195
196 \<external svg draw\><<<
197 \HAssign\:svgN = 0
198 \def\Svg{%
199 \gHAdvance\:svgN by 1
200 \HCode{<embed src="\jobname\:svgN.svg"\Hnewline
201 name="svg\:svgN" type="image/svg+xml"
202 % height="600" width="600"
203 \Hnewline pluginspage="http://www.adobe.com/svg/viewer/install/">}%
204 |<open embeded file|>%
205 |<open embeded svg|>%
206 \bgroup\Canvas \x:SUBOff \x:SUPOff
207 \let\Picture=\empty \everymath{}\everydisplay{}%
208 }
209 \def\EndSvg{\EndCanvas\egroup
210 |<close embeded svg|>%
211 |<close embeded file|>}
212 >>>
213
214
215
216
217
218 \<internal svg draw\><<<
219 \def\Svg{\HCode{<svg:svg>\Hnewline
220 <svg:g style="stroke:black; stroke-width:1;
221 stroke-opacity:1;">\Hnewline}%
222 \bgroup\Canvas \x:SUBOff \x:SUPOff
223 \let\Picture=\empty \everymath{}\everydisplay{}%
224 }
225 \def\EndSvg{\EndCanvas\egroup
226 \HCode{</svg:g></svg:svg>}}
227 >>>
228
229
230
231
232 \<embed svg draw\><<<
233 \let\:svg=\empty
234 \NewConfigure{Canvas}[4]{\ht:special{t4ht"%
235 *%
236 *d\Hnewline<!--width="\%.1f#4" %
237 *D height="\%.1f#4" %
238 *y above-baseline="\%.1f#4" -->%
239 **\Hnewline<\:svg text x="\%.1f" y="\%.1f" >%
240 *</\:svg text>%
241 *\Hnewline<\:svg rect x="\%.1f#4" y="\%.1f#4"
242 width="\%.1f#4" height="\%.1f#4" />%
243 *#1*#2*#1*#2*#3}}
244 \Configure{Canvas}{0.0000152587890625}{0.0}{0.5}{}
245 >>>
246
247
248 65536 scaled units = 1 pt. 1 / 65536 = 0.0000152587890625.
249
250 \<\><<<
251 \NewConfigure{Canvas}[4]{\ht:special{t4ht"%
252 *%
253 *d\Hnewline<!--width="\%.0f#4;" %
254 *D height="\%.0f#4;" -->\Hnewline %
255 % **<svg:text x="\%.0f" y="\%.0f" >%
256 % *</svg:text>\Hnewline %
257 **<svg:foreignObject x="\%.0f" y="\%.0f" >%
258 *</svg:foreignObject>\Hnewline %
259 % *\Hnewline<svg:rect x="\%.0f#4" y="\%.0f#4"
260 % width="\%.0f#4" height="\%.0f#4"
261 % fill="black" stroke-width="0" />%
262 *\Hnewline<svg:polyline points="\%.0f#4 \%.0f#4 \%.0f#4 \%.0f#4"
263 style="stroke-width:\%.0f#4" />%
264 *#1*#2*#1*#2*#3*2}}
265 >>>
266
267
268
269
270
271 \<open embeded file\><<<
272 \ht:special{t4ht>\jobname\:svgN.svg}%
273 \HCode{<?xml version="1.0" encoding="iso-8859-1"?>\Hnewline
274 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//|<dtd lang|>"\Hnewline
275 "http://www.w3.org/TR/2001/PR-SVG-20010719/DTD/svg10.dtd">
276 \Hnewline}
277 >>>
278
279 \<close embeded file\><<<
280 \ht:special{t4ht<\jobname\:svgN.svg}%
281 >>>
282
283 \<open embeded svg\><<<
284 \HCode{<\:svg svg>\Hnewline
285 <\:svg g style="stroke-width:0; fill:black;">\Hnewline}%
286 >>>
287
288 \<close embeded svg\><<<
289 \HCode{</\:svg g></\:svg svg>}%
290 >>>
291
292
293
294
295
296
297 %%%%%%%%%%%%%%%%%%
298 \chapter{Notes}
299 %%%%%%%%%%%%%%%%%%
300
301
302 Requires two compilations (e.g., with \verb!mzlatex try "html,svg"!)
303 for importing the SVG code.
304
305
306
307
308 \endinput
309