Debian Codegraph @

texmf-dist/source/latex/styledcmd/styledcmd.dtx

raw
1 % \iffalse meta-comment
2 %
3 % styledcmd Handle multiple versions for user-defined macros in LaTeX
4 % Copyright (C) 2021-2024 Paolo De Donato <[email protected]>
5 %
6 % This file is part of Styledcmd.
7 %
8 % Styledcmd is free software: you can redistribute it and/or modify
9 % it under the terms of the GNU General Public License as published by
10 % the Free Software Foundation, either version 3 of the License, or
11 % (at your option) any later version.
12 %
13 % Styledcmd is distributed in the hope that it will be useful,
14 % but WITHOUT ANY WARRANTY; without even the implied warranty of
15 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 % GNU General Public License for more details.
17 %
18 % You should have received a copy of the GNU General Public License
19 % along with Styledcmd. If not, see <https://www.gnu.org/licenses/>.
20 %
21 % \fi
22 %
23 % \iffalse
24 %<*driver>
25 \ProvidesFile{styledcmd.dtx}[2024/03/07 2.0.1 Command with different styles]
26 %</driver>
27 %<package>\NeedsTeXFormat{LaTeX2e}
28 %<package>\RequirePackage{expl3}[2022-04-10]
29 %<package>\ProvidesExplPackage{styledcmd}{2024/03/07}{2.0.1}{Command with different styles}
30 %<package>\RequirePackage{lt3rawobjects}[2023-03-17]
31 %<package>\RequirePackage{xparse}
32 %<*driver>
33 \documentclass[full]{l3doc}
34 \usepackage{styledcmd}
35 \begin{document}
36 \DocInput{styledcmd.dtx}
37 \end{document}
38 %</driver>
39 % \fi
40 %
41 %\newstyledcmd{\saluto}{informal}[1]{Hi #1}
42 %\newstyledcmd{\saluto}{formal}[1]{Good morning #1}
43 %
44 %\newcommand{\thpkg}{\pkg{styledcmd}}
45 %
46 %\title{styledcmd}
47 %\author{Paolo De Donato}
48 %\date{2.0.1 2024/03/07}
49 %
50 %\maketitle
51 %
52 %\begin{documentation}
53 %
54 %\thpkg{} is a \LaTeX{} package that allows you to create and manage different versions of your macro in order to be able to choose the better style for every occasion and avoid rewriting code each time.
55
56 %\section{How can you include it in your project?}
57 %You need only to have the file \verb+styledcmd.sty+ in your current working directory. Otherwise you can manually install it inside your preferred \LaTeX{} compiler (for example \verb+TeXLive+ or \verb+MiKTeX+) in order to make it available for all your projects. Instructions for manually install a package can be found on Internet.
58 %
59 %Then once you've added it you can include in your project with this command:
60 %\begin{verbatim}
61 % \usepackage{styledcmd}
62 %\end{verbatim}
63 %
64 %\section{How do you use it?}
65 %You can create a formatted macro via the following command
66 %\begin{function}{\newstyledcmd, \renewstyledcmd, \providestyledcmd}
67 %\begin{syntax}
68 %\tn{newstyledcmd} \{\tn{\meta{macro name}}\} \marg{style name} \oarg{number of arguments} \marg{code}
69 %\end{syntax}
70 %it has the same syntax of \tn{newcommand} except for the \meta{style name} argument that specify the style. This macro alone creates commands \tn{\meta{macro name}} and \tn{\meta{macro name}}\oarg{style name} that both expand as \meta{code}.
71 %\end{function}
72 %
73 %The most important feature is that you can call \tn{newstyledcmd} multiple times with the same \meta{macro name} but different \meta{style name}, in this way each of \tn{\meta{macro name}}\oarg{style name} expands to \meta{code} associated to specified \meta{style name}. Notice that if you don't specify a style with just calling \tn{meta{macro name}} then it expands as the first created style, that style is the \emph{default} one for such command.
74 %
75 %As an example these commands
76 %\begin{verbatim}
77 % \newstyledcmd{\saluto}{informal}[1]{Hi #1}
78 % \newstyledcmd{\saluto}{formal}[1]{Good morning #1}
79 %\end{verbatim}
80 %define the two formats \verb+informal+ and \verb+formal+ for macro \tn{saluto}. Once you've created these two styles for \tn{saluto} you can use it with or without the style name argument, for example these commands
81 %\begin{verbatim}
82 % \saluto{uncle}
83 % \saluto[informal]{uncle}
84 % \saluto[formal]{uncle}
85 %\end{verbatim}
86 %will be expanded respectively as \saluto{uncle}, \saluto[informal]{uncle}, \saluto[formal]{uncle}. With the same syntax you can use \tn{renewstyledcmd} and \tn{providestyledcmd} with the same meaning of \tn{renewcommand} and \tn{providecommand} respectively.
87 %
88 %\section{How do you change the default style?}
89 %In order to change the default style (the one used when you don't choose explicitily a style) you need to execute the following command
90 %\begin{function}{\SetGlobalStyle}
91 %\begin{syntax}
92 %\tn{SetGlobalStyle} \{\cs{\meta{command name}}\} \marg{new default style name}
93 %\end{syntax}
94 %\end{function}
95 %\SetGlobalStyle{\saluto}{formal}
96 %
97 %For example in order to change the default style of command \tn{saluto} from \verb+informal+ to \verb+formal+ you need to execute command \tn{SetGlobalStyle}\{\cs{saluto}\}\{\verb+formal+\}. With this command the output of preceding commands will instead be \saluto{uncle}, \saluto[informal]{uncle}, \saluto[formal]{uncle}.
98 %
99 %\section{Customize parameters with \pkg{xparse}}
100 %\thpkg{} loads automatically the \pkg{xparse} package for internal reasons. You can also define new styled commands with the same syntax used by \tn{NewDocumentCommand} with the following command
101 %
102 %\begin{function}{\NewDocStyledCMD, \RenewDocStyledCMD, \ProvideDocStyledCMD}
103 %\begin{syntax}
104 %\tn{NewDocStyledCMD} \Arg{\cs{\meta{command name}}} \Arg{format name} \Arg{arguments format} \Arg{code}
105 %\end{syntax}
106 %\end{function}
107 %
108 %\NewDocStyledCMD{\prova}{stylea}{r<>}{Stile 1 #1}
109 %\NewDocStyledCMD{\prova}{styleb}{r<>}{Stile 2 #1}
110 %For example we can create the following two styles
111 %\begin{verbatim}
112 % \NewDocStyledCMD{\prova}{stylea}{r<>}{Stile 1 #1}
113 % \NewDocStyledCMD{\prova}{styleb}{r<>}{Stile 2 #1}
114 %\end{verbatim}
115 %in order to execute
116 %\begin{verbatim}
117 % \prova<Hello>
118 % \prova[stylea]<Hello>
119 % \prova[styleb]<Hello>
120 %\end{verbatim}
121 %which are expanded respectively as \prova<Hello>; \prova[stylea]<Hello>; \prova[styleb]<Hello>. Notice that the first optional argument passed to a command defined via \tn{NewDocStyledCMD} will always be interpreted as a style argument, so you should use another syntax for optional arguments or use a mandatory argument for the first place.
122 %
123 %For example this declaration \verb+\NewDocStyledCMD{\bad}{style}{o m}{Bad declaration}+ should be avoided since for example \verb+\bad[arg1]{arg2}+ will interpret \verb+arg1+ as a style name and not as the first optional argument for \tn{bad}.
124 %
125 %\section{Expandable commands}
126 %Coomands created by \tn{newstyledcmd} doesn't work very well in expansion only context due to the presence of optional style argument. In order to be able to create expandable commands you should instead use
127 %
128 %\begin{function}{\newstyledcmdExp, \renewstyledcmdExp, \providestyledcmdExp}
129 %\begin{syntax}
130 %\tn{newstyledcmdExp} \{\tn{\meta{macro name}}\} \marg{style name} \oarg{number of arguments} \marg{code}
131 %\end{syntax}
132 %\end{function}
133 % Despite commands created with \tn{newstyledcmd} the style name of commands created by \tn{newstyledcmdExp} are always mandatory and must be passed inside curly braces. In order to use the default style just pass an empty string as style name.
134 %
135 % For example this code
136 %\begin{verbatim}
137 % \newstyledcmdExp{\expCMD}{sty1}{Style 1}
138 % \newstyledcmdExp{\expCMD}{sty2}{Style 2}
139 %
140 % \expCMD{}
141 % \expCMD{sty1}
142 % \expCMD{sty2}
143 %\end{verbatim}
144 %expand as \newstyledcmdExp{\expCMD}{sty1}{Style 1}\newstyledcmdExp{\expCMD}{sty2}{Style 2} \expCMD{} \expCMD{sty1} \expCMD{sty2}
145 %
146 %\section{Groups}
147 %The group mechanism is very different from \thpkg\ |1.2| and preceding versions. From |2.0| styled commands can be added to a group in order to change toghether their style. Groups are automatically created when you're tying to add commands to it:
148 %\begin{function}{\AddCMDToGroup}
149 %\begin{syntax}
150 % \tn{AddCMDToGroup} \Arg{group name} \Arg{comma list of commands}
151 %\end{syntax}
152 %\end{function}
153 % You can change the default style for each member of a group with
154 %\begin{function}{\SetGroupStyle}
155 %\begin{syntax}
156 % \tn{SetGroupStyle} \Arg{group name} \Arg{style name}
157 %\end{syntax}
158 %\end{function}
159 %
160 %Suppose you've created the following styled commands:
161 %
162 % \begin{verbatim}
163 % \newstyledcmd{\LenUnit}{SI}{metre}
164 % \newstyledcmd{\MasUnit}{SI}{kilo}
165 %
166 % \newstyledcmd{\LenUnit}{old}{yard}
167 % \newstyledcmd{\MasUnit}{old}{pound}
168 % \end{verbatim}
169 %
170 % \newstyledcmd{\LenUnit}{SI}{metre}
171 % \newstyledcmd{\MasUnit}{SI}{kilo}
172 %
173 % \newstyledcmd{\LenUnit}{old}{yard}
174 % \newstyledcmd{\MasUnit}{old}{pound}
175 %
176 % Commands \tn{LenUnit}, \tn{MasUnit} will expand as \LenUnit, \MasUnit\ respectively since |SI| is the default style. We've used \tn{newstyledcmd} but you could use also \tn{NewDocStyledCMD}, \tn{newstyledcmdExp} or any other command generated as in section \ref{advanced}. To add these two commands to group |Units| run
177 % \begin{verbatim}
178 % \AddCMDToGroup{Units}{\LenUnit, \MasUnit}
179 % \end{verbatim}
180 % \AddCMDToGroup{Units}{\LenUnit}\AddCMDToGroup{Units}{\MasUnit}\SetGroupStyle{Units}{old}If you want to set |old| as the default style for these commands just run
181 % \begin{verbatim}
182 % \SetGroupStyle{Units}{old}
183 % \end{verbatim}
184 % now \tn{LenUnit}, \tn{MasUnit} will expand as \LenUnit, \MasUnit\ respectively.
185 %
186 % Notice that if the specified group already exists then \tn{AddCMDToGroup} just appends the speficied commands to it. In particular this
187 % \begin{verbatim}
188 % \AddCMDToGroup{Units}{\LenUnit}
189 % \AddCMDToGroup{Units}{\MasUnit}
190 % \end{verbatim}
191 % is equivalent to write
192 % \begin{verbatim}
193 % \AddCMDToGroup{Units}{\LenUnit, \MasUnit}
194 % \end{verbatim}
195 %
196 %\section{Advanced usage}
197 %\label{advanced}This section is for advanced users and package mantainers that knows \LaTeX3, It's not needed to use \thpkg\ daily or creating documents. If \tn{newstyledcmd}, \tn{NewDocStyledCMD} and \tn{newstyledcmdExp} aren't suitable for you it's possible to create a custom styled command generator, but we first need to know a bit of the internal structure of \thpkg.
198 %
199 % What you see as a styled command it's instead a collection of different macros:
200 % \begin{itemize}
201 % \item multiple \emph{effective styled commands} (\emph{ES commands}), one for each style;
202 % \item a single \emph{dispatch command} that's called by the user and expands to the specified ES command.
203 % \end{itemize}
204 %
205 % \begin{function}{\stycmd_generate:NNN, \stycmd_generate:NN}
206 % \begin{syntax}
207 % \cs{stycmd_generate:NNN} \meta{generator name} \meta{ES commands generator} \meta{dispatch command generator}
208 % \cs{stycmd_generate:NN} \meta{generator name} \meta{ES commands generator}
209 % \end{syntax}
210 % Creates a generator of styled commands with name \meta{generator name}. Argument \meta{ES commands generator} is used to create ES commands and should accept a macro name as the first argument, but there aren't other restrictions on remaining arguments. Suitable ES commands generators are \tn{newcommand} and \tn{NewDocumentCommand}.
211 % \end{function}
212 %
213 % Argument \meta{dispatch command generator} should generate the dispatch command. Despite \meta{ES commands generator} this command must have only one parameter, a string representing the command to be created. Suitable values for this parameter are:
214 %
215 % \begin{function}{\stycmd_xparsecmd:N}
216 % \begin{syntax}
217 % \cs{stycmd_xparsecmd:N} \meta{command}
218 % \end{syntax}
219 % Creates the dispatch command with \tn{ProvideDocumentCommand} with optional style name parameter (used in \tn{newstyledcmd} and \tn{NewDocStyledCMD}).
220 %\end{function}
221 %
222 %\begin{function}{\stycmd_expcmd:N}
223 % \begin{syntax}
224 % \cs{stycmd_expcmd:N} \meta{command}
225 % \end{syntax}
226 % Creates the dispatch command with \tn{providecommand} with mandatory style name parameter (used in \tn{newstyledcmdExp}).
227 %\end{function}
228 %
229 % If you don't specify the dispatch command generator (by using the |NN| variant) \cs{stycmd_xparsecmd:N} is used implicitly.
230 %
231 % \begin{function}{\stycmd_generate_renew:NN}
232 % \begin{syntax}
233 % \cs{stycmd_generate_renew:NN} \meta{updater name} \meta{ES commands generator}
234 % \end{syntax}
235 % Creates command \tn{\meta{updater name}} that modifies styles of commands already generated, like \tn{renewcommmand} edits commands generated by \tn{newcommand}.
236 %
237 % For example if you have \tn{createA} that creates commands and \tn{editA} that edits commands generated by \tn{createA} then
238 % \begin{verbatim}
239 % \stycmd_generate:NN \createStyledA \createA
240 % \end{verbatim}
241 % creates styled commands by using \tn{createA} and
242 % \begin{verbatim}
243 % \stycmd_generate_renew:NN \editStyledA \editA
244 % \end{verbatim}
245 % modifies commands generated by \tn{createStyledA} (by invoking \tn{editA}).
246 % \end{function}
247 %
248 %\end{documentation}
249 %
250 %\begin{implementation}
251 %
252 %\section{Implementation}
253 % \begin{macrocode}
254 %<*package>
255 % \end{macrocode}
256 %
257 % \begin{macrocode}
258 %<@@=stycmd>
259 % \end{macrocode}
260 %
261 %\begin{variable}{\c_@@_cmdproxy_str}
262 %Proxy used to generate styled commands
263 % \begin{macrocode}
264
265 \str_const:Nx \c_@@_cmdproxy_str { \object_address:nn
266 { stycmd }{ proxy } }
267
268 \proxy_create:nn { stycmd }{ proxy }
269 \proxy_push_member:Vnn \c_@@_cmdproxy_str { default }{ tl }
270
271 % \end{macrocode}
272 %\end{variable}
273 %
274 %\begin{macro}{\@@_cmd:n}
275 % Entity name
276 % \begin{macrocode}
277
278 \cs_new:Nn \@@_cmd:n
279 {
280 \object_address:nn{ stycmd }{ entity - #1 }
281 }
282
283 % \end{macrocode}
284 %\end{macro}
285 %
286 %\begin{macro}{\@@_setdef_strip:Nn}
287 %Changes the default style
288 % \begin{macrocode}
289
290 \cs_new_protected:Nn \@@_setdef_aux:nN
291 {
292 \object_member_set:nnn
293 {
294 \@@_cmd:n{ #1 }
295 }
296 { default }
297 { #2 }
298 }
299 \cs_generate_variant:Nn \@@_setdef_aux:nN { nc }
300
301 \cs_new_protected:Nn \@@_setdef_style:nn
302 {
303 \@@_setdef_aux:nc{ #1 }
304 {
305 \object_macro_adr:nn
306 {
307 \@@_cmd:n{ #1 }
308 }
309 {
310 style - #2
311 }
312 }
313 }
314
315 \cs_generate_variant:Nn \@@_setdef_style:nn { ff }
316
317 \cs_new_protected:Nn \@@_setdef_strip:Nn
318 {
319 \@@_setdef_style:ff{ \cs_to_str:N #1 }
320 { \tl_trim_spaces:n{ #2 } }
321 }
322
323 % \end{macrocode}
324 %\end{macro}
325 %
326 %\begin{macro}{\@@_cmd_define_strip:NNn}
327 % Define a macro with the specified command
328 % \begin{macrocode}
329
330 \cs_new_protected:Nn \@@_cmd_define_aux_aux:NN
331 {
332 #1 { #2 }
333 }
334 \cs_generate_variant:Nn \@@_cmd_define_aux_aux:NN { Nc }
335
336 \cs_new_protected:Nn \@@_cmd_define_aux:Nnn
337 {
338 \@@_cmd_define_aux_aux:Nc #1
339 {
340 \object_macro_adr:nn
341 {
342 \@@_cmd:n{ #2 }
343 }
344 {
345 style - #3
346 }
347 }
348 }
349
350 \cs_generate_variant:Nn \@@_cmd_define_aux:Nnn { Nff }
351
352 \cs_new_protected:Nn \@@_cmd_define_strip:NNn
353 {
354 \@@_cmd_define_aux:Nff #1
355 { \cs_to_str:N #2 }{ \tl_trim_spaces:n { #3 } }
356 }
357
358 % \end{macrocode}
359 %\end{macro}
360 %
361 %\begin{macro}{\@@_cmd_usedef:N, \@@_cmd_usesty_strip:Nn}
362 %Uses the styled command
363 % \begin{macrocode}
364
365 \cs_new:Nn \@@_cmd_usedef_aux:n
366 {
367 \object_member_use:nn
368 {
369 \@@_cmd:n{ #1 }
370 }
371 {
372 default
373 }
374 }
375
376 \cs_generate_variant:Nn \@@_cmd_usedef_aux:n { f }
377
378 \cs_new:Nn \@@_cmd_usedef:N
379 {
380 \@@_cmd_usedef_aux:f{ \cs_to_str:N #1 }
381 }
382
383
384 \cs_new:Nn \@@_cmd_usesty_aux:nn
385 {
386 \object_macro_use:nn
387 {
388 \@@_cmd:n{ #1 }
389 }
390 {
391 style - #2
392 }
393 }
394
395 \cs_generate_variant:Nn \@@_cmd_usesty_aux:nn { ff }
396
397 \cs_new:Nn \@@_cmd_usesty_strip:Nn
398 {
399 \@@_cmd_usesty_aux:ff{ \cs_to_str:N #1 }
400 { \tl_trim_spaces:n{ #2 } }
401 }
402
403 % \end{macrocode}
404 %\end{macro}
405 %
406 % \begin{macro}{\@@_entity_create_strip:Nnn}
407 % Creates a new entity if it doesn't exists and execute following code
408 % \begin{macrocode}
409
410 \cs_new_protected:Nn \@@_entity_create_aux:nnn
411 {
412 \object_if_exist:nF
413 {
414 \@@_cmd:n{ #1 }
415 }
416 {
417 \object_create:Vnn \c_@@_cmdproxy_str
418 { stycmd }{ entity - #1 }
419
420 \@@_setdef_style:nn{ #1 }{ #2 }
421
422 #3
423 }
424 }
425
426 \cs_generate_variant:Nn \@@_entity_create_aux:nnn { ffn }
427
428 \cs_new_protected:Nn \@@_entity_create_strip:Nnn
429 {
430 \@@_entity_create_aux:ffn
431 { \cs_to_str:N #1 }
432 { \tl_trim_spaces:n{ #2 } }
433 { #3 }
434 }
435
436 % \end{macrocode}
437 % \end{macro}
438 %
439 %\begin{macro}{\stycmd_xparsecmd:N}
440 % Defines the main macro with \cs{ProvideDocumentCommand}.
441 % \begin{macrocode}
442
443 \cs_new_protected:Nn \stycmd_xparsecmd:N
444 {
445 \ProvideDocumentCommand { #1 } { o }
446 {
447 \IfNoValueTF {##1}
448 {
449 \@@_cmd_usedef:N #1
450 }
451 {
452 \@@_cmd_usesty_strip:Nn #1 { ##1 }
453 }
454 }
455 }
456
457 % \end{macrocode}
458 %\end{macro}
459 %
460 %\begin{macro}{\stycmd_expcmd:N}
461 % Defines the main macro with \tn{providecommand} but the style argument is mandatory in order to make the command expandable. To use default style pass an empty argument as style.
462 % \begin{macrocode}
463
464 \cs_new_protected:Nn \stycmd_expcmd:N
465 {
466 \providecommand { #1 } [1]
467 {
468 \tl_if_empty:nTF {##1}
469 {
470 \@@_cmd_usedef:N #1
471 }
472 {
473 \@@_cmd_usesty_strip:Nn #1 { ##1 }
474 }
475 }
476 }
477
478 % \end{macrocode}
479 %\end{macro}
480 %
481 %\begin{macro}{\SetGlobalStyle}
482 %Change the default style for specified command
483 % \begin{macrocode}
484
485 \NewDocumentCommand{\SetGlobalStyle}{m m}
486 {
487 \@@_setdef_strip:Nn #1 { #2 }
488 }
489
490 % \end{macrocode}
491 %\end{macro}
492 %
493 %\begin{macro}{\stycmd_generate:NNN, \stycmd_generate:NN, \stycmd_generate_renew:NN}
494 %Declare the styled version \verb+#1+ of the macro generator command \verb+#2+. the \verb+_renew+ variant requires a preceding declaration
495 % \begin{macrocode}
496
497 \cs_new_protected:Nn \stycmd_generate:NNN
498 {
499 \cs_new_protected:Npn #1 ##1 ##2
500 {
501 \@@_entity_create_strip:Nnn ##1 { ##2 }
502 {
503 #3 ##1
504 }
505 \@@_cmd_define_strip:NNn #2 ##1 { ##2 }
506 }
507 }
508
509 \cs_new_protected:Nn \stycmd_generate:NN
510 {
511 \stycmd_generate:NNN #1 #2 \stycmd_xparsecmd:N
512 }
513
514
515 \cs_new_protected:Nn \stycmd_generate_renew:NN
516 {
517 \cs_new_protected:Npn #1 ##1 ##2
518 {
519 \@@_cmd_define_strip:NNn #2 ##1 { ##2 }
520 }
521 }
522
523 % \end{macrocode}
524 %\end{macro}
525 %
526 %\begin{macro}{\newstyledcmd, \renewstyledcmd, \providestyledcmd}
527 %Declare a new macro with the specified style name.
528 % \begin{macrocode}
529 \stycmd_generate:NN \newstyledcmd \newcommand
530 \stycmd_generate_renew:NN \renewstyledcmd \renewcommand
531 \stycmd_generate:NN \providestyledcmd \providecommand
532 % \end{macrocode}
533 %\end{macro}
534 %
535 %\begin{macro}{\NewDocStyledCMD, \RenewDocStyledCMD, \ProvideDocStyledCMD}
536 %Declare a new styled macro with the \tn{NewDocumentCommand} syntax.
537 % \begin{macrocode}
538 \stycmd_generate:NN \NewDocStyledCMD \NewDocumentCommand
539 \stycmd_generate_renew:NN \RenewDocStyledCMD \RenewDocumentCommand
540 \stycmd_generate:NN \ProvideDocStyledCMD \ProvideDocumentCommand
541 % \end{macrocode}
542 %\end{macro}
543 %
544 %\begin{macro}{\newstyledcmdExp, \renewstyledcmdExp, \providestyledcmdExp}
545 %Declare a new macro with the specified style name.
546 % \begin{macrocode}
547 \stycmd_generate:NNN \newstyledcmdExp \newcommand \stycmd_expcmd:N
548 \stycmd_generate_renew:NN \renewstyledcmdExp \renewcommand
549 \stycmd_generate:NNN \providestyledcmdExp \providecommand \stycmd_expcmd:N
550 % \end{macrocode}
551 %\end{macro}
552 %
553 %\begin{macro}{\AddCMDToGroup}
554 %Creates a group of commands
555 % \begin{macrocode}
556
557 \str_new:N \g_@@_grproxy_str
558 \seq_new:N \g_@@_tmp_seq
559 \seq_new:N \g_@@_tmpb_seq
560
561 \proxy_create_gset:Nnn \g_@@_grproxy_str { stycmd }{ groups }
562
563 \proxy_push_member:Vnn \g_@@_grproxy_str { commands }{ seq }
564
565 \cs_generate_variant:Nn \seq_gconcat:NNN { ccN }
566
567 \cs_new_protected:Nn \@@_gconcat:nN
568 {
569 \seq_gconcat:ccN { #1 }{ #1 } #2
570 }
571
572 \cs_new_protected:Nn \@@_addgroup:nn
573 {
574 \object_if_exist:nF
575 {
576 \object_address:nn{ stycmd }{ group - #1 }
577 }
578 {
579 \object_create:Vnn \g_@@_grproxy_str
580 { stycmd }
581 { group - #1 }
582 }
583
584 \seq_gset_from_clist:Nn \g_@@_tmp_seq { #2 }
585 \seq_gset_map_x:NNn \g_@@_tmpb_seq \g_@@_tmp_seq
586 {
587 \cs_to_str:N ##1
588 }
589
590 \@@_gconcat:nN
591 {
592 \object_member_adr:nnn
593 {
594 \object_address:nn
595 { stycmd }
596 { group - #1 }
597 }
598 { commands }
599 { seq }
600 } \g_@@_tmpb_seq
601 }
602
603 \cs_generate_variant:Nn \@@_addgroup:nn { fn }
604
605 \NewDocumentCommand{\AddCMDToGroup}{m m}
606 {
607 \@@_addgroup:fn { \tl_trim_spaces:n{ #1 } } { #2 }
608 }
609
610 % \end{macrocode}
611 %\end{macro}
612 %
613 %\begin{macro}{\SetGroupStyle}
614 %Change the default style for each command in the group.
615 % \begin{macrocode}
616 \NewDocumentCommand{\SetGroupStyle}{m m}
617 {
618 \seq_map_inline:cn
619 {
620 \object_member_adr:nnn
621 {
622 \object_address:nn
623 { stycmd }
624 { group - #1 }
625 }
626 { commands }
627 { seq }
628 }
629 {
630 \@@_setdef_style:nn{ ##1 }{ #2 }
631 }
632 }
633 % \end{macrocode}
634 %\end{macro}
635 %
636 %Legacy commands
637 % \begin{macrocode}
638
639 \msg_new:nnnn{ styledcmd }{ stydep }{ Old-fashioned~groups~for~styled~commands~are~deprecated }
640 {
641 From~version~2.0~of~styledcmd~you~should~use~new~group~commands~instea~of~old~ones,~see~official~documentation~on~CTAN.
642 }
643
644 \str_new:N \g_@@_act_group_str
645 \str_new:N \g_@@_act_style_str
646
647 \NewDocumentCommand{\styBeginGroup}{ m }
648 {
649 \msg_warning:nn{ styledcmd }{ stydep }
650 \str_gset:Nn \g_@@_act_group_str{ #1 }
651 }
652
653 \NewDocumentCommand{\styEndGroup}{}
654 {
655 \msg_warning:nn{ styledcmd }{ stydep }
656 \str_gset:Nn \g_@@_act_group_str{}
657 }
658
659 \NewDocumentCommand{\styBeginStyle}{ m }
660 {
661 \msg_warning:nn{ styledcmd }{ stydep }
662 \str_gset:Nn \g_@@_act_style_str{ #1 }
663 }
664
665 \NewDocumentCommand{\styEndStyle}{}
666 {
667 \msg_warning:nn{ styledcmd }{ stydep }
668 \str_gset:Nn \g_@@_act_style_str{}
669 }
670
671 \cs_generate_variant:Nn \@@_addgroup:nn { Vn }
672
673 \NewDocumentCommand{\newGstyledcmd}{m o m}
674 {
675 \msg_warning:nn{ styledcmd }{ stydep }
676 \@@_addgroup:Vn \g_@@_act_group_str { #1 }
677 \IfNoValueTF{ #2 }
678 {
679 \exp_args:NNV \newstyledcmd #1 \g_@@_act_style_str { #3 }
680 }
681 {
682 \exp_args:NNV \newstyledcmd #1 \g_@@_act_style_str [ #2 ] { #3 }
683 }
684 }
685
686 \NewDocumentCommand{\NewGDocStyledCMD}{m m m}
687 {
688 \msg_warning:nn{ styledcmd }{ stydep }
689 \@@_addgroup:Vn \g_@@_act_group_str { #1 }
690 \exp_args:NNV \NewDocStyledCMD #1 \g_@@_act_style_str { #2 } { #3 }
691 }
692
693 \NewDocumentCommand{\setGroupStyle}{m m}
694 {
695 \msg_warning:nn{ styledcmd }{ stydep }
696 \SetGroupStyle{ #1 }{ #2 }
697 }
698 % \end{macrocode}
699 %
700 % \begin{macrocode}
701 %</package>
702 % \end{macrocode}
703 %
704 %\end{implementation}
705 %
706 %\PrintIndex