m-tikz.mkxl /size: 8353 b    last modification: 2025-02-21 11: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        \frozen\overloaded\let\pdfsavepos \savepos
42        \frozen\overloaded\let\pdflastxpos\lastxpos
43        \frozen\overloaded\let\pdflastypos\lastypos
44    \protect
45\fi
46
47\ifdefined\pdfstrcmp\else
48
49    \startluacode
50        interfaces.implement {
51            name      = "pdfstrcmp",
52            arguments = "2 strings",
53            usage     = "value",
54            public    = true,
55            actions   = function(a,b)
56                return
57                    tokens.values.integer,
58                    (a < b and -1) or (a > b and 1) or 0
59            end
60        }
61    \stopluacode
62
63\fi
64
65\newcatcodetable \tikzcatcodes
66
67\startcatcodetable \tikzcatcodes
68    \catcode\tabasciicode             \spacecatcode
69    \catcode\endoflineasciicode       \endoflinecatcode
70    \catcode\formfeedasciicode        \endoflinecatcode
71    \catcode\spaceasciicode           \spacecatcode
72    \catcode\endoffileasciicode       \ignorecatcode
73    \catcode\circumflexasciicode      \superscriptcatcode
74    \catcode\underscoreasciicode      \subscriptcatcode
75    \catcode\ampersandasciicode       \alignmentcatcode
76    \catcode\backslashasciicode       \escapecatcode
77    \catcode\leftbraceasciicode       \begingroupcatcode
78    \catcode\rightbraceasciicode      \endgroupcatcode
79    \catcode\dollarasciicode          \mathshiftcatcode
80    \catcode\hashasciicode            \parametercatcode
81    \catcode\commentasciicode         \commentcatcode
82    \catcode\atsignasciicode          \lettercatcode
83    \catcode\exclamationmarkasciicode \othercatcode
84    \catcode\questionmarkasciicode    \lettercatcode
85    \catcode\tildeasciicode           \activecatcode
86    \catcode\barasciicode             \othercatcode
87\stopcatcodetable
88
89\newinteger\tikzinputlevel
90
91\permanent\protected\def\starttikzinput
92  {\advanceby\tikzinputlevel\plusone
93   \ifcase\tikzinputlevel\or
94     \pushoverloadmode
95     \pushcatcodetable
96     \setcatcodetable\tikzcatcodes
97     \pushmacro\meaning
98     \let\meaning\meaningless
99     \autoparagraphmode\zerocount
100  \fi}
101
102\permanent\protected\def\stoptikzinput
103  {\autoparagraphmode\plusone
104   \ifcase\tikzinputlevel\or
105     \popcatcodetable
106     \popmacro\meaning
107     \popoverloadmode
108   \fi
109   \advanceby\tikzinputlevel\minusone}
110
111\permanent\protected\def\tikzinputfile#1%
112  {\starttikzinput
113   \input{#1}\relax
114   \stoptikzinput}
115
116\permanent\protected\def\tikzerrormessage#1#2#3%
117  {\writestatus{#1}{#2}}
118
119% For now we need this but we need to educate the user to wrap settings in the
120% wrappers. So some day the next line will go. I need to check what commands are
121% possible outside a picture.
122
123\overloadmode\zerocount
124
125\newtoks\everytikzpicture
126\newtoks\everyinsidetikzpicture
127
128% \appendtoks
129%     \resetcharacterspacing
130% \to \everytikzpicture
131
132\permanent\protected\def\starttikzsettings
133  {\pushoverloadmode
134   \pushcatcodetable
135   \setcatcodetable\tikzcatcodes
136   \pushmacro\meaning
137   \let\meaning\meaningless
138   \autoparagraphmode\zerocount}
139
140\permanent\protected\def\stoptikzsettings
141  {\autoparagraphmode\plusone
142   \popmacro\meaning
143   \popcatcodetable
144   \popoverloadmode}
145
146\permanent\tolerant\protected\def\starttikzpicture[#S#1]%
147  {%\dontleavehmode % doesn't work well in figures so ...
148   \hcontainer\bgroup
149   \setcatcodetable\tikzcatcodes
150   \the\everytikzpicture
151   \autoparagraphmode\zerocount
152   \pushmacro\meaning
153   \let\meaning\meaningless
154 % \pushoverloadmode
155   \ifdefined\PackageError\else \let\PackageError\tikzerrormessage \fi
156   \tikzpicture[#1]%
157   \the\everyinsidetikzpicture}
158
159\permanent\protected\def\stoptikzpicture
160  {\endtikzpicture
161 % \popoverloadmode
162   \popmacro\meaning
163   \egroup}
164
165\let\pgfdefined    \relax
166\let\pgfcoredefined\relax
167
168\tikzinputfile{pgfutil-common.tex}
169\tikzinputfile{pgfutil-context.def}
170\tikzinputfile{pgfrcs.code.tex}
171\tikzinputfile{pgfsys.code.tex}
172\tikzinputfile{pgfkeys.code.tex}
173\tikzinputfile{pgfsyssoftpath.code.tex}
174\tikzinputfile{pgfsysprotocol.code.tex}
175\tikzinputfile{pgfcore.code.tex}
176\tikzinputfile{pgffor.code.tex}
177\tikzinputfile{pgfmoduleplot.code.tex}
178\tikzinputfile{tikz.code.tex}
179
180\let\startpgfpicture             \pgfpicture              \let\stoppgfpicture            \endpgfpicture
181\let\startpgfscope               \pgfscope                \let\stoppgfscope              \endpgfscope
182\let\startpgflowlevelscope       \pgflowlevelscope        \let\stoppgflowlevelscope      \endpgflowlevelscope
183\let\startpgfinterruptpath       \pgfinterruptpath        \let\stoppgfinterruptpath      \endpgfinterruptpath
184\let\startpgfinterruptpicture    \pgfinterruptpicture     \let\stoppgfinterruptpicture   \endpgfinterruptpicture
185\let\startpgfinterruptboundingbox\pgfinterruptboundinbox  \let\stoppgfinterruptboudingbox\endpgfinterruptboundingbox
186
187\let\normalusepgfmodule  \usepgfmodule
188\let\normalusepgflibrary \usepgflibrary
189\let\normalusetikzlibrary\usetikzlibrary
190
191\installnamespace{pgfmhack}
192\installnamespace{pgflhack}
193\installnamespace{tikzhack}
194
195\tolerant\protected\def\usepgfmodule[#1]#;#2% somehow both variants are used
196  {\starttikzinput
197   \normalusepgfmodule[#1#2]%
198   \stoptikzinput}
199
200\tolerant\protected\def\usepgflibrary[#1]#;#2% somehow both variants are used
201  {\starttikzinput
202   \normalusepgflibrary[#1#2]%
203   \stoptikzinput}
204
205\tolerant\protected\def\usetikzlibrary[#1]#;#2% somehow both variants are used
206  {\starttikzinput
207   \normalusetikzlibrary[#1#2]%
208   \stoptikzinput}
209
210\unprotect
211
212\protected\def\installsomethingtikzindeed#1#2#3#4%
213  {\defcsname#1:b:#2\endcsname{#3}%
214   \defcsname#1:a:#2\endcsname{#4}}
215
216\protected\def\usesomethingtikzindeed#1#2#3%
217  {\ifcsname#1:l:#3\endcsname\else
218     \letcsname#1:l:#3\endcsname\relax
219     \begincsname#1:b:#3\endcsname
220     \starttikzinput
221     #2[#3]%
222     \stoptikzinput
223     \begincsname#1:a:#3\endcsname
224   \fi}
225
226% somehow both variants [#1] and {#1} are used
227
228\protected\def\installtikzlibraryhacks{\installsomethingtikzindeed\????tikzhack}
229\protected\def\installpgfmodulehacks  {\installsomethingtikzindeed\????pgfmhack}
230\protected\def\installpgflibraryhacks {\installsomethingtikzindeed\????pgflhack}
231
232\tolerant\protected\def\usepgfmodule  [#1]#;#2{\usesomethingtikzindeed\????pgfmhack\normalusepgfmodule  {#1#2}}
233\tolerant\protected\def\usepgflibrary [#1]#;#2{\usesomethingtikzindeed\????pgflhack\normalusepgflibrary {#1#2}}
234\tolerant\protected\def\usetikzlibrary[#1]#;#2{\usesomethingtikzindeed\????tikzhack\normalusetikzlibrary{#1#2}}
235
236\protect
237
238\usepgfmodule[shapes]
239\usepgfmodule[plot]
240\usepgfmodule[matrix]
241\usepgfmodule[decorations]
242
243\definefilesynonym [pgfplots]      [tikz-pgfplots]
244\definefilesynonym [pgfplotstable] [tikz-pgfplotstable]
245
246% Here come the hacks:
247
248\installtikzlibraryhacks{calendar}{}{\tikzinputfile{pgfcalendar.code.tex}}
249
250\startsetups tikz:hacks:tikzcd
251\permanent\protected\def\starttikzcd%
252  {\starttikzinput
253   \hcontainer\bgroup
254   \tikzcd}
255
256\permanent\protected\def\stoptikzcd
257  {\endtikzcd
258   \egroup
259   \stoptikzinput}
260\stopsetups
261
262\installtikzlibraryhacks{cd}{}{\directsetup{tikz:hacks:tikzcd}}
263
264\stopmodule
265