diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/exsheets/cntformats.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/exsheets/cntformats.sty | 241 |
1 files changed, 127 insertions, 114 deletions
diff --git a/Master/texmf-dist/tex/latex/exsheets/cntformats.sty b/Master/texmf-dist/tex/latex/exsheets/cntformats.sty index f97ca6147e0..cb2cccd2db0 100644 --- a/Master/texmf-dist/tex/latex/exsheets/cntformats.sty +++ b/Master/texmf-dist/tex/latex/exsheets/cntformats.sty @@ -9,7 +9,7 @@ % Web: https://bitbucket.org/cgnieder/exsheets/ % E-Mail: contact@mychemistry.eu % -------------------------------------------------------------------------- -% Copyright 2012 Clemens Niederberger +% Copyright 2012-2013 Clemens Niederberger % % This work may be distributed and/or modified under the % conditions of the LaTeX Project Public License, either version 1.3 @@ -28,29 +28,23 @@ % If you have any ideas, questions, suggestions or bugs to report, please % feel free to contact me. % -------------------------------------------------------------------------- -\def\@cntfmts@date{2012/04/23} -\def\@cntfmts@version{v0.5} - -\ProvidesPackage{cntformats}[\@cntfmts@date\space \@cntfmts@version\space A different way to read counters.] -\RequirePackage{etoolbox} +\def\@cntfmts@date{2013/10/11} +\def\@cntfmts@version{v0.6} + +\ProvidesPackage{cntformats}[% + \@cntfmts@date\space + \@cntfmts@version\space + A different way to read counters. (CN)] +\RequirePackage{etoolbox,cnltx-base} % -------------------------------------------------------------------------- % message handling \def\@cntfmts@error@message{% For details have a look at the `exsheets' manual.} -\def\@cntfmts@create@message#1{% - \ifstrequal{#1}{Error} - {% - \lowercase{\csdef{@cntfmts@#1}}##1{% - \csuse{Package#1}{cntformats}{##1}{\@cntfmts@error@message}}% - }{% - \lowercase{\csdef{@cntfmts@#1}}##1{% - \csuse{Package#1}{cntformats}{##1}}% - }} -\@cntfmts@create@message{Error} -\@cntfmts@create@message{Warning} -\@cntfmts@create@message{WarningNoLine} -\@cntfmts@create@message{Info} +\cnltx@create@generic@message{@cntfmts}{cntformats}{Error}{\@cntfmts@error@message} +\cnltx@create@generic@message{@cntfmts}{cntformats}{Warning}{} +\cnltx@create@generic@message{@cntfmts}{cntformats}{WarningNoLine}{} +\cnltx@create@generic@message{@cntfmts}{cntformats}{Info}{} \def\@cntfmts@err@already@defined#1{% \@cntfmts@error{The counter `#1' already exists!}} @@ -66,91 +60,93 @@ % if you happen to read this code and notice some obvious reasons why these % macros shoudn't be used like this, please send me your improved version % (seriously! But please explain why yours is better) -\long\def\@cntfmts@ifintl#1#2{% - \def\@cntfmts@intl@tmpa##1#2{}% - \expandafter\if\expandafter\relax\expandafter - \detokenize\expandafter{\@cntfmts@intl@tmpa#1{}{}#2}\relax% - \expandafter\@secondoftwo - \else - \expandafter\@firstoftwo - \fi -} -\long\def\@cntfmts@ifintlcs#1{% - \expandafter\@cntfmts@ifintl\expandafter{#1}} - -\long\def\@cntfmts@replaceonceincs#1#2#3{% - \@cntfmts@ifintlcs#1{#2}% - {\@cntfmts@replace@once@incs#1{#2}{#3}}{}% -} -\long\def\@cntfmts@replace@once@incs#1#2#3{% - \def\@cntfmts@replo@tmpa##1#2##2\q@stop{% - \def#1{##1#3##2}}% - \expandafter\@cntfmts@replo@tmpa#1\q@stop -} - -\long\def\@cntfmts@replaceallin#1#2#3{% - \def\@cntfmts@repla@tmpa{#1}% - \@cntfmts@replaceonceincs\@cntfmts@repla@tmpa{#2}{#3}% - \@cntfmts@ifintlcs\@cntfmts@repla@tmpa{#2}% - {\expandafter\@cntfmts@replaceallin\expandafter{\@cntfmts@repla@tmpa}{#2}{#3}}% - {\expandonce\@cntfmts@repla@tmpa}% -} -\long\def\@cntfmts@replaceallincs#1#2#3{% - \@cntfmts@replaceonceincs#1{#2}{#3}% - \@cntfmts@ifintlcs#1{#2}{\@cntfmts@replaceallincs#1{#2}{#3}}{}% -} +% \long\def\@cntfmts@ifintl#1#2{% +% \def\@cntfmts@intl@tmpa##1#2{}% +% \expandafter\if\expandafter\relax\expandafter +% \detokenize\expandafter{\@cntfmts@intl@tmpa#1{}{}#2}\relax% +% \expandafter\@secondoftwo +% \else +% \expandafter\@firstoftwo +% \fi +% } +% \long\def\@cntfmts@ifintlcs#1{% +% \expandafter\@cntfmts@ifintl\expandafter{#1}} + +% \long\def\@cntfmts@replaceonceincs#1#2#3{% +% \@cntfmts@ifintlcs#1{#2}% +% {\@cntfmts@replace@once@incs#1{#2}{#3}}{}% +% } +% \long\def\@cntfmts@replace@once@incs#1#2#3{% +% \def\@cntfmts@replo@tmpa##1#2##2\q@stop{% +% \def#1{##1#3##2}}% +% \expandafter\@cntfmts@replo@tmpa#1\q@stop +% } + +% \long\def\@cntfmts@replaceallin#1#2#3{% +% \def\@cntfmts@repla@tmpa{#1}% +% \@cntfmts@replaceonceincs\@cntfmts@repla@tmpa{#2}{#3}% +% \@cntfmts@ifintlcs\@cntfmts@repla@tmpa{#2}% +% {\expandafter\@cntfmts@replaceallin\expandafter{\@cntfmts@repla@tmpa}{#2}{#3}}% +% {\expandonce\@cntfmts@repla@tmpa}% +% } +% \long\def\@cntfmts@replaceallincs#1#2#3{% +% \@cntfmts@replaceonceincs#1{#2}{#3}% +% \@cntfmts@ifintlcs#1{#2}{\@cntfmts@replaceallincs#1{#2}{#3}}{}% +% } % ---------------------------------------------------------------------------- % expansion tools % heavily inspired by expl3's \exp_args:N<spec> -- one might say: copied -\long\def\@cntfmts@getnextbraced#1#2#3{#2\@cntfmts@firstofone{#3{#1}}} -\long\def\@cntfmts@firstofone#1{#1} -\long\def\@cntfmts@braced@unexpanded#1\@cntfmts@firstofone#2#3{% - #1\@cntfmts@firstofone{#2{#3}}} -\long\def\@cntfmts@braced@expandedonce#1\@cntfmts@firstofone#2#3{% - \expandafter\@cntfmts@getnextbraced\expandafter{#3}{#1}{#2}} - -\long\def\@cntfmts@expand@first{% - \@cntfmts@braced@expandedonce - \@cntfmts@firstofone} - -\long\def\@cntfmts@expand@second{% - \@cntfmts@braced@unexpanded - \@cntfmts@braced@expandedonce - \@cntfmts@firstofone} - -\long\def\@cntfmts@expand@third{% - \@cntfmts@braced@unexpanded - \@cntfmts@braced@unexpanded - \@cntfmts@braced@expandedonce - \@cntfmts@firstofone} +% \long\def\@cntfmts@getnextbraced#1#2#3{#2\@cntfmts@firstofone{#3{#1}}} +% \long\def\@cntfmts@firstofone#1{#1} +% \long\def\@cntfmts@braced@unexpanded#1\@cntfmts@firstofone#2#3{% +% #1\@cntfmts@firstofone{#2{#3}}} +% \long\def\@cntfmts@braced@expandedonce#1\@cntfmts@firstofone#2#3{% +% \expandafter\@cntfmts@getnextbraced\expandafter{#3}{#1}{#2}} + +% \long\def\@cntfmts@expand@first{% +% \@cntfmts@braced@expandedonce +% \@cntfmts@firstofone} + +% \long\def\@cntfmts@expand@second{% +% \@cntfmts@braced@unexpanded +% \@cntfmts@braced@expandedonce +% \@cntfmts@firstofone} + +% \long\def\@cntfmts@expand@third{% +% \@cntfmts@braced@unexpanded +% \@cntfmts@braced@unexpanded +% \@cntfmts@braced@expandedonce +% \@cntfmts@firstofone} % ---------------------------------------------------------------------------- % expandable commands with optional argument (and no mandatory) % this is probably not very robust. If you know what you're doing you're -% probably able to define a better version yourself. If not, don't use it -\long\def\@cntfmts@isopt@#1[#2\q@marker#3#{% - \if\relax\detokenize{#1#2}\relax - \expandafter\@firstoftwo - \else - \expandafter\@secondoftwo - \fi} -\long\def\@cntfmts@isopt#1#2#3{% - \@cntfmts@isopt@#1\q@marker[\q@marker{#2#1}{#2[{#3}]{#1}}} - -\long\def\@cntfmts@defwopt#1[#2]#3{% - \long\def#1##1{\@cntfmts@isopt{##1}{\csuse{\@cntfmts@strip@bs#1@opt}}{#2}}% - \long\csdef{\@cntfmts@strip@bs#1@opt}[##1]{#3}} - -\def\@cntfmts@strip@bs{\expandafter\@gobble\string} +% probably able to define a better version yourself. If not: don't use this +% one! +% \long\def\@cntfmts@isopt@#1[#2\q@marker#3#{% +% \if\relax\detokenize{#1#2}\relax +% \expandafter\@firstoftwo +% \else +% \expandafter\@secondoftwo +% \fi} +% \long\def\@cntfmts@isopt#1#2#3{% +% \@cntfmts@isopt@#1\q@marker[\q@marker{#2#1}{#2[{#3}]{#1}}} + +% \long\def\@cntfmts@defwopt#1[#2]#3{% +% \long\def#1##1{\@cntfmts@isopt{##1}{\csuse{\@cntfmts@strip@bs#1@opt}}{#2}}% +% \long\csdef{\@cntfmts@strip@bs#1@opt}[##1]{#3}} + +% \def\@cntfmts@strip@bs{\expandafter\@gobble\string} % ---------------------------------------------------------------------------- % #1: module % #2: counter \def\@cntfmts@def@counter@read#1#2#3{% - \@cntfmts@expand@second\csdef + \cnltx@expandargs(no)\csdef {@#1@read@#3@counter}% - {\csname @#1@read@#2@counter\endcsname}} + {\csname @#1@read@#2@counter\endcsname}% +} % create pattern for an existing counter: % #1: module @@ -168,13 +164,14 @@ \newcommand*\@cntfmts@add@counter@pattern@nostar[3][cntfmts]{% \@cntfmts@add@counter@pattern[#1]{#2}{#3}% - \@cntfmts@expand@third - \@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}} + \cnltx@expandargs(nno)\@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}% +} \newrobustcmd*\AddCounterPattern{% \@ifstar {\@cntfmts@add@counter@pattern} - {\@cntfmts@add@counter@pattern@nostar}} + {\@cntfmts@add@counter@pattern@nostar}% +} \@onlypreamble\AddCounterPattern % create pattern for a new counter @@ -191,13 +188,14 @@ \newcommand*\@cntfmts@new@counter@pattern@nostar[3][cntfmts]{% \@cntfmts@new@counter@pattern[#1]{#2}{#3}% - \@cntfmts@expand@third - \@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}} + \cnltx@expandargs(nno)\@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}% +} \newrobustcmd*\NewCounterPattern{% \@ifstar {\@cntfmts@new@counter@pattern} - {\@cntfmts@new@counter@pattern@nostar}} + {\@cntfmts@new@counter@pattern@nostar}% +} \@onlypreamble\NewCounterPattern % renew pattern: @@ -213,13 +211,14 @@ \newcommand*\@cntfmts@renew@counter@pattern@nostar[3][cntfmts]{% \@cntfmts@renew@counter@pattern[#1]{#2}{#3}% - \@cntfmts@expand@third - \@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}} + \cnltx@expandargs(nno)\@cntfmts@create@read@counter{#1}{#2}{\csname c@#2\endcsname}% +} \newrobustcmd\RenewCounterPattern{% \@ifstar {\@cntfmts@renew@counter@pattern} - {\@cntfmts@renew@counter@pattern@nostar}} + {\@cntfmts@renew@counter@pattern@nostar}% +} \@onlypreamble\RenewCounterPattern % ---------------------------------------------------------------------------- @@ -230,7 +229,8 @@ % #2: counter % #3: internal command \def\@cntfmts@create@read@counter#1#2#3{% - \expandafter\@cntfmts@defwopt\csname @#1@read@#2@counter\endcsname[]{% + \expandafter\newexpandablecmd + \expandafter*\csname @#1@read@#2@counter\endcsname[1][]{% \ifblank{##1} {\@arabic{#3}} {\csuse{@cntfmts@counter@type@##1}{#3}}% @@ -238,17 +238,20 @@ } \newrobustcmd*\ReadCounterFrom[3][cntfmts]{% - \@cntfmts@create@read@counter{#1}{#2}{#3}} + \@cntfmts@create@read@counter{#1}{#2}{#3}% +} % ---------------------------------------------------------------------------- % pattern formats % #1: key % #2: number presentation command like \@alph \def\@cntfmts@new@pattern@format#1#2{% - \csdef{@cntfmts@counter@type@#1}{#2}} + \csdef{@cntfmts@counter@type@#1}{#2}% +} \newrobustcmd*\NewPatternFormat[2]{% - \@cntfmts@new@pattern@format{#1}{#2}} + \@cntfmts@new@pattern@format{#1}{#2}% +} \@onlypreamble\NewPatternFormat % ---------------------------------------------------------------------------- @@ -257,21 +260,24 @@ % #2: list % #3: pattern \def\@cntfmts@read@counter@pattern#1#2#3{% - \def\@cntfmts@parsed@pattern{#3\relax}% + \def\@cntfmts@parsed@pattern{#3\@empty}% \forlistcsloop{\@cntfmts@replace@pattern{#1}}{#2}% } % #1: module % #2: pattern-key \def\@cntfmts@replace@pattern#1#2{% - \@cntfmts@replaceallincs\@cntfmts@parsed@pattern - {#2}{{}\csuse{@#1@read@#2@counter}}} + \cnltx@replace@all\@cntfmts@parsed@pattern + {#2}{\csuse{@#1@read@#2@counter}}% +} \newrobustcmd*\ReadCounterPattern[2][cntfmts]{% - \@cntfmts@read@counter@pattern{#1}{@#1@counter@ids}{#2}\@cntfmts@parsed@pattern} + \@cntfmts@read@counter@pattern{#1}{@#1@counter@ids}{#2}\@cntfmts@parsed@pattern +} \newrobustcmd*\ReadCounterPatternFrom[2][cntfmts]{% - \@cntfmts@expand@third\@cntfmts@read@counter@pattern{#1}{@#1@counter@ids}{#2}% - \@cntfmts@parsed@pattern} + \cnltx@expandargs(nno)\@cntfmts@read@counter@pattern{#1}{@#1@counter@ids}{#2}% + \@cntfmts@parsed@pattern +} % #1: save pattern in % #2: save interpretation in @@ -290,16 +296,20 @@ } \newrobustcmd*\SaveCounterPattern[4][cntfmts]{% - \@cntfmts@save@counter@pattern{#2}{#3}{#4}{#1}} + \@cntfmts@save@counter@pattern{#2}{#3}{#4}{#1}% +} \newrobustcmd*\SaveCounterPatternFrom[4][cntfmts]{% - \@cntfmts@expand@third\@cntfmts@save@counter@pattern{#2}{#3}{#4}{#1}} + \cnltx@expandargs(nno)\@cntfmts@save@counter@pattern{#2}{#3}{#4}{#1}% +} \newrobustcmd*\eSaveCounterPattern[4][cntfmts]{% - \@cntfmts@esave@counter@pattern{#2}{#3}{#4}{#1}} + \@cntfmts@esave@counter@pattern{#2}{#3}{#4}{#1}% +} \newrobustcmd*\eSaveCounterPatternFrom[4][cntfmts]{% - \@cntfmts@expand@third\@cntfmts@esave@counter@pattern{#2}{#3}{#4}{#1}} + \cnltx@expandargs(nno)\@cntfmts@esave@counter@pattern{#2}{#3}{#4}{#1}% +} % ---------------------------------------------------------------------------- % predefined formats and pattern @@ -333,4 +343,7 @@ from \the<ounter> to \c@<ounter> - rename tokenlist test macros to use cntformats' namespace -
\ No newline at end of file +2013/10/11 v0.6 - use my `cnltx-base' package for the programming tools it + provides; this allows to get rid of the artefacts in the + expanded patterns + |