1% Copyright 2006 by Till Tantau 2% 3% This file may be distributed and/or modified 4% 5% 1. under the LaTeX Project Public License and/or 6% 2. under the GNU Public License. 7% 8% See the file doc/generic/pgf/licenses/LICENSE for more details. 9 10% PATCHED BY GZ for Stellarium Manual: 11% See https://tex.stackexchange.com/questions/185349/error-using-pgfsysdriver-with-tex4ht-only-shows-up-with-texlive-2014-ok-with-t 12 13\ProvidesFileRCS $Header: /cvsroot/pgf/pgf/generic/pgf/systemlayer/pgfsys-tex4ht.def,v 1.25 2013/08/06 17:46:08 tantau Exp $ 14 15 16 17% Driver commands for tex4ht 18 19% 20% Load common pdf commands: 21% 22\input pgfsys-common-svg.def 23 24% 25% tex4ht-specific stuff: 26% 27\def\pgfsys@invoke#1{\pgf@sys@fail{svg code in preamble}} 28\def\pgfsys@body@invoke#1{\HCode{#1}} 29 30\newcount\pgf@sys@svg@picnum 31 32\def\pgfsys@pictureboxsynced#1{% 33 \pgfsys@beginscope\pgflowlevelsynccm\box#1\pgfsys@endscope% 34} 35 36 37%% 38%% initial support of Mathml and xhtml inside svg through the svg:foreignelement tag 39%% 40%% it'll allow us to have complicated text nodes in the tex4ht driver 41%% 42 43 44%Example (to improve the display, you have to use css) 45% 46%\tikzpicture[svg text only=false] 47%\draw (0,0) node[inner sep=0pt,draw] {tight} 48%(0cm,2em) node[inner sep=5pt,draw] {loose} 49%(0cm,4em) node[fill=red!20] {default}; 50%\draw (3,0) node[inner sep=0pt,draw] {TIGHT} 51%(3cm,2em) node[inner sep=5pt,draw] {LOOSE} 52%(3cm,4em) node[fill=red!20] {DEFAULT}; 53%\draw (6,0) node[inner sep=0pt,draw] {$tight$} 54%(6cm,2em) node[inner sep=5pt,draw] {$loose$} 55%(6cm,4em) node[fill=red!20] {$default$}; 56%\draw (9,0) node[inner sep=0pt,draw] {$TIGHT$} 57%(9cm,2em) node[inner sep=5pt,draw] {$LOOSE$} 58%(9cm,4em) node[fill=red!20] {$Default$}; 59%\endtikzpicture 60% 61% you can use the options "svg text css=filename", "svg text id=idname", "svg text class=classname" to customize the display through the use of css 62% 63 64 65 66 67 68 69 70%\def\pgfsys@beginpicture{% 71% % \Configure{[]}{$}{$} these two lines aren't needed for tex4ht and moreother they produce errors with plain tex ! 72% % \Configure{()}{$}{$} 73% \Configure{$$}{}{}{}%$$ 74% \Configure{$}{}{}{}%$ 75% \Configure{SUB}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}} 76% \Configure{SUP}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}} 77% \Configure{SUBSUP}{}{}{} 78% \Configure{htf} 79% {0}{+}{<tspan font-family="} 80% {\%s}{" font-size="\%s}{}{} 81% {">}{</tspan>} 82%} 83 84 85 86%\def\pgfsys@endpicture{% 87% % undo: 88% \Configure{htf}{0}{+}{<span\Hnewline 89% class="}{\%s}{-\%s}{x-x-\%d}{}{">}{</span>} 90%} 91 92% GZ This was the buggy line. See note near top for URL. 93%\def\pgfsys@svg@newline{\Hnewline} 94\def\pgfsys@svg@newline{^^J} 95 96% we don't want tex4ht putting <p> and </p> tags automatically in our svg code and causing invalid xhtml in our svg pictures 97\newif\ifpgfsys@CssIncluded@\pgfsys@CssIncluded@false 98\def\pgfsys@beginpicture{% 99 \EndP\HtmlParOff 100 \pgfkeys{/pgf/tex4ht node/escape=false}% 101 % text only nodes are the default. Advantage : pure svg pictures are 102 % the default, nicer for text only nodes. 103 % Disadvantages : this rendering methods produce more invalid or degraded svg pictures than with the foreignelement tag 104 %% we use css to control the display of foreignelement rendered text nodes 105 \ifpgfsys@CssIncluded@ 106 \else 107 \Css{ 108 .foreignobject {% 109 line-height:100\%; 110 font-size:120\%; % this is the trick....a font of size 100% in 111 % a box scaled down to half size makes it a 112 % half size font. 113 % you'll have to double the size of things 114 % that you want to have a regular size in 115 % this half-scaled box though 116 font-family:STIXgeneral,Times,Symbol,cmr10,CMSY10,CMEX10;% 117 % can't wait for the stix font...the cmr10, etc font are 118 % available from the mozilla site, times and symbols should be 119 % okey 120 padding:0; 121 margin:0; 122 % background-color:\#12ff55; usefull for debugging positioning 123 text-align:center; % good for centered text nodes...will have to improve that later on...with more integration with pgf options for text nodes 124 } 125 }% 126 \Css{% 127 math {%, math[mode="inline"] { 128 vertical-align:baseline; 129 line-height:100\%; 130 font-size:100\%; 131 font-family:STIXGeneral,Times,Symbol, cmr10,cmsy10,cmex10,cmmi10; 132 font-style: normal; 133 margin:0; 134 % background-color:\#99ff99; 135 padding:0; 136 }% 137 }% 138 \pgfsys@CssIncluded@true 139 \fi 140}% 141 142\def\pgfsys@endpicture{% 143 \HtmlParOn 144 \par% FIXME : was '\Par' but that seems to be undefined!? 145}% 146 147% this is okay for both rendering methods for text nodes (mtext or foreignelement)... 148\def\pgfsys@typesetpicturebox#1{% 149 \global\advance\pgf@sys@svg@picnum by 1\relax% 150 % Ok, compute width/height 151 \pgf@xa=\pgf@picminx% 152 \pgf@ya=\pgf@picminy% 153 \pgf@xb=\pgf@picmaxx% 154 \pgf@yb=\pgf@picmaxy% 155 \pgf@x=\pgf@xb% 156 \advance\pgf@x by-\pgf@xa% 157 \pgf@y=\pgf@yb% 158 \advance\pgf@y by-\pgf@ya% 159 \ifdim\pgf@y<1pt% 160 \pgf@y=1pt% 161 \fi% 162 \pgf@xc=\pgf@x% 163 \pgf@yc=\pgf@y% 164 \pgfsysprotocol@flushcurrentprotocol% 165 \HCode{<object data="\jobname-\the\pgf@sys@svg@picnum.svg" width="}% 166 % Calculate pixel coordinates (this does not really make sense, but 167 % we have to do it anyway). Assume 96dpi. 168 \pgf@x=1.3333333\pgf@x% 169 \pgf@y=1.3333333\pgf@y% 170 % Add one pixel for security: 171 \advance\pgf@x by1pt% 172 \advance\pgf@y by1pt% 173 \pgf@sys@pt\pgf@x% 174 \pgfsysprotocol@flushcurrentprotocol% 175 \pgfsys@invoke{" height="}% 176 \pgf@sys@pt\pgf@y% 177 \pgfsysprotocol@flushcurrentprotocol% 178 \pgfsys@invoke{" type="image/svg+xml"><p>SVG-Viewer needed.</p></object>}% 179 \special{t4ht>\jobname-\the\pgf@sys@svg@picnum.svg}% 180 %%%%%%%% This is necessary to control the svg through css 181 \pgfkeys{% 182 /pgf/tex4ht node/css/.get=\pgfsys@foreignobject@css 183 }% 184 \pgfsys@invoke{<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>\Hnewline% added that 185 <?xml-stylesheet href="\pgfsys@foreignobject@css.css" type="text/css"?>\Hnewline}% added that 186%%%%%%%%%%%%%%% maybee I should add an option to change the css, for the whole picture 187 \pgfsys@invoke{<svg xmlns="http://www.w3.org/2000/svg" 188 xmlns:xlink="http://www.w3.org/1999/xlink" width="\the\pgf@xc" 189 height="\the\pgf@yc" viewBox="}% 190 \pgf@sys@pt{\pgf@xa}\pgf@sys@pt{\pgf@ya}\pgf@sys@pt{\pgf@xc}\pgf@sys@pt{\pgf@yc}% 191 \pgfsysprotocol@flushcurrentprotocol% 192 \pgf@ya=-\pgf@ya% 193 \pgfsys@invoke{">\Hnewline <g transform="translate(0,} 194 \pgf@sys@pt\pgf@yb\pgfsysprotocol@flushcurrentprotocol% 195 \pgfsys@invoke{) scale(1,-1) translate(0,}% 196 \pgf@sys@pt\pgf@ya\pgfsysprotocol@flushcurrentprotocol% 197 \pgfsys@invoke{)">\Hnewline }% 198 % 199 \pgf@ya=\pgf@shift@baseline\relax% 200 \advance\pgf@ya by-\pgf@picminy\relax% 201 % 202 % 203 \advance\pgf@picmaxy by-\pgf@picminy\relax% maxy is now the height 204 \advance\pgf@picmaxx by-\pgf@picminx\relax% maxx is now the width 205 \setbox#1=\hbox{\hskip-\pgf@picminx\lower\pgf@picminy\box#1}% 206 \ht#1=\pgf@picmaxy% 207 \wd#1=\pgf@picmaxx% 208 \dp#1=0pt% 209 \leavevmode 210 \pgf@xa=\pgf@trimleft@final\relax \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi 211 \raise-\pgf@ya\box#1% 212 \pgf@xa=\pgf@trimright@final\relax \ifdim\pgf@xa=0pt \else\kern\pgf@xa\fi 213 \pgfsys@invoke{</g>\Hnewline </svg>\Hnewline }% 214 \special{t4ht<\jobname-\the\pgf@sys@svg@picnum.svg}% 215}% 216 217%% we'll use this hbox for the mtext rendering method (the "text only=true" option) 218\def\pgfsys@hbox#1{% 219 \pgf@x=.5\wd#1% 220 \ifx\tikz@textcolor\relax\else\ifx\tikz@textcolor\@undefined\else% 221 \ifx\tikz@textcolor\pgfutil@empty% 222 \pgfsetfillcolor{.}% 223 \else% 224 \pgfsetfillcolor{\tikz@textcolor}% 225 \fi% 226 \fi\fi% tweak for TikZ 227 \HCode{<text 228 style="stroke:none" 229 transform="scale(1,-1) translate(\pgf@sys@tonumber{\pgf@x},0)" 230 text-anchor="middle" 231 }% 232 \ifpgfutil@format@is@latex% 233 \ifx\f@size\pgfutil@empty% 234 \else% 235 \HCode{ font-size="\f@size"}% 236 \fi% 237 \fi% 238 \HCode{>\Hnewline }% 239 \wd#1=0pt% 240 \ht#1=0pt% 241 \dp#1=0pt% 242 \box#1 243 \HCode{</text>\Hnewline }% 244}% 245 246%% we save this definition 247\let\pgfsys@mtext@hbox\pgfsys@hbox 248 249%% we have to use some "evil" ^^ tex4ht hackery 250% tex4ht hackery 251{% grouping necessary cause we change the catcode of ":" 252 \catcode`:=11\relax 253 %%% this is necessary to calculate the size of text nodes with 254 %%% inline maths 255 % (it is an improvement of tex4ht, got to ask eitan gurary if he 256 % could put it in the tex4ht code) 257 \gdef\DviMathAlt{% 258 \a:DviMath\leavevmode \MathClass 259 \ht:special{t4ht@(}\hbox\bgroup{\expandafter\ifx\csname 260 ht:everypar\endcsname\relax\expandafter\everypar\else 261 \expandafter\ht:everypar\fi{}\leavevmode\ht:special{t4ht@)}}\DviSend 262 }% 263 % these are configures for the foreignelement rendering method of text nodes : we let tex4ht write xhtml and mathml in the svg picture 264 % 265 \gdef\pgfsys@foreignobject@configure{% 266 \Configure{$}{\Configure{@math}{%\a:mathml 267 display="inline" }\DviMathAlt}{\EndDviMath}{}%%% we REALLY need to use \DviMathAlt here instead of \DviMath see above remark 268 \Configure{$$}{\Configure{@math}{%\a:mathml 269 display="block" }\IgnorePar 270 \ifvmode\else \HCode{<!--tex4ht:inline-->}\fi\EndP 271 \DviMath}{\EndDviMath\ShowPar\pgfsys@foreignobject@par{\csname HCondtrue\endcsname\noindent} 272 }{\DisplayMathtrue}% 273 \Configure{SUB}{\Send{BACK}{<\a:mathml msub><\a:mathml mrow\Hnewline>}% 274 \Tg</\a:mathml mrow>\Tg<\a:mathml mrow\Hnewline>\trap:base}{\Tg</\a:mathml mrow>\TG</\a:mathml msub\Hnewline>}% 275 \Configure{SUP}{\Send{BACK}{<\a:mathml msup><\a:mathml mrow\Hnewline>}% 276 \Tg</\a:mathml mrow>\Tg<\a:mathml mrow\Hnewline>\trap:base}{\Tg</\a:mathml mrow>\TG</\a:mathml msup\Hnewline>}% 277 \Configure{SUBSUP}{\Send{BACK}{<\a:mathml msubsup><\a:mathml mrow\Hnewline>}% 278 \Tg</\a:mathml mrow>\Tg<\a:mathml mrow\Hnewline>\trap:base}{\Tg</\a:mathml mrow>\Tg<\a:mathml mrow\Hnewline>\trap:base}{\Tg</\a:mathml mrow>\TG</\a:mathml msubsup\Hnewline>}% 279 \Configure{htf}{0}{+}{<span\Hnewline 280 class="}{\%s}{-\%s}{x-x-\%d}{}{">}{</span>}% 281 }% 282 \global\let\pgfsys@foreignobject@par=\par % use this instead of \par 283 % -- \Configure is no \long macro (at 284 % least in one of the older 285 % versions). 286 287 % these are the configures for the mtext rendering method of text 288 % nodes : we turn everything into regular character (don't want math 289 % modes or subsup) 290 % and we hope it works (it doesn't if the text nodes aren't simple) 291 \gdef\pgfsys@mtext@configure{% 292 % no configures for \(\) and \[\] those might be needed for 293 % context or Latex. Let me know ! 294 \Configure{$$}{}{}{}% no block maths 295 \Configure{$}{}{}{}%$ no inline maths 296 \Configure{SUB}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}}% 297 \Configure{SUP}{\HCode{<tspan baseline-shift="sub">}}{\HCode{</tspan>}}% 298 \Configure{SUBSUP}{}{}{}% not both sub and sup 299 \Configure{htf} {0}{+}{<tspan font-family="}{\%s}{" font-size="\%s}{}{}{">}{</tspan>}% 300 }% 301}% 302 303% a counter to produce unique ids for each text node rendered with foreign element 304\newcount\pgf@sys@svg@nodenum 305 306 307% pgfutil@minipage 308% 309% I had to change it to make it play nice with the way tex4ht puts <p> and <\p> tags 310% 311 312\newif\ifpgfsys@textonly 313\def\pgfutil@minipage[#1]#2{% 314 \hbox to#2\bgroup 315 \hsize=#2\relax 316 \vbox\bgroup 317% though it works, I'm desabling the above mentioned hack to make tex4ht behave with <p> <\p>, because it blurps the positioning 318% (I''l try to fix that later, it's a css thing) 319% 320% \ifpgfsys@textonly\else\HtmlParOn\fi 321% 322% \noindent is better as it doesn't produce indentation AND it makes you leave vertical mode 323 \noindent%\leavevmode 324}% 325\def\pgfutil@endminipage{% 326% same thing here 327% 328% \ifpgfsys@textonly\else\EndP\HtmlParOff\fi 329 \egroup\egroup 330}% 331 332 333% I'll have to fix those names later 334\newbox\pgfsys@foreignobject@Box 335\newdimen\pgf@s 336\newdimen\pgf@t 337% this is the alternate hbox routine that renders text nodes through the foreignobject tag 338\def\pgfsys@foreignobject@hbox#1{% 339 % Compute box y translation (x translation is correct). 340 \pgf@y=-\ht#1\relax 341 \HCode{<g transform="scale(1,-1) translate(0,\pgf@sys@tonumber{\pgf@y}) % got to translate in y 342 scale(0.5,0.5)">\Hnewline}% scaling work around (damn dumb browsers !) 343 % Compute box size (scaled 2 times) 344 % this is necessary to make the browser scale the font down 50% (the STUPID browsers won't make font-size:50% happen, 345 % so we have to work around this by making svg scale the things down 50%, doubling the size of the text node frame (i.e. no changement there) 346 \pgf@x=2\wd#1\relax 347 \pgf@y=2\ht#1\relax 348 \advance\pgf@y by 2\dp#1\relax 349 % this is to adjust the y translation to compensate for the differences between the TeX and the Html models for lines 350 \setbox\pgfsys@foreignobject@Box=\hbox{abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 351 $abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZf_1^1\overline D)_1^1\vec i\vec j$}% 352 \pgf@t=\ht#1\relax 353 \advance\pgf@t by -\ht\pgfsys@foreignobject@Box\relax 354 \pgf@s=\pgf@t\relax 355 \advance\pgf@s by \dp#1\relax 356 \advance\pgf@s by -\dp\pgfsys@foreignobject@Box\relax 357 \ifnum\pgf@s>0\relax 358 \pgf@s=0pt 359 \pgf@t=0pt 360 \else 361 \advance \pgf@y by -2\pgf@s\relax 362 \pgf@t=2\pgf@t\relax 363 \fi 364 % 365 \HCode{<foreignObject x="0" y="\pgf@sys@tonumber{\pgf@t}" 366 width="\pgf@sys@tonumber{\pgf@x}" height="\pgf@sys@tonumber{\pgf@y}">}% 367 % this is to make use of the css, class and id options through which you can control the way things display 368 \pgfkeys{% 369 /pgf/tex4ht node/css/.get=\pgfsys@foreignobject@css,% 370 /pgf/tex4ht node/class/.get=\pgfsys@foreignobject@class,% 371 /pgf/tex4ht node/id/.get=\pgfsys@foreignobject@id 372 }% 373 \HCode{<head>\Hnewline 374 <link rel="stylesheet" type="text/css" href="\pgfsys@foreignobject@css.css" />\Hnewline 375 </head>\Hnewline 376 % I'll have to look into this, perhaps there are better 377 % doctype.... aren't recognised and produces invalid svg 378 % pictures a workaround (not implemented yet) would be to make 379 % them into entities of the svg picture. 380 <body id="\pgfsys@foreignobject@id" class="\pgfsys@foreignobject@class" xmlns="http://www.w3.org/1999/xhtml" >\Hnewline 381 <div>\Hnewline 382 }% 383 \box#1% 384 \HCode{% 385 </div>\Hnewline 386 </body>\Hnewline 387 </foreignObject>\Hnewline 388 }% 389 % debug positioning not needed but it would be nice to let it there to control things later on 390 % \HCode{<rect x="0" y="0" width="\pgf@sys@tonumber{\pgf@x}" height="\pgf@sys@tonumber{\pgf@y}" 391 % style="fill:yellow;stroke:red; fill-opacity:0.5;stroke-opacity:0.5"/>} 392 \HCode{</g>\Hnewline}% 393 \global\advance\pgf@sys@svg@nodenum by 1\relax 394}% 395 396% the options and the code that controls it all (switches between \pgfsys@mtext@hbox and \pgfsys@foreignelement@hbox) 397 398\pgfkeys{% 399 /pgf/.cd, 400 tex4ht node/escape/.is choice, 401 tex4ht node/escape/false/.code={\let\pgfsys@hbox\pgfsys@mtext@hbox\pgfsys@mtext@configure\pgfsys@textonlytrue}, 402 tex4ht node/escape/true/.code={\let\pgfsys@hbox\pgfsys@foreignobject@hbox\pgfsys@foreignobject@configure\pgfsys@textonlyfalse}, 403 tex4ht node/css/.initial=\jobname, 404 tex4ht node/class/.initial=foreignobject, 405 tex4ht node/id/.initial=\jobname\the\pgf@sys@svg@picnum-\the\pgf@sys@svg@nodenum 406}% 407 408 409 410 411 412 413% this might be needed 414%\font\SvgText=cmr10\relax 415 416 417 418 419% There is something rellay wrong with the way "%" chars are used in here... you should code "}%" to avoid unnecessary spaces 420% and it is unnecessary to code \cs% 421% got to be carefull with numbers though, cf the texbook...2\relax and 2 % are okey 422 423\def\pgfsys@outerinvoke{\ifpgfpicture\expandafter\pgfsys@invoke\else\expandafter\pgfutil@gobble\fi} 424 425\def\pgfsys@shadingoutsidepgfpicture#1{\pgf@sys@fail{svg code in preamble}} 426\def\pgfsys@shadinginsidepgfpicture#1{\pgf@sys@fail{svg code in preamble}} 427 428\def\pgfsys@body@shadingoutsidepgfpicture#1{% 429 \begingroup% 430 #1% 431 \setbox\pgfpic=\hbox to0pt{% 432 \pgfsys@beginpicture% 433 \pgfsys@beginscope% 434 \pgf@sys@svg@sh@defs% 435 \pgf@sys@svg@sh% 436 \pgfsys@endscope% 437 \pgfsys@endpicture% 438 \hss% 439 }% 440 \pgf@process{\pgf@sys@svg@pos}% 441 \pgf@picminx=0pt% 442 \pgf@picminy=0pt% 443 \pgf@picmaxx=\pgf@x% 444 \pgf@picmaxy=\pgf@y% 445 \def\pgf@shift@baseline{0pt}% 446 \pgfsys@typesetpicturebox\pgfpic% 447 \endgroup% 448} 449 450\def\pgfsys@body@shadinginsidepgfpicture#1{% 451 #1% 452 \pgf@sys@svg@sh@defs% hmmm.... 453 \pgf@process{\pgf@sys@svg@pos} 454 \pgf@xa=-.5\pgf@x% 455 \pgf@ya=-.5\pgf@y% 456 \pgfsysprotocol@literal{<g transform="translate(\pgf@sys@tonumber{\pgf@xa},\pgf@sys@tonumber{\pgf@ya})">\Hnewline}% 457 \pgf@sys@svg@sh% 458 \pgfsysprotocol@literal{</g>\Hnewline}% 459} 460 461 462\ifpgfutil@format@is@latex 463 % Protect against color.4ht evil meddling with xcolor: 464 \RequirePackage{xcolor} 465 \let\pgf@xcolor@declaredcolor=\@declaredcolor 466 \let\pgf@xcolor@undeclaredcolor=\@undeclaredcolor 467\fi 468 469\AtBeginDocument{ 470 \let\pgfsys@invoke=\pgfsys@body@invoke 471 \let\pgfsys@shadingoutsidepgfpicture=\pgfsys@body@shadingoutsidepgfpicture 472 \let\pgfsys@shadinginsidepgfpicture=\pgfsys@body@shadinginsidepgfpicture 473 \ifpgfutil@format@is@latex 474 \let\pgf@texht@declaredcolor=\@declaredcolor 475 \let\pgf@texht@undeclaredcolor=\@undeclaredcolor 476 \def\@declaredcolor{\ifpgfpicture\expandafter\pgf@xcolor@declaredcolor\else\expandafter\pgf@texht@declaredcolor\fi} 477 \def\@undeclaredcolor{\ifpgfpicture\expandafter\pgf@xcolor@undeclaredcolor\else\expandafter\pgf@texht@undeclaredcolor\fi} 478 \fi 479 \def\pgfutil@color{\pgfsetcolor} 480 % \ConfigureEnv{pgfpicture}{}{}{}{} there is no environment in plain TeX and this produces errors 481 % this might be needed for context or latex though....let me know ! 482}% 483 484\endinput 485 486 487%%% Local Variables: 488%%% mode: latex 489%%% End: 490