Debian Codegraph @

texmf-dist/tex/lualatex/luasseq/luasseq.sty

raw
1 %%
2 %% This is file `luasseq.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% luasseq.dtx (with options: `package')
8 %%
9 %% IMPORTANT NOTICE:
10 %%
11 %% For the copyright see the source file.
12 %%
13 %% Any modified versions of this file must be renamed
14 %% with new filenames distinct from luasseq.sty.
15 %%
16 %% For distribution of the original source see the terms
17 %% for copying and modification in the file luasseq.dtx.
18 %%
19 %% This generated file may be distributed as long as the
20 %% original source files, as listed above, are part of the
21 %% same distribution. (The sources need not necessarily be
22 %% in the same archive or directory.)
23
24 \NeedsTeXFormat{LaTeX2e}
25
26 \ProvidesPackage{luasseq}[2023/01/10]
27
28 \RequirePackage{ifthen,calc,pifont}
29 \RequirePackage{pgf}[2006/01/01]
30 \RequirePackage{xkeyval}
31 \usepgflibrary{snakes}
32
33 \newboolean{debug}
34 \setboolean{debug}{false}
35
36 \DeclareOption{ps}{\errmessage{sseq: ps/nops is deprecated}}
37 \DeclareOption{nops}{\errmessage{sseq: ps/nops is deprecated}}
38 \DeclareOption{dvips}{\errmessage{sseq: deprecated option dvips ignored}}
39 \DeclareOption{xdvi}{\errmessage{sseq: deprecated option xdvi ignored}}
40 \DeclareOption{color}{\errmessage{sseq: deprecated option color ignored}}
41 \DeclareOption{nocolor}{\errmessage{sseq: deprecated option nocolor ignored}}
42 \DeclareOption{debug}{\setboolean{debug}{true}}
43
44 \ProcessOptions
45
46
47 \directlua0{dofile(kpse.find_file("luasseq.lua","lua"))}
48
49 \definecolor{sseqgr}{gray}{0.65}
50 \definecolor{sslightgr}{gray}{0.9}
51 \definecolor{ssred}{rgb}{1,0,0}
52 \definecolor{ssblack}{rgb}{0,0,0}
53 \newcommand{\ssconncolor}{ssblack}
54 \newcommand{\sslabelcolor}{ssblack}
55 \newcommand{\ssplacecolor}{ssblack}
56
57 %% ^^A Initialization
58 \newcount\sseqxstart \sseqxstart=0
59 \newcount\sseqystart \sseqystart=0
60 \newdimen\sseq@dimen % ^^A To convert dimensions to scaled points (in TeX)
61 \newbox\sseqbox % ^^A To compute the size of dropped objects (in TeX)
62
63 \long\def\for #1=#2\to#3\do#4\od{#1=#2 \sseq@for #1\to #3\do #4\od}
64 \long\def\sseq@for #1\to #2\do #3\od{%
65 \ifnum #1>#2 \else
66 #3\relax
67 \advance #1 by 1
68 \def\tempcmd{\sseq@for #1\to #2\do #3\od}%
69 \expandafter\tempcmd
70 \fi
71 }
72
73 \def\@eval#1#2{%
74 \edef\tempcmd{\noexpand#1#2}%
75 \tempcmd
76 }
77
78 \def\ss@placespecial#1#2#3#4#5{
79 \directlua0{sseq_drop_object(#1,#2,[[#3]],[[#4]],[[#5]],[[\ssplacecolor]])}}
80
81 \newcommand{\ssplace}[3]{
82 \ss@placespecial{#1}{#2}{rectangle}{discard}{#3}
83 }
84
85 \newcommand{\ssplaceboxed}[3]{
86 \ss@placespecial{#1}{#2}{rectangle}{stroke}{\ensuremath{#3}}
87 }
88
89 \newcommand{\ssplacecircled}[3]{
90 \ss@placespecial{#1}{#2}{circle}{stroke}{\ensuremath{#3}}
91 }
92
93 \newcommand{\ssmoveto}[2]{\directlua0{sseq_moveto(#1,#2)}}
94 \newcommand{\ssmove}[2]{\directlua0{sseq_move(#1,#2)}}
95 \define@key{sseqdrop}{circled}[true]{\newif\ifKV@sseqdrop@circled\csname KV@sseqdrop@circled#1\endcsname}
96 \define@key{sseqdrop}{boxed}[true]{\newif\ifKV@sseqdrop@boxed\csname KV@sseqdrop@boxed#1\endcsname}
97 \define@key{sseqdrop}{color}{\def\sseq@color{#1}}
98 \define@key{sseqdrop}{name}{\def\sseq@name{#1}}
99 \def\ssdrop{\@ifnextchar[\sseq@drop{\sseq@drop[]}}
100 \def\sseq@drop[#1]#2{
101 \presetkeys{sseqdrop}{circled=false,boxed=false,color=\ssplacecolor,name=\relax}{}
102 \setkeys{sseqdrop}{#1}
103 \ifKV@sseqdrop@circled
104 \directlua0{sseq_drop_object_here("circle","stroke",[[#2]],"\sseq@color")}
105 \else
106 \ifKV@sseqdrop@boxed
107 \directlua0{sseq_drop_object_here("rectangle","stroke",[[#2]],"\sseq@color")}
108 \else
109 \directlua0{sseq_drop_object_here("rectangle","discard",[[#2]],"\sseq@color")}
110 \fi
111 \fi
112 \def\temp{\relax}
113 \ifx\sseq@name\temp \else
114 \@eval\ssname{{\sseq@name}}
115 \fi
116 }
117 \newcommand{\ssdropbull}{\ssdrop{\bullet}}
118 \newcommand{\ssdropboxed}[1]{\ssdrop[boxed]{#1}}
119 \newcommand{\ssdropcircled}[1]{\ssdrop[circled]{#1}}
120 \def\ssname#1{\directlua0{sseq_name("#1")}}
121 \newcommand{\ssgoto}[1]{\directlua0{sseq_goto("#1")}}
122 \newcommand{\ssprefix}[1]{\directlua0{sseq_prefix("#1")}}
123 \newcommand{\ssbeginprefixcontext}{\directlua0{sseq_begin_prefix_context()}}
124 \newcommand{\ssendprefixcontext}{\directlua0{sseq_end_prefix_context()}}
125 \newcommand{\ssresetprefix}{\directlua0{sseq_reset_prefix()}}
126 \newcommand{\ssabsgoto}[1]{\directlua0{sseq_abs_goto("#1")}}
127 \define@key{sseqlabel}{color}{\def\sseq@color{#1}}
128 \define@key{sseqlabel}{pos}{\def\sseq@position{#1}}
129 \define@key{sseqlabel}{U}[]{\def\sseq@position{U}}
130 \define@key{sseqlabel}{LU}[]{\def\sseq@position{LU}}
131 \define@key{sseqlabel}{L}[]{\def\sseq@position{L}}
132 \define@key{sseqlabel}{LD}[]{\def\sseq@position{LD}}
133 \define@key{sseqlabel}{D}[]{\def\sseq@position{D}}
134 \define@key{sseqlabel}{RD}[]{\def\sseq@position{RD}}
135 \define@key{sseqlabel}{R}[]{\def\sseq@position{R}}
136 \define@key{sseqlabel}{RU}[]{\def\sseq@position{RU}}
137 \def\ssdroplabel{\@ifnextchar[\sseq@droplabel{\sseq@droplabel[]}}
138 \def\sseq@droplabel[#1]#2{
139 \def\sseq@position{L}
140 \presetkeys{sseqlabel}{color=\ssplacecolor}{}
141 \setkeys{sseqlabel}{#1}
142 \directlua0{sseq_drop_label("\sseq@position","\sseq@color",[[#2]])}
143 }
144 \define@key{sseqdropext}{circled}[true]{\newif\ifKV@sseqdrop@circled\csname KV@sseqdrop@circled#1\endcsname}
145 \define@key{sseqdropext}{boxed}[true]{\newif\ifKV@sseqdrop@boxed\csname KV@sseqdrop@boxed#1\endcsname}
146 \define@key{sseqdropext}{color}{\def\ssplacecolor{#1}}
147 \define@key{sseqdropext}{name}{\def\sseq@name{#1}}
148 \def\ssdropextension{\@ifnextchar[\sseq@dropextension{\sseq@dropextension[]}}
149 \def\sseq@dropextension[#1]{
150 \edef\sseq@savecolor{\ssplacecolor}
151 \def\sseq@name{\relax}
152 \presetkeys{sseqdropext}{circled=false,boxed=false}{}
153 \setkeys{sseqdrop}{#1}
154 \ifKV@sseqdrop@boxed
155 \directlua0{sseq_drop_extension("rectangle","stroke","\sseq@color")}
156 \else
157 \directlua0{sseq_drop_extension("circle","stroke","\sseq@color")}
158 \fi
159
160 \def\temp{\relax}
161 \ifx\sseq@name\temp \else
162 \@eval\ssname{{\sseq@name}}
163 \fi
164 }
165 \define@key{sseqstroke}{color}{\def\sseq@color{#1}}
166 \define@key{sseqstroke}{curve}{\def\sseq@curve{#1}}
167 \define@key{sseqstroke}{dashed}[{{2pt}{2pt}}]{\def\sseq@dashing{#1}}
168 \define@key{sseqstroke}{dotted}[{{.5pt}{2pt}}]{\def\sseq@dashing{#1}}
169 \define@key{sseqstroke}{arrowfrom}[\sseq@defaultarrowstyle]{\def\sseq@arrowfrom{\ssinversearrowhead[#1]}}
170 \define@key{sseqstroke}{arrowto}[\sseq@defaultarrowstyle]{\def\sseq@arrowto{\ssarrowhead[#1]}}
171 \define@key{sseqstroke}{void}[true]{\newif\ifKV@sseqstroke@void\csname KV@sseqstroke@void#1\endcsname}
172 \def\ssstroke{\@ifnextchar[\sseq@stroke{\sseq@stroke[]}}
173 \def\sseq@stroke[#1]{
174 \def\sseq@dashing{}
175 \def\sseq@curve{}
176 \def\sseq@arrowfrom{}
177 \def\sseq@arrowto{}
178 \presetkeys{sseqstroke}{void=false,color=\ssconncolor}{}
179 \setkeys{sseqstroke}{#1}
180 \ifKV@sseqstroke@void % ^^A a void line
181 \directlua0{sseq_late_connection("\sseq@dashing","\sseq@curve","\sseq@color",false,true)}
182 \else
183 \directlua0{sseq_late_connection("\sseq@dashing","\sseq@curve","\sseq@color",false,false)}
184 \fi
185 \sseq@arrowfrom
186 \sseq@arrowto
187 }
188 \newcommand{\sscurve}[1]{\sseq@stroke[curve=#1]}
189 \newcommand{\ssdashedstroke}{\sseq@stroke[dashed]}
190 \newcommand{\ssdashedcurve}[1]{\sseq@stroke[dashed,curve=#1]}
191 \newcommand{\ssdottedstroke}{\sseq@stroke[dotted]}
192 \newcommand{\ssdottedcurve}[1]{\sseq@stroke[dotted,curve=#1}
193 \newcommand{\ssarrowhead}[1][\sseq@defaultarrowstyle]{\directlua0{sseq_add_arrow("arrowto","#1")}}
194 \newcommand{\ssinversearrowhead}[1][\sseq@defaultarrowstyle]{\directlua0{sseq_add_arrow("arrowfrom","#1")}}
195 \define@key{sseqline}{color}{\def\sseq@color{#1}}
196 \define@key{sseqline}{curve}{\def\sseq@curve{#1}}
197 \define@key{sseqline}{dashed}[{{2pt}{2pt}}]{\def\sseq@dashing{#1}}
198 \define@key{sseqline}{dotted}[{{.5pt}{2pt}}]{\def\sseq@dashing{#1}}
199 \define@key{sseqline}{arrowfrom}[\sseq@defaultarrowstyle]{\def\sseq@arrowfrom{\ssinversearrowhead[#1]}}
200 \define@key{sseqline}{arrowto}[\sseq@defaultarrowstyle]{\def\sseq@arrowto{\ssarrowhead[#1]}}
201 \define@key{sseqline}{void}[true]{\newif\ifKV@sseqline@void\csname KV@sseqline@void#1\endcsname}
202 \def\ssline{\@ifnextchar[\sseq@line{\sseq@line[]}}
203 \def\sseq@line[#1]#2#3{
204 \def\sseq@dashing{}
205 \def\sseq@curve{}
206 \edef\sseq@arrowfrom{}
207 \edef\sseq@arrowto{}
208 \presetkeys{sseqline}{void=false,color=\ssconncolor}{}
209 \setkeys{sseqline}{#1}
210 \ifKV@sseqline@void % ^^A a void line
211 \directlua0{sseq_assert_source(); sseq_finish_pos(); sseq_move(#2,#3); sseq_late_connection("\sseq@dashing","\sseq@curve","\sseq@color",false,true)}
212 \else
213 \directlua0{sseq_open_connection("\sseq@dashing","\sseq@curve","\sseq@color",false,false); sseqposx = sseqposx+#2; sseqposy = sseqposy+#3}
214 \fi
215 \sseq@arrowfrom
216 \sseq@arrowto
217 }
218 \newcommand{\sscurvedline}[3]{\ssline[curve=#3]{#1}{#2}}
219 \newcommand{\ssdashedline}[2]{\ssline[dashed]{#1}{#2}}
220 \newcommand{\sscurveddashedline}[3]{\ssline[curve=#3,dashed]{#1}{#2}}
221 \newcommand{\ssarrow}[3][]{
222 \ssline[arrowto,#1]{#2}{#3}
223 }
224 \newcommand{\sscurvedarrow}[3]{\ssline[arrowto,curve=#3]{#1}{#2}}
225 \newcommand{\ssdashedarrow}[2]{\ssline[arrowto,dashed]{#1}{#2}}
226 \newcommand{\sscurveddashedarrow}[3]{\ssline[arrowto,dashed,curve=#3]{#1}{#2}}
227 \def\ssvoidline{\@ifnextchar[\sseq@voidline{\sseq@voidline[]}}
228 \def\sseq@voidline[#1]#2#3{
229 \def\sseq@dashing{}
230 \def\sseq@curve{}
231 \edef\sseq@arrowfrom{}
232 \edef\sseq@arrowto{}
233 \presetkeys{sseqline}{color=\ssconncolor}{}
234 \setkeys{sseqline}{#1}
235 \directlua0{sseq_void_line("\sseq@dashing","\sseq@curve","\sseq@color",#2,#3)}
236 \sseq@arrowfrom
237 \sseq@arrowto
238 }
239
240 \newcommand{\ssvoidarrow}[2]{\ssvoidline{#1}{#2}\ssarrowhead}
241 \newcommand{\ssinversevoidarrow}[2]{\ssvoidline{#1}{#2}\ssinversearrowhead}
242
243 \newcommand{\ssbullstring}[3]{
244 \directlua0{sseq_bullstring(#1,#2,#3,[[\ssplacecolor]])}
245 }
246 \newcommand{\ssinfbullstring}[3]{
247 \ssbullstring{#1}{#2}{#3}
248 \ssvoidarrow{#1}{#2}
249 }
250 \newcommand{\ssgrayout}[1][gray]{\directlua0{sseq_grayout("#1")}}
251 \define@key{sseq}{grid}{
252 \directlua0{sseqgriddrawer = sseq_grid_#1}
253 }
254 \define@key{sseq}{entrysize}{
255 \sseq@dimen=#1
256 \directlua0{sseqentrysize=\number\sseq@dimen} % In LUA, it's all in scaled points.
257 }
258
259 \define@key{sseq}{labels}{
260 \setkeys{sseq}{xlabels=#1,ylabels=#1}
261 }
262 \define@key{sseq}{xlabels}{
263 \def\temp{#1}
264 \def\temptwo{none}
265 \ifx\temp\temptwo
266 \directlua0{sseqxlabels = sseq_parse_label_list("")}
267 \else
268 \def\temptwo{numbers}
269 \ifx\temp\temptwo
270 \directlua0{sseqxlabels = sseq_parse_label_list("&n")}
271 \else
272 \directlua0{sseqxlabels = sseq_parse_label_list([[#1]])}
273 \fi
274 \fi
275 }
276 \define@key{sseq}{ylabels}{
277 \def\temp{#1}
278 \def\temptwo{none}
279 \ifx\temp\temptwo
280 \directlua0{sseqylabels = sseq_parse_label_list("")}
281 \else
282 \def\temptwo{numbers}
283 \ifx\temp\temptwo
284 \directlua0{sseqylabels = sseq_parse_label_list("&n")}
285 \else
286 \directlua0{sseqylabels = sseq_parse_label_list([[#1]])}
287 \fi
288 \fi
289 }
290
291 \define@key{sseq}{xlabelstep}{
292 \directlua0{sseqxstep=#1}
293 }
294 \define@key{sseq}{ylabelstep}{
295 \directlua0{sseqystep=#1}
296 }
297
298 \define@key{sseq}{labelstep}{\setkeys{sseq}{xlabelstep=#1}\setkeys{sseq}{ylabelstep=#1}}
299
300 \define@key{sseq}{gapsize}{\setkeys{sseq}{xgapsize=#1}\setkeys{sseq}{ygapsize=#1}}
301 \define@key{sseq}{xgapsize}{
302 \sseq@dimen=#1
303 \directlua0{sseqxgap=\number\sseq@dimen}
304 }
305 \define@key{sseq}{ygapsize}{
306 \sseq@dimen=#1
307 \directlua0{sseqygap=\number\sseq@dimen}
308 }
309 \define@key{sseq}{leak}{\setkeys{sseq}{xleak=#1}\setkeys{sseq}{yleak=#1}}
310 \define@key{sseq}{xleak}{
311 \sseq@dimen=#1
312 \directlua0{sseqxleak=\number\sseq@dimen}
313 }
314 \define@key{sseq}{yleak}{
315 \sseq@dimen=#1
316 \directlua0{sseqyleak=\number\sseq@dimen}
317 }
318
319 \define@key{sseq}{gridstroke}{
320 \sseq@dimen=#1
321 \directlua0{sseqgridstrokethickness=\number\sseq@dimen}
322 }
323
324 \define@key{sseq}{arrows}{
325 \def\sseq@defaultarrowstyle{#1}
326 \directlua0{sseqdefaultarrowstyle="#1"}
327 }
328
329 \define@key{sseq}{packing}{
330 \directlua0{sseqpacking = sseq_pack_#1}
331 }
332 \def\sseq@defaultarrowstyle{to}
333
334 \directlua0{sseq_set_defaults()}
335
336 \newenvironment{sseq}[3][]{%
337 \begingroup
338 \directlua0{sseq_init()}
339 \begin{pgfpicture}
340 \setkeys{sseq}{#1}
341 \directlua0{sseq_setup_ranges("#2","#3",\the\sseqxstart,\the\sseqystart)}
342 \directlua0{sseq_drawgrid()}
343 \directlua0{sseq_drawlabels()}
344 \directlua0{sseqboxno = \the\sseqbox} % ^^A Needed to measure the size of entries
345 }
346 {
347 \relax
348 \ssmoveto 0 0
349 \directlua0{sseq_position_objects(); sseq_dump_code()}
350 \end{pgfpicture}
351 \endgroup
352 }
353 \endinput
354 %%
355 %% End of file `luasseq.sty'.