diff options
author | Karl Berry <karl@freefriends.org> | 2022-12-13 21:06:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-12-13 21:06:54 +0000 |
commit | 619b560e8164b9f0cddb6bb443e921e54904237b (patch) | |
tree | 9f6af72e405da40f48f484166b4c7667534df5aa /Master/texmf-dist/source/latex | |
parent | 467f85c787d8654f13143688c4e2dd3e86e9145a (diff) |
styledcmd (13dec22)
git-svn-id: svn://tug.org/texlive/trunk@65262 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex')
-rw-r--r-- | Master/texmf-dist/source/latex/styledcmd/styledcmd.dtx | 706 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/styledcmd/styledcmd.ins | 1 |
2 files changed, 423 insertions, 284 deletions
diff --git a/Master/texmf-dist/source/latex/styledcmd/styledcmd.dtx b/Master/texmf-dist/source/latex/styledcmd/styledcmd.dtx index 79da85718ad..c11714952aa 100644 --- a/Master/texmf-dist/source/latex/styledcmd/styledcmd.dtx +++ b/Master/texmf-dist/source/latex/styledcmd/styledcmd.dtx @@ -1,4 +1,4 @@ -% \iffalse meta-comment + % \iffalse meta-comment % % styledcmd Handle multiple versions for user-defined macros in LaTeX % Copyright (C) 2021 Paolo De Donato <dedonato95@hotmail.it> @@ -22,11 +22,12 @@ % % \iffalse %<*driver> -\ProvidesFile{styledcmd.dtx}[2021/08/20 1.1 Command with different styles] +\ProvidesFile{styledcmd.dtx}[2022/12/13 2.0 Command with different styles] %</driver> %<package>\NeedsTeXFormat{LaTeX2e} -%<package>\RequirePackage{expl3}[2018-04-12] -%<package>\ProvidesExplPackage{styledcmd}{2021/08/20}{1.1}{Command with different styles} +%<package>\RequirePackage{expl3}[2022-04-10] +%<package>\ProvidesExplPackage{styledcmd}{2022/12/13}{2.0}{Command with different styles} +%<package>\RequirePackage{lt3rawobjects}[2022-12-12] %<package>\RequirePackage{xparse} %<*driver> \documentclass[full]{l3doc} @@ -44,7 +45,7 @@ % %\title{styledcmd} %\author{Paolo De Donato} -%\date{23 August 2021} +%\date{13 December 2022} % %\maketitle % @@ -64,16 +65,19 @@ %You can create a formatted macro via the following command %\begin{function}{\newstyledcmd, \renewstyledcmd, \providestyledcmd} %\begin{syntax} -%|\newstyledcmd| \marg{macro name} \marg{format name} \oarg{number of arguments} \marg{code} +%\tn{newstyledcmd} \{\tn{\meta{macro name}}\} \marg{style name} \oarg{number of arguments} \marg{code} %\end{syntax} +%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}. %\end{function} % -%You can repeat that command for the same macro in order to create different styles, for example these commands +%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. +% +%As an example these commands %\begin{verbatim} % \newstyledcmd{\saluto}{informal}[1]{Hi #1} % \newstyledcmd{\saluto}{formal}[1]{Good morning #1} %\end{verbatim} -%define the two formats \verb+informal+ and \verb+formal+ for macro \tn{saluto}. You can directly use the command \tn{saluto} and use the default format (the first declared one) or using a specific style by passing it as an optional argument. So commands +%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 %\begin{verbatim} % \saluto{uncle} % \saluto[informal]{uncle} @@ -82,22 +86,22 @@ %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. % %\section{How do you change the default style?} -%In order to change the default style (the one used when you don't choose explicitily a format) you need to execute the following command -%\begin{function}{\setGlobalStyle} +%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 +%\begin{function}{\SetGlobalStyle} %\begin{syntax} -%|\setGlobalStyle| \marg{command name} \marg{new default format name} +%\tn{SetGlobalStyle} \{\cs{\meta{command name}}\} \marg{new default style name} %\end{syntax} %\end{function} -%\setGlobalStyle{\saluto}{formal} +%\SetGlobalStyle{\saluto}{formal} % -%For example in order to change the default style of command \tn{saluto} from \verb+informal+ to \verb+formal+ you need to execute command \verb+\setGlobalStyle{\saluto}{formal}+. With this command the output of preceding commands will instead be \saluto{uncle}, \saluto[informal]{uncle}, \saluto[formal]{uncle}. +%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}. % %\section{Customize parameters with \pkg{xparse}} %\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 % %\begin{function}{\NewDocStyledCMD, \RenewDocStyledCMD, \ProvideDocStyledCMD} %\begin{syntax} -%|\NewDocStyledCMD| \marg{command name} \marg{format name} \marg{arguments format} \marg{code} +%\tn{NewDocStyledCMD} \Arg{\cs{\meta{command name}}} \Arg{format name} \Arg{arguments format} \Arg{code} %\end{syntax} %\end{function} % @@ -114,116 +118,132 @@ % \prova[stylea]<Hello> % \prova[styleb]<Hello> %\end{verbatim} -%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{NewDocStyleCMD} 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. +%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. % %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}. % +%\section{Expandable commands} +%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 % -%\section{Commands group} -%You can define also a commands group in which defined commands will share the same styles, that allow you to change the style for all commands in that group. -% -%To start a group you have to use the following macro -%\begin{function}{\styBeginGroup} -%\begin{syntax} -%|\styBeginGroup| \marg{group name} -%\end{syntax} -%\end{function} -%any group should be terminated via the following macro -%\begin{function}{\styEndGroup} +%\begin{function}{\newstyledcmdExp, \renewstyledcmdExp, \providestyledcmdExp} %\begin{syntax} -%|\styEndGroup| +%\tn{newstyledcmdExp} \{\tn{\meta{macro name}}\} \marg{style name} \oarg{number of arguments} \marg{code} %\end{syntax} %\end{function} +% 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. % -%In each group commands are grouped toghether according to the used style. So inside a group you can define a style with the command -%\begin{function}{\styBeginStyle} -%\begin{syntax} -%|\styBeginStyle| \marg{format name} -%\end{syntax} -%\end{function} -%and once you've finished to define command with that style you have to close it with the command -%\begin{function}{\styEndStyle} -%\begin{syntax} -%|\styEndStyle| -%\end{syntax} -%\end{function} +% For example this code +%\begin{verbatim} +% \newstyledcmdExp{\expCMD}{sty1}{Style 1} +% \newstyledcmdExp{\expCMD}{sty2}{Style 2} % -%In order to define a command inside a \tn{styBeginStyle} ... \tn{styEndStyle} you can use +% \expCMD{} +% \expCMD{sty1} +% \expCMD{sty2} +%\end{verbatim} +%expand as \newstyledcmdExp{\expCMD}{sty1}{Style 1}\newstyledcmdExp{\expCMD}{sty2}{Style 2} \expCMD{} \expCMD{sty1} \expCMD{sty2} % -%\begin{function}{\newGstyledcmd} +%\section{Groups} +%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: +%\begin{function}{\AddCMDToGroup} %\begin{syntax} -%|\newGstyledcmd| \marg{command name} \oarg{arguments number} \marg{code} +% \tn{AddCMDToGroup} \Arg{group name} \Arg{comma list of commands} %\end{syntax} %\end{function} -%or -%\begin{function}{\NewGDocStyledCMD} +% You can change the default style for each member of a group with +%\begin{function}{\SetGroupStyle} %\begin{syntax} -%|\NewGDocStyledCMD| \marg{command name} \marg{arguments format} \marg{code} +% \tn{SetGroupStyle} \Arg{group name} \Arg{style name} %\end{syntax} %\end{function} -%if you want to use the \tn{NewDocumentCommand} syntax. -% -%Notice that in this case you mustn't define the style name in \tn{newGstyledcmd} or in \tn{NewGDocStyledCMD} since they use the format defined in the enclosing \tn{styBeginStyle} ... \tn{styEndStyle}. The defined style for a group is the first defined one, in order to change the default format you should use the following macro % -%\begin{function}{\setGroupStyle} -%\begin{syntax} -%|\setGroupStyle| \marg{group name} \marg{new default style} -%\end{syntax} +%Suppose you've created the following styled commands: +% +% \begin{verbatim} +% \newstyledcmd{\LenUnit}{SI}{metre} +% \newstyledcmd{\MasUnit}{SI}{kilo} +% +% \newstyledcmd{\LenUnit}{old}{yard} +% \newstyledcmd{\MasUnit}{old}{pound} +% \end{verbatim} +% +% \newstyledcmd{\LenUnit}{SI}{metre} +% \newstyledcmd{\MasUnit}{SI}{kilo} +% +% \newstyledcmd{\LenUnit}{old}{yard} +% \newstyledcmd{\MasUnit}{old}{pound} +% +% 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 +% \begin{verbatim} +% \AddCMDToGroup{Units}{\LenUnit, \MasUnit} +% \end{verbatim} +% \AddCMDToGroup{Units}{\LenUnit}\AddCMDToGroup{Units}{\MasUnit}\SetGroupStyle{Units}{old}If you want to set |old| as the default style for these commands just run +% \begin{verbatim} +% \SetGroupStyle{Units}{old} +% \end{verbatim} +% now \tn{LenUnit}, \tn{MasUnit} will expand as \LenUnit, \MasUnit\ respectively. +% +% Notice that if the specified group already exists then \tn{AddCMDToGroup} just appends the speficied commands to it. In particular this +% \begin{verbatim} +% \AddCMDToGroup{Units}{\LenUnit} +% \AddCMDToGroup{Units}{\MasUnit} +% \end{verbatim} +% is equivalent to write +% \begin{verbatim} +% \AddCMDToGroup{Units}{\LenUnit, \MasUnit} +% \end{verbatim} +% +%\section{Advanced usage} +%\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. +% +% What you see as a styled command it's instead a collection of different macros: +% \begin{itemize} +% \item multiple \emph{effective styled commands} (\emph{ES commands}), one for each style; +% \item a single \emph{dispatch command} that's called by the user and expands to the specified ES command. +% \end{itemize} +% +% \begin{function}{\stycmd_generate:NNN, \stycmd_generate:NN} +% \begin{syntax} +% \cs{stycmd_generate:NNN} \meta{generator name} \meta{ES commands generator} \meta{dispatch command generator} +% \cs{stycmd_generate:NN} \meta{generator name} \meta{ES commands generator} +% \end{syntax} +% 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}. +% \end{function} +% +% 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: +% +% \begin{function}{\stycmd_xparsecmd:N} +% \begin{syntax} +% \cs{stycmd_xparsecmd:N} \meta{command} +% \end{syntax} +% Creates the dispatch command with \tn{ProvideDocumentCommand} with optional style name parameter (used in \tn{newstyledcmd} and \tn{NewDocStyledCMD}). %\end{function} % -%Consider now the following example -% -% \styBeginGroup{saluti} -% \styBeginStyle{formal} -% \newGstyledcmd{\ciao}[1]{Good morning #1} -% \newGstyledcmd{\via}{Goodbye} -% \styEndStyle -% \styBeginStyle{informal} -% \newGstyledcmd{\ciao}[1]{Hi #1} -% \newGstyledcmd{\via}{Catch you later} -% \styEndStyle -% \styEndGroup -% -%\begin{verbatim} -% \styBeginGroup{saluti} -% \styBeginStyle{formal} -% \newGstyledcmd{\ciao}[1]{Good morning #1} -% \newGstyledcmd{\via}{Goodbye} -% \styEndStyle -% -% \styBeginStyle{informal} -% \newGstyledcmd{\ciao}[1]{Hi #1} -% \newGstyledcmd{\via}{Catch you later} -% \styEndStyle -% \styEndGroup -%\end{verbatim} -%We've defined the group \verb+saluti+ with two styles: \verb+formal+ and \verb+informal+. In that group are also defined the two commands \tn{ciao} and \tn{via} for both the styles. Since in \verb+saluti+ group the first defined style is \verb+formal+ it'll be also the default style for this group, so commands \verb+\ciao{Enrico}+ and \verb+\via+ will be expanded as \ciao{Enrico} and \via{}. -% -%If now we execute the command \setGroupStyle{saluti}{informal} \verb+\setGroupStyle{saluti}{informal}+ we change the default style to \verb+informal+ so the preceding commands this time will be expanded as \ciao{Enrico} and \via{}. -% -%You can also pass an optional argument for the style name you want to use, in particular \verb+\ciao[formal]{Enrico}+ will be always expanded as \ciao[formal]{Enrico}. -% -%\section{Generate more styled commands} -%Suppose now that you've created your own version of \tn{newcommand} or \tn{NewDocumentCommand} in order to generate some classes of commands. Suppose that your function name is \tn{mynewcommand} and it accepts, like \tn{newcommand}, the new macro as its first argument. Then you can create styled commands with your own macro by using this function -%\begin{function}{\stycmd_generate:NN, \stycmd_generate_renew:NN} -%\begin{syntax} -%|\stycmd_generate:NN| \meta{new generator name} \meta{generator name} -%\end{syntax} +%\begin{function}{\stycmd_expcmd:N} +% \begin{syntax} +% \cs{stycmd_expcmd:N} \meta{command} +% \end{syntax} +% Creates the dispatch command with \tn{providecommand} with mandatory style name parameter (used in \tn{newstyledcmdExp}). %\end{function} -%So for example executing -%\begin{verbatim} -% \stycmd_generate:NN\mynewstyledcommand\mynewcommand -%\end{verbatim} -%you'll create the new macro \tn{mynewstyledcommand} that accepts the command you want to define as first argument, the style you want to use as second argument and the remaining arguments are the same needed by \tn{mynewcommand}. % -%Notice that \tn{newstyledcmd} is defined internally as -%\begin{verbatim} -% \stycmd_generate:NN \newstyledcmd \newcommand -%\end{verbatim} -% -%Notice that \tn{mynewcommand} first argument has to be the macro you want to define, otherwise \cs{stycmd_generate:NN} will have undefined behaviour. The \cs{stycmd_generate_renew:NN} function should be used only for ''renew`` type commands that requires a preceding declaration, like \tn{renewcommand} and \tn{RenewDocumentCommand}. -% -%Actually there isn't any analogue proceeding for defining customized versions for \tn{newGstyledcmd} and \tn{NewGDocStyledCMD}. +% If you don't specify the dispatch command generator (by using the |NN| variant) \cs{stycmd_xparsecmd:N} is used implicitly. +% +% \begin{function}{\stycmd_generate_renew:NN} +% \begin{syntax} +% \cs{stycmd_generate_renew:NN} \meta{updater name} \meta{ES commands generator} +% \end{syntax} +% Creates command \tn{\meta{updater name}} that modifies styles of commands already generated, like \tn{renewcommmand} edits commands generated by \tn{newcommand}. +% +% For example if you have \tn{createA} that creates commands and \tn{editA} that edits commands generated by \tn{createA} then +% \begin{verbatim} +% \stycmd_generate:NN \createStyledA \createA +% \end{verbatim} +% creates styled commands by using \tn{createA} and +% \begin{verbatim} +% \stycmd_generate_renew:NN \editStyledA \editA +% \end{verbatim} +% modifies commands generated by \tn{createStyledA} (by invoking \tn{editA}). +% \end{function} % %\end{documentation} % @@ -238,167 +258,270 @@ %<@@=stycmd> % \end{macrocode} % -%\begin{variable}{\c__stycmd_defname_str} -%the default style +%\begin{variable}{\c_@@_cmdproxy_str} +%Proxy used to generate styled commands % \begin{macrocode} -\str_const:Nn \c_@@_defname_str{ default } + +\str_const:Nx \c_@@_cmdproxy_str { \object_address:nn + { stycmd }{ proxy } } + +\proxy_create:nnN { stycmd }{ proxy } \c_object_public_str +\proxy_push_member:Vnn \c_@@_cmdproxy_str { default }{ tl } + % \end{macrocode} %\end{variable} % -%\begin{variable}{\l__stycmd_cexp_str, \l__stycmd_fexp_str} -%Temporary variables to store expanded names. +%\begin{macro}{\@@_cmd:n} +% Entity name % \begin{macrocode} -\str_new:N \l_@@_cexp_str -\str_new:N \l_@@_fexp_str + +\cs_new:Nn \@@_cmd:n + { + \object_address:nn{ stycmd }{ entity - #1 } + } + % \end{macrocode} -%\end{variable} +%\end{macro} % -%\begin{macro}{\__stycmd_cmd:nn, \__stycmd_cmd:nV, \__stycmd_cmd:VV, \__stycmd_cmd:, \__stycmd_cmddefname:n} -%Name of a command bounded to some style. +%\begin{macro}{\@@_setdef_strip:Nn} +%Changes the default style % \begin{macrocode} -\cs_new:Npn \__stycmd_cmd:nn #1#2{ @@_command_#1_#2 } -\cs_generate_variant:Nn \@@_cmd:nn { nV } -\cs_generate_variant:Nn \@@_cmd:nn { VV } +\cs_new_protected:Nn \@@_setdef_aux:nN + { + \object_member_set:nnn + { + \@@_cmd:n{ #1 } + } + { default } + { #2 } + } +\cs_generate_variant:Nn \@@_setdef_aux:nN { nc } -\cs_new:Nn \@@_cmd: +\cs_new_protected:Nn \@@_setdef_style:nn { - \@@_cmd:VV\l_@@_cexp_str\l_@@_fexp_str + \@@_setdef_aux:nc{ #1 } + { + \object_macro_adr:nn + { + \@@_cmd:n{ #1 } + } + { + style - #2 + } + } } -\cs_new:Npn \@@_cmddefname:n #1 +\cs_generate_variant:Nn \@@_setdef_style:nn { ff } + +\cs_new_protected:Nn \@@_setdef_strip:Nn { - \@@_cmd:nV { #1 } \c_@@_defname_str + \@@_setdef_style:ff{ \cs_to_str:N #1 } + { \tl_trim_spaces:n{ #2 } } } + % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_erroring:nn, \__stycmd_erroring:nV, \__stycmd_erroring:VV} -%Error messages for undefined styles. +%\begin{macro}{\@@_cmd_define_strip:NNn} +% Define a macro with the specified command % \begin{macrocode} -\msg_new:nnn { stycmd } { noformat } + +\cs_new_protected:Nn \@@_cmd_define_aux_aux:NN { - Style~#2~not~defined~for~command~#1 + #1 { #2 } } +\cs_generate_variant:Nn \@@_cmd_define_aux_aux:NN { Nc } -\cs_new_protected:Npn\@@_erroring:nn #1#2 +\cs_new_protected:Nn \@@_cmd_define_aux:Nnn { - \cs_if_free:cT { \@@_cmd:nn {#1} {#2} } - { \msg_error:nnnn { stycmd } { noformat } {#1} {#2} } + \@@_cmd_define_aux_aux:Nc #1 + { + \object_macro_adr:nn + { + \@@_cmd:n{ #2 } + } + { + style - #3 + } + } + } + +\cs_generate_variant:Nn \@@_cmd_define_aux:Nnn { Nff } + +\cs_new_protected:Nn \@@_cmd_define_strip:NNn + { + \@@_cmd_define_aux:Nff #1 + { \cs_to_str:N #2 }{ \tl_trim_spaces:n { #3 } } } -\cs_generate_variant:Nn \@@_erroring:nn { nV, VV } % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_deferr:} -%Error message when try to create the \verb+default+ style +%\begin{macro}{\@@_cmd_usedef:N, \@@_cmd_usesty_strip:Nn} +%Uses the styled command % \begin{macrocode} -\msg_new:nnn { stycmd } { deferror } + +\cs_new:Nn \@@_cmd_usedef_aux:n { - Cannot~define~a~style~with~name~default + \object_member_use:nn + { + \@@_cmd:n{ #1 } + } + { + default + } } -\cs_new_protected:Nn\@@_deferr: +\cs_generate_variant:Nn \@@_cmd_usedef_aux:n { f } + +\cs_new:Nn \@@_cmd_usedef:N + { + \@@_cmd_usedef_aux:f{ \cs_to_str:N #1 } + } + + +\cs_new:Nn \@@_cmd_usesty_aux:nn + { + \object_macro_use:nn + { + \@@_cmd:n{ #1 } + } + { + style - #2 + } + } + +\cs_generate_variant:Nn \@@_cmd_usesty_aux:nn { ff } + +\cs_new:Nn \@@_cmd_usesty_strip:Nn { - \str_if_eq:NNT \l_@@_fexp_str \c_@@_defname_str - { \msg_error:nn { stycmd } { deferror } } + \@@_cmd_usesty_aux:ff{ \cs_to_str:N #1 } + { \tl_trim_spaces:n{ #2 } } } + % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_macro_default:nn, \__stycmd_macro_default:VV} -%Sets the default style to use. +% \begin{macro}{\@@_entity_create_strip:Nnn} +% Creates a new entity if it doesn't exists and execute following code % \begin{macrocode} -\cs_new_protected:Npn \@@_macro_default:nn #1#2 + +\cs_new_protected:Nn \@@_entity_create_aux:nnn { - \exp_args:Nc \ProvideDocumentCommand { \@@_cmddefname:n { #1 } } - {} + \object_if_exist:nF { - \use:c { \@@_cmd:nn { #1 } { #2 } } + \@@_cmd:n{ #1 } } + { + \object_create:VnnNN \c_@@_cmdproxy_str + { stycmd }{ entity - #1 } + \c_object_global_str + \c_object_public_str + + \@@_setdef_style:nn{ #1 }{ #2 } + + #3 + } + } + +\cs_generate_variant:Nn \@@_entity_create_aux:nnn { ffn } + +\cs_new_protected:Nn \@@_entity_create_strip:Nnn + { + \@@_entity_create_aux:ffn + { \cs_to_str:N #1 } + { \tl_trim_spaces:n{ #2 } } + { #3 } } -\cs_generate_variant:Nn \@@_macro_default:nn { VV } % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{\__stycmd_macro_overwrite:nn, \__stycmd_macro_overwrite:VV} -%Overwrite the default style, not the command associated to that style. +%\begin{macro}{\stycmd_xparsecmd:N} +% Defines the main macro with \cs{ProvideDocumentCommand}. % \begin{macrocode} -\cs_new_protected:Npn \@@_macro_overwrite:nn #1#2 - { - \@@_erroring:nn { #1 } { #2 } - \exp_args:Nc \RenewDocumentCommand { \@@_cmddefname:n { #1 } } - {} +\cs_new_protected:Nn \stycmd_xparsecmd:N + { + \ProvideDocumentCommand { #1 } { o } { - \use:c { \@@_cmd:nn { #1 } { #2 } } + \IfNoValueTF {##1} + { + \@@_cmd_usedef:N #1 + } + { + \@@_cmd_usesty_strip:Nn #1 { ##1 } + } } } -\cs_generate_variant:Nn \@@_macro_overwrite:nn { VV } % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_macro_declaration:n, \__stycmd_macro_declaration:V} -%Declare the effective macro. It'll overwrite existing \tn{l__stycmd_fexp_str}. +%\begin{macro}{\stycmd_expcmd:N} +% 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. % \begin{macrocode} -\cs_new_protected:Npn \@@_macro_declaration:n #1 + +\cs_new_protected:Nn \stycmd_expcmd:N { - \exp_args:Nc \ProvideDocumentCommand { #1 } {o} + \providecommand { #1 } [1] { - \IfNoValueTF {##1} + \tl_if_empty:nTF {##1} { - \use:c { \@@_cmddefname:n { #1 } } + \@@_cmd_usedef:N #1 } { - \str_set:Nx \l_@@_fexp_str {##1} - \@@_erroring:nV { #1 } \l_@@_fexp_str - \use:c{ \@@_cmd:nV { #1 } \l_@@_fexp_str } + \@@_cmd_usesty_strip:Nn #1 { ##1 } } } } -\cs_generate_variant:Nn \__stycmd_macro_declaration:n { V } % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_init_vars:Nn} -%Initializes system variables. First argument is the command name, second argument should be \verb+x+ expandable. +%\begin{macro}{\SetGlobalStyle} +%Change the default style for specified command % \begin{macrocode} -\cs_new_protected:Npn \@@_init_vars:Nn #1#2 + +\NewDocumentCommand{\SetGlobalStyle}{m m} { - \str_set:Nx \l_@@_cexp_str { \cs_to_str:N #1 } - \str_set:Nx \l_@@_fexp_str {#2} - \@@_deferr: + \@@_setdef_strip:Nn #1 { #2 } } + % \end{macrocode} %\end{macro} % -%\begin{macro}{\stycmd_generate:NN, \stycmd_generate_renew:NN} +%\begin{macro}{\stycmd_generate:NNN, \stycmd_generate:NN, \stycmd_generate_renew:NN} %Declare the styled version \verb+#1+ of the macro generator command \verb+#2+. the \verb+_renew+ variant requires a preceding declaration % \begin{macrocode} -\cs_new_protected:Npn \stycmd_generate:NN #1#2 + +\cs_new_protected:Nn \stycmd_generate:NNN { - \NewDocumentCommand #1 {m m} + \cs_new_protected:Npn #1 ##1 ##2 { - \@@_init_vars:Nn { ##1 } { ##2 } - \@@_macro_default:VV \l_@@_cexp_str \l_@@_fexp_str - \@@_macro_declaration:V \l_@@_cexp_str - \exp_args:Nc #2 { \@@_cmd: } + \@@_entity_create_strip:Nnn ##1 { ##2 } + { + #3 ##1 + } + \@@_cmd_define_strip:NNn #2 ##1 { ##2 } } } -\cs_new_protected:Npn \stycmd_generate_renew:NN #1#2 +\cs_new_protected:Nn \stycmd_generate:NN { - \NewDocumentCommand #1 {m m} + \stycmd_generate:NNN #1 #2 \stycmd_xparsecmd:N + } + + +\cs_new_protected:Nn \stycmd_generate_renew:NN + { + \cs_new_protected:Npn #1 ##1 ##2 { - \@@_init_vars:Nn { ##1 } { ##2 } - \@@_erroring:VV \l_@@_cexp_str \l_@@_fexp_str - \exp_args:Nc #2 { \@@_cmd: } + \@@_cmd_define_strip:NNn #2 ##1 { ##2 } } } + % \end{macrocode} %\end{macro} % @@ -420,149 +543,164 @@ % \end{macrocode} %\end{macro} % -%\begin{macro}{\setGlobalStyle} -%Change the default style. -% \begin{macrocode} -\NewDocumentCommand \setGlobalStyle{m m}{ - \@@_init_vars:Nn { #1 } { #2 } - - \@@_macro_overwrite:VV \l_@@_cexp_str \l_@@_fexp_str -} -% \end{macrocode} -%\end{macro} -% -%\begin{variable}{\l__stycmd_group_str, \l__stycmd_format_str} -%Variables that stores group and format names. -% \begin{macrocode} -\str_new:N \l_@@_group_str -\str_new:N \l_@@_format_str -% \end{macrocode} -%\end{variable} -% -%\begin{macro}{\__stycmd_gvar:n, \__stycmd_gvar:V, \__stycmd_gvar:} -%Group command list. +%\begin{macro}{\newstyledcmdExp, \renewstyledcmdExp, \providestyledcmdExp} +%Declare a new macro with the specified style name. % \begin{macrocode} -\cs_new:Npn \@@_gvar:n #1 { g_@@_glist_#1_seq } - -\cs_generate_variant:Nn \@@_gvar:n { V } - -\cs_new:Nn \@@_gvar: { \@@_gvar:V \l_@@_group_str } +\stycmd_generate:NNN \newstyledcmdExp \newcommand \stycmd_expcmd:N +\stycmd_generate_renew:NN \renewstyledcmdExp \renewcommand +\stycmd_generate:NNN \providestyledcmdExp \providecommand \stycmd_expcmd:N % \end{macrocode} %\end{macro} % -%\begin{macro}{\__stycmd_push_g:Nn, \__stycmd_push_g:NV} -%Pushes command name inside group command sequence. First argument is command, second is group name +%\begin{macro}{\AddCMDToGroup} +%Creates a group of commands % \begin{macrocode} -\cs_new_protected:Npn \@@_push_g:Nn #1#2 - { - \seq_gput_left:cn { \@@_gvar:n { #2 } } { #1 } - } -\cs_generate_variant:Nn \@@_push_g:Nn { NV } -% \end{macrocode} -%\end{macro} -% -%\begin{macro}{\styBeginGroup} -%Starts a group. -% \begin{macrocode} -\msg_new:nnn { stycmd } { gnotclosed } { Group~not~closed } +\str_new:N \g_@@_grproxy_str +\seq_new:N \g_@@_tmp_seq +\seq_new:N \g_@@_tmpb_seq -\NewDocumentCommand \styBeginGroup { m } - { - \str_if_empty:NF \l_@@_group_str - { - \msg_error:nn { stycmd } { gnotclosed } - } +\proxy_create_gset:NnnN \g_@@_grproxy_str { stycmd }{ groups } + \c_object_public_str + +\proxy_push_member:Vnn \g_@@_grproxy_str { commands }{ seq } - \str_set:Nx \l_@@_group_str {#1} +\cs_generate_variant:Nn \seq_gconcat:NNN { ccN } - \seq_if_exist:cF { \@@_gvar: } - { \seq_new:c { \@@_gvar: } } - } -% \end{macrocode} -%\end{macro} -% -%\begin{macro}{\styEndGroup} -%Closes a group. -% \begin{macrocode} -\NewDocumentCommand \styEndGroup {} +\cs_new_protected:Nn \@@_gconcat:nN { - \str_clear:N \l_@@_group_str + \seq_gconcat:ccN { #1 }{ #1 } #2 } -% \end{macrocode} -%\end{macro} -% -%\begin{macro}{\styBeginStyle} -%Starts a style subgroup. -% \begin{macrocode} -\msg_new:nnn { stycmd } { fnotclosed } { Format~not~closed } - -\NewDocumentCommand \styBeginStyle { m } + +\cs_new_protected:Nn \@@_addgroup:nn { - \str_if_empty:NF \l_@@_format_str + \object_if_exist:nF + { + \object_address:nn{ stycmd }{ group - #1 } + } { - \msg_error:nn { stycmd } { fnotclosed } + \object_create:VnnNN \g_@@_grproxy_str + { stycmd } + { group - #1 } + \c_object_global_str + \c_object_public_str } - \str_set:Nx \l_@@_format_str {#1} + + \seq_gset_from_clist:Nn \g_@@_tmp_seq { #2 } + \seq_gset_map_x:NNn \g_@@_tmpb_seq \g_@@_tmp_seq + { + \cs_to_str:N ##1 + } + + \@@_gconcat:nN + { + \object_member_adr:nnn + { + \object_address:nn + { stycmd } + { group - #1 } + } + { commands } + { seq } + } \g_@@_tmpb_seq } -% \end{macrocode} -%\end{macro} -% -%\begin{macro}{\styEndStyle} -%Closes a style subgroup. -% \begin{macrocode} -\NewDocumentCommand \styEndStyle {} + +\cs_generate_variant:Nn \@@_addgroup:nn { fn } + +\NewDocumentCommand{\AddCMDToGroup}{m m} { - \str_clear:N \l_@@_format_str + \@@_addgroup:fn { \tl_trim_spaces:n{ #1 } } { #2 } } + % \end{macrocode} %\end{macro} % -%\begin{macro}{\newGstyledcmd} -%Declare a command inside a styled group. +%\begin{macro}{\SetGroupStyle} +%Change the default style for each command in the group. % \begin{macrocode} -\NewDocumentCommand \newGstyledcmd { m o +m } +\NewDocumentCommand{\SetGroupStyle}{m m} { - \IfNoValueTF {#2} + \seq_map_inline:cn { - \newstyledcmd {#1} { \l_@@_format_str } {#3} + \object_member_adr:nnn + { + \object_address:nn + { stycmd } + { group - #1 } + } + { commands } + { seq } } { - \newstyledcmd {#1} { \l_@@_format_str } [#2] {#3} + \@@_setdef_style:nn{ ##1 }{ #2 } } - \@@_push_g:NV {#1} \l_@@_group_str } % \end{macrocode} %\end{macro} % -%\begin{macro}{\NewGDocStyledCMD} -%Equivalent of \tn{NewDocStyledCMD} for command defined in a group. +%Legacy commands % \begin{macrocode} -\NewDocumentCommand \NewGDocStyledCMD { m m +m } + +\msg_new:nnnn{ styledcmd }{ stydep }{ Old-fashioned~groups~for~styled~commands~are~deprecated } { - \NewDocStyledCMD {#1} { \l_@@_format_str } {#2} {#3} + From~version~2.0~of~styledcmd~you~should~use~new~group~commands~instea~of~old~ones,~see~official~documentation~on~CTAN. + } + +\str_new:N \g_@@_act_group_str +\str_new:N \g_@@_act_style_str - \@@_push_g:NV {#1} \l_@@_group_str +\NewDocumentCommand{\styBeginGroup}{ m } + { + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g_@@_act_group_str{ #1 } } -% \end{macrocode} -%\end{macro} -% -%\begin{macro}{\setGroupStyle} -%Change the default style for a group. -% \begin{macrocode} -\NewDocumentCommand \setGroupStyle { m m } + +\NewDocumentCommand{\styEndGroup}{} + { + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g_@@_act_group_str{} + } + +\NewDocumentCommand{\styBeginStyle}{ m } + { + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g_@@_act_style_str{ #1 } + } + +\NewDocumentCommand{\styEndStyle}{} + { + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g_@@_act_style_str{} + } + +\cs_generate_variant:Nn \@@_addgroup:nn { Vn } + +\NewDocumentCommand{\newGstyledcmd}{m o m} { - \str_set:Nx \l_@@_group_str {#1} - \str_set:Nx \l_@@_format_str {#2} - \seq_map_inline:cn { \@@_gvar: } + \msg_warning:nn{ styledcmd }{ stydep } + \@@_addgroup:Vn \g_@@_act_group_str { #1 } + \IfNoValueTF{ #2 } { - \setGlobalStyle {##1} { \l_@@_format_str } + \exp_args:NNV \newstyledcmd #1 \g_@@_act_style_str { #3 } + } + { + \exp_args:NNV \newstyledcmd #1 \g_@@_act_style_str [ #2 ] { #3 } } - \str_clear:N \l_@@_format_str - \str_clear:N \l_@@_group_str } + +\NewDocumentCommand{\NewGDocStyledCMD}{m m m} + { + \msg_warning:nn{ styledcmd }{ stydep } + \@@_addgroup:Vn \g_@@_act_group_str { #1 } + \exp_args:NNV \NewDocStyledCMD #1 \g_@@_act_style_str { #2 } { #3 } + } + + \NewDocumentCommand{\setGroupStyle}{m m} + { + \msg_warning:nn{ styledcmd }{ stydep } + \SetGroupStyle{ #1 }{ #2 } + } % \end{macrocode} -%\end{macro} % % \begin{macrocode} %</package> diff --git a/Master/texmf-dist/source/latex/styledcmd/styledcmd.ins b/Master/texmf-dist/source/latex/styledcmd/styledcmd.ins index d314af58ae7..1b48ace486c 100644 --- a/Master/texmf-dist/source/latex/styledcmd/styledcmd.ins +++ b/Master/texmf-dist/source/latex/styledcmd/styledcmd.ins @@ -45,6 +45,7 @@ along with Styledcmd. If not, see <https://www.gnu.org/licenses/>. \endpreamble +\askforoverwritefalse \generate{\file{styledcmd.sty}{\from{styledcmd.dtx}{package}}} \obeyspaces |