Debian Codegraph @

texmf-dist/tex/optex/pkg/tikz.opm

raw
1 % This is macro package used by OpTeX, see http://petr.olsak.net/optex
2
3 \_codedecl \tikzpicture {TikZ for OpTeX <2023-03-04>}
4 \_namespace{pgf}
5 \_catcode`\@=11
6 \_let\_optexforeach=\foreach
7
8 \_doc
9 This package is \OpTeX/'s compatibility layer for PGF/TikZ. When users do
10 `\load[tikz]` they expect `tikz.tex` to be loaded, but this file gets loaded
11 instead. It does load `tikz.tex`, but also does fixups.
12
13 We want to change some definitions in `pgfutil-plain.def` and
14 `pgfsys-luatex.def`. We need to do that in right times, so we manually
15 emulate some files from PGF to ensure we do things in the correct order.
16 \_cod
17
18 %tikz.tex
19 % pgf.tex
20 % pgfrcs.tex
21 % pgfutil-common.tex
22 % pgfutil-common-lists.tex
23 % pgfutil-plain.tex
24 % pgfrcs.code.tex
25 % pgfcore.tex
26 % pgfsys.tex
27 % pgfsrcs.tex
28 % pgfsys.code.tex
29 % driver
30 % pgfcore.code.tex
31 % pgffor.tex
32 % pgfrcs.tex
33 % pgfkeys.code.tex
34 % pgffor.code.tex
35 % tikz.code.tex
36
37 \def\pgfrcsincluded{}
38 \input pgfutil-common.tex
39
40 \_doc
41 We load macros from `pgfutil-plain.def` because they are most
42 similar to macros we actually need. But there are several differences.
43 We don't want to load the output routine hack realized by
44 `\input atbegshi.sty\relax \AtBeginShipout{...}` in `pgfutil-plain.def`.
45 This is the reason why we re-define `\input` temporarily.
46 \_cod
47
48 \def\input#1\relax{}
49 \def\AtBeginShipout#1{}
50 \_input pgfutil-plain.def
51 \let\input=\_input
52 \let\AtBeginShipout=\_undefined
53 \let\end=\_end
54
55 \_doc
56 More changes should be done for macros loaded from `pgfutil-plain.def`.
57 These changes follows.
58 \_cod
59
60 % Writing to auxiliary files, customized
61
62 \_let\pgfutil@aux@read@hook=\_relax
63 \_def\pgfutil@writetoaux#1{}
64
65
66 % Driver detection, customized
67
68 \def\pgfsysdriver{pgfsys-luatex.def}
69
70
71 % Font stuff, \_typosize to fixed sizes used, math fonts are scaled too
72
73 \def\pgfutil@font@tiny{\_typosize[5/]}
74 \def\pgfutil@font@scriptsize{\_typosize[7/]}
75 \def\pgfutil@font@footnotesize{\_typosize[8/]}
76 \def\pgfutil@font@small{\_typosize[9/]}
77 \def\pgfutil@font@normalsize{\_typosize[10/]}
78 \def\pgfutil@font@large{\_typosize[12/]}
79 \def\pgfutil@font@Large{\_typosize[14.4/]}
80 \def\pgfutil@font@huge{\_typosize[20.74/]}
81 \def\pgfutil@font@Huge{\_typosize[24.88/]}
82
83 \def\pgfutil@font@normalfont{\_rm}
84 \def\pgfutil@font@itshape{\_it}
85 \def\pgfutil@font@bfseries{\_bf}
86 \def\pgfutil@selectfont{\_rm}
87
88 \_doc
89 PGF's `\pgfutil@everybye` hooks into `\end`, but normally \OpTeX/ uses the
90 prefixed `\_end`. Here we make it hook into `\_byehook` which should
91 hopefully be preserved by all \OpTeX/ macro writers.
92 \_cod
93
94 \_addto\_byehook{\_the\pgfutil@everybye}
95
96 \_doc
97 Make PGF/TikZ use our PDF resource management. Our functions expect split
98 key and value.
99 \_cod
100
101 \_def\.kvsplit#1{\_ea\.kvsplitA\_expanded{#1}\_end}
102 \_def\.kvsplitA#1/#2 #3\_end{{#2}{#3}}
103
104 \_def\pgfutil@addpdfresource@extgs{\_addpageresource{ExtGState}\.kvsplit}
105 \_def\pgfutil@addpdfresource@colorspaces{\_addpageresource{ColorSpace}\.kvsplit}
106 \_def\pgfutil@addpdfresource@patterns{\_addpageresource{Pattern}\.kvsplit}
107 \_let\pgfutil@setuppdfresources=\_relax
108 \_let\pgf@sys@pdf@check@resources=\_relax
109 \_def\pgf@sys@pdf@possible@resources{\_pageresources}
110
111 \_input pgfrcs.code.tex
112 \ProvidesPackageRCS{pgf.tex}
113 \_input pgfcore.tex
114 \usepgfmodule{shapes,plot}
115 \_input pgffor.tex
116 \_input tikz.code.tex
117
118 \_doc
119 More changes should be done for macros loaded from `pgfsys-luatex.def`.
120 These changes follows.
121
122 There is a general disagreement about the use/meaning of `\hoffset` and
123 `\voffset` -- \LaTeX/, the \LaTeX/ `crop`
124 package\fnote{\url{https://www.ctan.org/pkg/crop}}, TikZ, and \OpTeX/ all
125 try to use the values differently. Unfortunately this means a broken
126 behaviour observed by end users in
127 \OpTeX/\fnote{\url{https://github.com/pgf-tikz/pgf/issues/983}}.
128
129 The problem at hand is that PGF nowadays sets the page origin to include
130 `\hoffset` and `\voffset`. We instead set it to the origin (i.e. the point
131 $(0, 0)$).
132 \_cod
133
134 \_def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}
135
136 \_refdecl{%
137 \_def\.Xpgfsysmark#1#2#3{\_sdef{pgf@sys@pdf@mark@pos@#1}{\pgfqpoint{#2sp}{#3sp}}}%
138 }
139
140 \_def\pgfsys@markposition#1{%
141 \_openref
142 \_savepos
143 \_edef\.tmp{#1}%
144 \_ea\_wref\_ea\.Xpgfsysmark\_ea{\_ea{\.tmp}{\_the\_lastxpos}{\_the\_lastypos}}%
145 }
146
147 \_doc
148 I decide to keep \OpTeX's `\foreach` outside the Tikz environment.
149 The Tikz's `\foreach` is activated only inside its environment.
150 If you want to use Tikz's `\foreach` outside too then you can say
151 `\let\foreach=\_pgf_foreach`.
152 \_cod
153
154 \addto \tikz@startup@env {\let\foreach=\pgffor@foreach}
155 \_let\.foreach=\pgffor@foreach % \_pgf_foreach is \pgffor@foreach
156 \_let\foreach=\_optexforeach % \foreach is OpTeX's \foreach
157
158 \_let\.usetikzlibrary=\usetikzlibrary
159 \_def\usetikzlibrary#1{\_let\foreach=\.foreach
160 \.usetikzlibrary{#1}\let\foreach=\_optexforeach
161 }
162
163 % don't worry about resetting catcodes - we are at the end of \opinput'ed file
164 \_endnamespace
165 \_endcode
166
167 History:
168 2023-03-04 \_tikz_foreach used during \usetikzlibrary (bug fix).
169 2022-03-18 Tikz's \foreach only in its environment.
170 2022-03-05 resources management re-implemented.
171 2021-07-15 released