m-tikz.mkxl /size: 7874 b    last modification: 2024-01-16 09:03
1%D \module
2%D   [       file=m-tikz,
3%D        version=2021.07.12,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=TIKZ support,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D A fixed variant of the t-tikz module distributed with tikz. For practical reasons
15%D per 2021 we split the module for \MKIV\ and \LMTX. (Maybe some day I'll optimize
16%D TIKZ a bit.)
17%D
18%D All these t-* modules in the tikz distribution make no sense as we can just load
19%D them here which is way cleaner. There is also some mkii filename mapping going on
20%D that is not needed on todays systems (windows has no 8.3 limitation and on unix
21%D tds finally adopted a case insensitive approach.)
22
23%D Just in case someone does a hard input ...
24
25\ifdefined\pgfdefined    \endinput \fi
26\ifdefined\pgfcoredefined\endinput \fi
27
28%D ... but normally we end up here:
29
30\startmodule[tikz]
31
32\ifdefined\hoffset \else
33    \newdimen\hoffset
34    \newdimen\voffset
35\fi
36
37\ifdefined\pdflastxpos \else
38    \unprotect
39        \frozen\overloaded\protected\def\pdflastxpos{\numexpr\clf_lastxpos\relax}
40        \frozen\overloaded\protected\def\pdflastypos{\numexpr\clf_lastypos\relax}
41    \protect
42\fi
43
44\ifdefined\pdfstrcmp\else
45
46    \startluacode
47        interfaces.implement {
48            name      = "pdfstrcmp",
49            arguments = "2 strings",
50            usage     = "value",
51            public    = true,
52            actions   = function(a,b)
53                return
54                    tokens.values.integer,
55                    (a < b and -1) or (a > b and 1) or 0
56            end
57        }
58    \stopluacode
59
60\fi
61
62\newcatcodetable \tikzcatcodes
63
64\startcatcodetable \tikzcatcodes
65    \catcode\tabasciicode             \spacecatcode
66    \catcode\endoflineasciicode       \endoflinecatcode
67    \catcode\formfeedasciicode        \endoflinecatcode
68    \catcode\spaceasciicode           \spacecatcode
69    \catcode\endoffileasciicode       \ignorecatcode
70    \catcode\circumflexasciicode      \superscriptcatcode
71    \catcode\underscoreasciicode      \subscriptcatcode
72    \catcode\ampersandasciicode       \alignmentcatcode
73    \catcode\backslashasciicode       \escapecatcode
74    \catcode\leftbraceasciicode       \begingroupcatcode
75    \catcode\rightbraceasciicode      \endgroupcatcode
76    \catcode\dollarasciicode          \mathshiftcatcode
77    \catcode\hashasciicode            \parametercatcode
78    \catcode\commentasciicode         \commentcatcode
79    \catcode\atsignasciicode          \lettercatcode
80    \catcode\exclamationmarkasciicode \othercatcode
81    \catcode\questionmarkasciicode    \lettercatcode
82    \catcode\tildeasciicode           \activecatcode
83    \catcode\barasciicode             \othercatcode
84\stopcatcodetable
85
86\newinteger\tikzinputlevel
87
88\permanent\protected\def\starttikzinput
89  {\advance\tikzinputlevel\plusone
90   \ifcase\tikzinputlevel\or
91     \pushoverloadmode
92     \pushcatcodetable
93     \setcatcodetable\tikzcatcodes
94     \pushmacro\meaning
95     \let\meaning\meaningless
96     \autoparagraphmode\zerocount
97  \fi}
98
99\permanent\protected\def\stoptikzinput
100  {\autoparagraphmode\plusone
101   \ifcase\tikzinputlevel\or
102     \popcatcodetable
103     \popmacro\meaning
104     \popoverloadmode
105   \fi
106   \advance\tikzinputlevel\minusone}
107
108\permanent\protected\def\tikzinputfile#1%
109  {\starttikzinput
110   \input{#1}\relax
111   \stoptikzinput}
112
113\permanent\protected\def\tikzerrormessage#1#2#3%
114  {\writestatus{#1}{#2}}
115
116% For now we need this but we need to educate the user to wrap settings in the
117% wrappers. So some day the next line will go. I need to check what commands are
118% possible outside a picture.
119
120\overloadmode\zerocount
121
122\newtoks\everytikzpicture
123\newtoks\everyinsidetikzpicture
124
125% \appendtoks
126%     \resetcharacterspacing
127% \to \everytikzpicture
128
129\permanent\protected\def\starttikzsettings
130  {\pushoverloadmode
131   \pushcatcodetable
132   \setcatcodetable\tikzcatcodes
133   \pushmacro\meaning
134   \let\meaning\meaningless
135   \autoparagraphmode\zerocount}
136
137\permanent\protected\def\stoptikzsettings
138  {\autoparagraphmode\plusone
139   \popmacro\meaning
140   \popcatcodetable
141   \popoverloadmode}
142
143\permanent\tolerant\protected\def\starttikzpicture[#S#1]%
144  {\dontleavehmode
145   \hcontainer\bgroup
146   \setcatcodetable\tikzcatcodes
147   \the\everytikzpicture
148   \autoparagraphmode\zerocount
149   \pushmacro\meaning
150   \let\meaning\meaningless
151 % \pushoverloadmode
152   \ifdefined\PackageError\else \let\PackageError\tikzerrormessage \fi
153   \tikzpicture[#1]%
154   \the\everyinsidetikzpicture}
155
156\permanent\protected\def\stoptikzpicture
157  {\endtikzpicture
158 % \popoverloadmode
159   \popmacro\meaning
160   \egroup}
161
162\let\pgfdefined    \relax
163\let\pgfcoredefined\relax
164
165\tikzinputfile{pgfutil-common.tex}
166\tikzinputfile{pgfutil-context.def}
167\tikzinputfile{pgfrcs.code.tex}
168\tikzinputfile{pgfsys.code.tex}
169\tikzinputfile{pgfkeys.code.tex}
170\tikzinputfile{pgfsyssoftpath.code.tex}
171\tikzinputfile{pgfsysprotocol.code.tex}
172\tikzinputfile{pgfcore.code.tex}
173\tikzinputfile{pgffor.code.tex}
174\tikzinputfile{pgfmoduleplot.code.tex}
175\tikzinputfile{tikz.code.tex}
176
177\let\startpgfpicture             \pgfpicture              \let\stoppgfpicture            \endpgfpicture
178\let\startpgfscope               \pgfscope                \let\stoppgfscope              \endpgfscope
179\let\startpgflowlevelscope       \pgflowlevelscope        \let\stoppgflowlevelscope      \endpgflowlevelscope
180\let\startpgfinterruptpath       \pgfinterruptpath        \let\stoppgfinterruptpath      \endpgfinterruptpath
181\let\startpgfinterruptpicture    \pgfinterruptpicture     \let\stoppgfinterruptpicture   \endpgfinterruptpicture
182\let\startpgfinterruptboundingbox\pgfinterruptboundinbox  \let\stoppgfinterruptboudingbox\endpgfinterruptboundingbox
183
184\let\normalusepgfmodule  \usepgfmodule
185\let\normalusepgflibrary \usepgflibrary
186\let\normalusetikzlibrary\usetikzlibrary
187
188\installnamespace{pgfmhack}
189\installnamespace{pgflhack}
190\installnamespace{tikzhack}
191
192\tolerant\protected\def\usepgfmodule[#1]#;#2% somehow both variants are used
193  {\starttikzinput
194   \normalusepgfmodule[#1#2]%
195   \stoptikzinput}
196
197\tolerant\protected\def\usepgflibrary[#1]#;#2% somehow both variants are used
198  {\starttikzinput
199   \normalusepgflibrary[#1#2]%
200   \stoptikzinput}
201
202\tolerant\protected\def\usetikzlibrary[#1]#;#2% somehow both variants are used
203  {\starttikzinput
204   \normalusetikzlibrary[#1#2]%
205   \stoptikzinput}
206
207\unprotect
208
209\protected\def\installsomethingtikzindeed#1#2#3#4%
210  {\defcsname#1:b:#2\endcsname{#3}%
211   \defcsname#1:a:#2\endcsname{#4}}
212
213\protected\def\usesomethingtikzindeed#1#2#3%
214  {\ifcsname#1:l:#3\endcsname\else
215     \letcsname#1:l:#3\endcsname\relax
216     \begincsname#1:b:#3\endcsname
217     \starttikzinput
218     #2[#3]%
219     \stoptikzinput
220     \begincsname#1:a:#3\endcsname
221   \fi}
222
223% somehow both variants [#1] and {#1} are used
224
225\protected\def\installtikzlibraryhacks{\installsomethingtikzindeed\????tikzhack}
226\protected\def\installpgfmodulehacks  {\installsomethingtikzindeed\????pgfmhack}
227\protected\def\installpgflibraryhacks {\installsomethingtikzindeed\????pgflhack}
228
229\tolerant\protected\def\usepgfmodule  [#1]#;#2{\usesomethingtikzindeed\????pgfmhack\normalusepgfmodule  {#1#2}}
230\tolerant\protected\def\usepgflibrary [#1]#;#2{\usesomethingtikzindeed\????pgflhack\normalusepgflibrary {#1#2}}
231\tolerant\protected\def\usetikzlibrary[#1]#;#2{\usesomethingtikzindeed\????tikzhack\normalusetikzlibrary{#1#2}}
232
233\protect
234
235\usepgfmodule[shapes]
236\usepgfmodule[plot]
237\usepgfmodule[matrix]
238\usepgfmodule[decorations]
239
240\definefilesynonym [pgfplots]      [tikz-pgfplots]
241\definefilesynonym [pgfplotstable] [tikz-pgfplotstable]
242
243% Here come the hacks:
244
245\installtikzlibraryhacks{calendar}{}{\tikzinputfile{pgfcalendar.code.tex}}
246
247\stopmodule
248