From 8c3ddd9a73576bcd8c7c63e5452b5b6fdbac670a Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sun, 7 Mar 2010 00:06:53 +0000 Subject: gmutils 0.991 update (5mar10) git-svn-id: svn://tug.org/texlive/trunk@17343 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/latex/gmutils/gmutils.sty | 5932 +++++++++++++++++------ 1 file changed, 4381 insertions(+), 1551 deletions(-) (limited to 'Master/texmf-dist/tex/latex/gmutils') diff --git a/Master/texmf-dist/tex/latex/gmutils/gmutils.sty b/Master/texmf-dist/tex/latex/gmutils/gmutils.sty index 721b87c4bdf..745e0f86f03 100644 --- a/Master/texmf-dist/tex/latex/gmutils/gmutils.sty +++ b/Master/texmf-dist/tex/latex/gmutils/gmutils.sty @@ -11,12 +11,12 @@ %%Written by Grzegorz Murzynowski, %% natror at o2 dot pl %% -%% \copyright\,2005–2008 by Grzegorz Murzynowski. +%% \copyright\,2005, 2006, 2007, 2008, 2009, 2010 by Grzegorz Murzynowski. %% %% This program is subject to the \LaTeX\ Project Public License. %% See ^^A %% \url{http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html} ^^A -%% for the details of that license. +%% for the details of that license.\rrthis %% %% LPPL status: "author-maintained".\par %% @@ -28,6 +28,7 @@ %% % \RecordChanges % \ChangesStart{}{1000/00/0} +% % \chschange{v0.59}{06/09/04}{396} % \chschange{v0.61}{06/09/06}{432} % \chschange{v0.62}{06/9/7}{444} @@ -56,16 +57,33 @@ % \chschange{v0.94}{2008/10/4}{4880} % \chschange{v0.95}{2008/10/8}{4908} % \chschange{v0.96}{2008/11/21}{5363} -% \toCTAN{v0.96}{2008/11/21} +% \toCTAN{2008/11/21 v0.96} % \chschange{v0.97}{2008/11/22}{5375} -% \toCTAN{v0.97}{2008/11/22} -% +% \toCTAN{2008/11/22 v0.97} +% \chschange{v0.98}{2008/11/30}{5429} +% \chschange{v0.98}{2008/12/5}{5577}[\cs{DeclareCommand}] +% \chschange{v0.98}{2008/12/5}{5627}[\cs{fakeonum}] +% \chschange{v0.98}{2008/12/9}{6035}[\cs{DeclareCommand}, \cmd\arg] +% \chschange{v0.98}{2008/12/10}{6129} +% [\cmd\DeclareEnvironment] +% \chschange{v0.98}{2008/12/10}{6147} +% [\cmd\arg\ in verbatims] +% \chschange{v0.98}{2008/12/12}{6535} +% [\cmd\UrlFix] +% \chschange{v0.98}{2008/12/14}{6656} +% [type settings for \pk{gmdoc} (\cmd\narrativett) and for +% \cmd\verbatimspecials] +% \chschange{v0.991}{2010/3/4}{8257} +% [some shorthands and major development of \cmd\DeclareCommand, +% including ‘Knuthian’ and general optional arguments and +% ‘\cmd\afterassignment’ pseudo-argument] +% \toCTAN{2010/03/04 v0.991} % % \skiplines we skip the driver \ifnum\catcode`\@=12 \documentclass[debug, countalllines, codespacesgrey, outeroff, -pagella, fontspec=quiet]{gmdocc} +pagella, trebuchet, cursor, fontspec=quiet]{gmdocc} \usepackage{eufrak}% for |\continuum| in the commentary. \twocoltoc \begin{document} @@ -87,7 +105,7 @@ pagella, fontspec=quiet]{gmdocc} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{gmutils} - [2008/11/22 v0.97 some rather TeXnical macros, some of them tricky (GM)] + [2010/03/04 v0.991 some rather TeXnical macros, some of them tricky (GM)] % % \tableofcontents @@ -161,7 +179,7 @@ pagella, fontspec=quiet]{gmdocc} % \ifx\XeTeXversion\relax \let\XeTeXversion\@undefined% If someone earlier used -% \inverb|\@ifundefined{XeTeXversion}| to test +% \nlperc|\@ifundefined{XeTeXversion}| to test % whether the engine is \XeTeX, then \incs{XeTeXversion} \emph{is} defined % in the sense of \eTeX\ tests. In that case we |\let| it to something % really undefined. Well, we might keep sticking to \incs{@ifundefined}, @@ -174,14 +192,49 @@ pagella, fontspec=quiet]{gmdocc} \fi% and if we are not in \XeTeX, we skip them thanks to \XeTeX-test. + %^^A % \division{Ignoring spaces and line ends in packages and classes} + %^^A % + %^^A % Spurious spaces and line ends that convert to spaces are a~plague + %^^A % for the package writers including me. On the other hand, changing + %^^A % catcodes is dangerous and should be done with care. Therefore + %^^A % I~provide a~declaration that reverts its effect at most at the end + %^^A % of a~package or class. + %^^A + %^^A \def\package@ignorespaces{% + %^^A \catcode`\ =9 + %^^A \endlinechar-1 + %^^A \AtEndOfPackage{\package@restorespace}} + %^^A + %^^A \def\package@restorespace{\catcode`\ =10 \endlinechar13 } + %^^A + +% \division{Options} + +\newif\ifgmu@quiet + +\DeclareOption{quiet}{\gmu@quiettrue} + +\ProcessOptions + % % \division{A~couple of abbreviations} % {\DoIndex{\@nx \@xa} \Define\@xa \Define\@nx \let\@xa\expandafter \let\@nx\noexpand -\def\@xau{\@xa\unexpanded\@xa} +\def\@xau#1{\unexpanded\@xa{#1}} %\changes{v0.94}{2008/10/4}{added} +% \nostanza Note that there's only one |\expandafter|, after +% |\unexpanded|. It's because |\unexpanded| expands expandable tokens +% and gobbles |\relax|es while looking for an opening brace or |\bgroup|. +% Note also that it \emph{requires} a text in braces. +% +% \chgs{2010/03/04 v0.991 made 1-parameter} +% Note also that (since v0.991) this is a 1-parameter macro so doesn't +% expand subsequent tokens until meets a \ but just +% takes first single token or \. + + %} \HideDefining*\pdef \def\pdef{\protected\def} @@ -229,6 +282,12 @@ pagella, fontspec=quiet]{gmdocc} \long\def\@nameedef#1#2{% \changes{v0.93}{2008/08/30}{added} \@xa\edef\csname#1\endcsname{#2}} +% \division{\cs{if}s as a~four-argument \LaTeX\ command robust to unbalanced \cs{if}s and \cs{fi}s} + +\long\def\gmu@if#1#2{% + \csname if#1\endcsname#2\@xa\@firstoftwo\else\@xa\@secondoftwo\fi +} + % \division{\cs{firstofone} and the queer \cs{catcode}s} % % Remember that once a~macro's argument has been read, its @@ -240,16 +299,165 @@ pagella, fontspec=quiet]{gmdocc} % \long\def\firstofone#1{#1} +% ^^A \long\def\bracethis#1{{#1}} +% ^^A \long\def\fooscant{\@xa\scantokens\bracethis} +\long\pdef\scantwo#1#2{ + \begingroup\endlinechar\m@ne + \@xa\endgroup\scantokens{#1#2}% +} + +\long\def\@firstofthree#1#2#3{#1} +\long\def\@secondofthree#1#2#3{#2} +\long\def\@thirdofthree#1#2#3{#3} +\long\def\@secondoffive#1#2#3#4#5{#2} + +% In some |\if›[cat›?›]|\ test I~needed to look only at the first token of +% a~tokens' string (first letter of a~word usually) and to +% drop the rest of it. So I~define a~macro that expands +% to the first token (or \arg{text}) of its argument. +% +\long\def\@firstofmany#1#2\@@nil{#1} +% \changes{v0.63}{06/9/9}{added} + +\long\def\@allbutfirstof#1#2\@@nil{#2} +% \changes{v0.97}{2008/11/22}{added} +% \changes{v0.98}{2008/11/22}{renamed from \cs{@secondofmany}} + + +% \division{\cs{afterfi} and pals} + +% It happens from time to time that you have some sequence of macros +% in an |\if…| and you would like to expand |\fi| before expanding +% them (e.g., when the macros should take some tokens next to |\fi…| +% as their arguments. If you know how many macros are there, you may +% type a~couple of |\expandafter|s and not to care how terrible it +% looks. But if you don't know how many tokens will there be, you +% seem to be in a~real trouble. There's the Knuthian trick with +% |\next|. And here another, revealed to me by my \TeX\ Guru. +% +% I~think the situations when the Knuthian (the former) trick is not +% available are rather seldom, but they are imaginable at least: the +% |\next| trick involves an assignment so it won't work e.g.\ in +% |\edef|. +% +% But |\afterfi| and pals are sensitive to |\fi|s that may occur in +% macros' arguments so probably the safest and expandable way is the +% |\expandafter\@›(first⁄|second›)oftwo| trick. %^^A| +%^^A % One warning: those macros peel the braces off, i.e., +%^^A % \[|\if..\afterfi{\@makeother\^^M}\fi|\] +%^^A % causes a~leakage of +%^^A % |^^M|\catother. To avoid pollution write +%^^A % \[|\if..\afterfi{\bgroup\@makeother\^^M\egroup}\fi|\,.\] +% + +\def\longafterfi{% + \long\def\afterfi##1##2\fi{\fi##1}} +\longafterfi +% And two more of that family: +\long\def\afterfifi#1#2\fi#3\fi{\fi\fi#1} +% \changes{v0.94}{2008/09/09}{\cs{if} removed from parameters' string} +\long\def\afteriffifi#1#2\fi#3\fi{\fi#1} +% Notice the refined elegance of those macros, that cover both `then' +% and `else' cases thanks to |#2| that is discarded. + +\long\def\afterififfififi#1#2\fi#3\fi#4\fi{\fi#1} +\long\def\afteriffififi#1#2\fi#3\fi#4\fi{\fi\fi#1} +\long\def\afterfififi#1#2\fi#3\fi#4\fi{\fi\fi\fi#1} + +% \division{\cs{foone}} + % The next command, |\foone|, is intended as two-argument for -% shortening of the |\begingroup...\firstofone{\endgroup...}| hack. +% shortening of the |\begingroup…\firstofone{\endgroup…}| hack. % -\long\def\foone#1{\begingroup#1\egfirstofone} +\long\def\foone#1{\begingroup#1\relax\egfirstofone} % \UnDef \long\def\egfirstofone#1{\endgroup#1} -\long\def\fooatletter{\foone\makeatletter} +\def\fooatletter{\foone\makeatletter} + +% \division{\cs{@ifempty}, \cs{IfAmong}, \cmd\IfIntersect\ \cs{@ifinmeaning}} +% After a~short deliberation I~make the \cmd\IfAmong…\cmd\among\ and +% \cmd\IfIntersect\ macros' names apeless since they are intended for +% the macro and class writers, at the same level of abstraction as +% \cmd\DeclareCommand. +% +\long\pdef\@ifempty#1{%\ + % \begin{enumargs} + % \item the token(s) we test, it may be just |{}|, + % \item the stuff executed if |#1| is empty (is |{}|), + % \item the stuff executed if |#1| consists of at least one token. + % \end{enumargs} + \def\gmu@reserveda{#1}% + \ifx\gmu@reserveda\@empty\@xa\@firstoftwo + \else\@xa\@secondoftwo + \fi} + +\long\def\@ifnonempty#1#2#3{\@ifempty{#1}{#3}{#2}} + +\long\pdef\IfAmong#1\among#2{%\label{IfAmong}\ + % \begin{enumargs} + % \item the token(s) whose presence we check, + % \item the list of tokens in which we search |#1|, + % \item the ‘if found’ stuff, + % \item the ‘if not found’ stuff. + % \end{enumargs} + % \chgs{2008/12/05 v0.98 split from \cs{IfAmong}} + % + \long\def\gmu@among@##1#1##2\gmu@among@{% + \@ifempty{##2}\@secondoftwo\@firstoftwo}% + \gmu@among@#2#1\gmu@among@} + +\long\def\IfIntersect#1#2{% this (not expandable) macro checks\ + % whether the list of tokens \inverb|#1| and \inverb|#2| have\ + % nonempty intersection and if so executes \incs{@firstoftwo} or\ + % else \incs{@secondoftwo}, so it's a~4-argument command:\ + % \begin{enumargs} + % \item first list to match, + % \item second list to match, + % \item if match (nonempty intersection), + % \item if not match (empty intersection). + % \end{enumargs} + \let\IfIntersect@next\@secondoftwo + \gmu@foreach#1\gmu@foreach{% + \@xa\IfAmong\gmu@forarg\among{#2} + {\let\IfIntersect@next\@firstoftwo}{}}% + \IfIntersect@next} + +% We need a~macro that iterates over every token on a~list. \LaTeX's +% |\@for| iterates over a~list separated with commas so it's not the +% case. Our macro is much simpler. +\long\def\gmu@foreach#1\gmu@foreach#2{% + \long\def\gmu@forer##1{% + \ifx\gmu@foreach##1\else + \long\def\gmu@forarg{##1}% + #2% + \@xa\gmu@forer + \fi}% + \gmu@forer#1\gmu@foreach} + + + +\long\pdef\@ifinmeaning#1\of#2{% \ + % \begin{enumargs} + % \item the token(s) whose presence we check, + % \item the macro in whose meaning we search |#1| (the first token of + % this argument is expanded one level with |\expandafter|), + % \item the `if found' stuff, + % \item the `if not found' stuff. + % \end{enumargs} + % + % \chgs{2007/11/06 v0.98 (in \pk{gmdoc}) made more elegant: + % \cs{if} changed to \cs{ifx} made four parameters and not expanding + % to an open \cs{if›(true⁄|false›)}. Also renamed from \cs{@ifismember}} + % \chgs{2008/12/05 v0.98 moved here from \pk{gmdoc} and rewritten, + % including split to \cs{IfAmong} because the latter is needed in + % \cs{DeclareCommand}} + % + \def\gmu@reserveda{\IfAmong#1\among}% + \@xa\gmu@reserveda\@xa{#2}} + % \division{Global Boolean switches} % @@ -305,10 +513,10 @@ pagella, fontspec=quiet]{gmdocc} % Note the letter $g$ added to underline globalness of the assignment. % % If for any reason, no matter how queer ;-) may it be, you need -% \emph{both} global and local switchers of your |\if...|, declare +% \emph{both} global and local switchers of your |\if…|, declare % it both with |\newif| and |\newgif|. % -% Note that it's just a~shorthand. |\global\if|\|true/false| +% Note that it's just a~shorthand. |\global\if⁄›(true⁄|false›)| % \emph{does} work as expected. % \Define\grefstepcounter @@ -323,7 +531,7 @@ pagella, fontspec=quiet]{gmdocc} {\let\protected@edef=\protected@xdef\refstepcounter{#1}}} % Na\"\i{}ve first try |\globaldefs=\tw@| raised an error % |unknown command \reserved@e|. The matter was to globalize -% |\protected@edef| of |\@currentlabel|. +% |\protected@edef| of |\@currentlabel|.\rrthis % % Thanks to using the true |\refstepcounter| inside, it observes the % change made to |\refstepcounter| by \pk{hyperref}. @@ -364,11 +572,14 @@ pagella, fontspec=quiet]{gmdocc} % The redefining of the first argument of the above macro(s) is % |\global|. What if we want it local? Here we are: -% \Define\addto@macro +% \long\def\addto@macro#1#2{% - \toks@\@xa{#1#2}% - \edef#1{\the\toks@}% -}%(|\toks@| is a~scratch register, namely |\toks0|.) + % \chgs{2008/12/7 v0.98 \cs{toks@} replaced with some + % \cmd\expandafter s because use of \cs{toks@} here caused + % a~disaster in \cs{DeclareCommand}} + \edef#1{\@xa\unexpanded\@xa{#1}\unexpanded{#2}}% \incmd\edef\ and + % \incmd\unexpanded\ to double the hashes. +} % And for use in the very document, % \Define\addtomacro @@ -407,7 +618,7 @@ pagella, fontspec=quiet]{gmdocc} % I~define it under another name not redefine |\@ifundefined| because % I~can imagine an odd case when something works thanks to -% |\@ifundefined|'s `relaxation effect'. +% |\@ifundefined|'s `relaxation’ effect. \long\def\gm@ifundefined#1{% not |\protected| because expandable. % \changes{v0.94}{2008/9/12}{added. All \cs{@ifundefined}s used by @@ -415,21 +626,22 @@ pagella, fontspec=quiet]{gmdocc} % \changes{v0.94}{2008/10/03}{made robust to unbalanced \cs{if}s and % \cs{fi}s the same way as \LaTeX's \cs{@ifundefined} (after a~heavy % debug :-)} - \ifcsname#1\endcsname% defined - \@xa\ifx\csname #1\endcsname\relax% but as |\relax| + \ifcsname#1\endcsname% defined… + \@xa\ifx\csname #1\endcsname\relax% but only as |\relax|---then + % 2nd argument. \afterfifi\@firstoftwo% - \else% defined and not |\relax| + \else% defined and not |\relax|---then 3rd argument. \afterfifi\@secondoftwo% \fi - \else% not defined + \else% not defined---then 3rd. \afterfi\@firstoftwo% \fi} \long\def\gm@testdefined#1\iftrue{% This is a~macro that expands to - % \incs{iftrue} or \incs{iffalse} depending on whether it's argument + % \incs{iftrue} or \incs{iffalse} depending on whether its argument % is defined in the \LaTeX\ sense. Its syntax requires an - % \incs{iftrue} to balance \incs{if}s with \incs{fi}s. + % \incs{iftrue} to force balancing \incs{if}s with \incs{fi}s. % \changes{v0.95}{2008/10/8}{added} \csname \ifdefined#1% @@ -447,570 +659,1965 @@ pagella, fontspec=quiet]{gmdocc} \@xa\@xa\@xa\unless\gm@testdefined#1\iftrue} -% \subdivision{Storing and restoring the catcodes of specials} - -\newcommand*\gmu@storespecials[1][]{% we provide a~possibility of - % adding stuff. For usage see line \ref{@storespecials}. - \def\do##1{\catcode`\@nx##1=\the\catcode`##1\relax}% - \edef\gmu@restorespecials{\dospecials\do\^^M#1}} - -\pdef\gmu@septify{% restoring the standard catcodes of specials. The - % name is the opposite of `sanitize' ^^A( - % :-)\,. It restores also the original catcode of \inverb|^^M| - \def\do{\relax\catcode`}% - \do\ 10\do\\0\do\{1\do\}2\do\$3\do\&4% - \do\#6\do\^7\do\_8\do\%14\do\~13\do\^^M5\relax} - - - %\division{From the ancient \pk{xparse} of \TeX Live 2007} - % The code of this section is rewritten contents of the \pk{xparse} - % package version 0.17 dated 1999/09/10, the version available in \TeX - % Live 2007-13, in Ubuntu packages at least. It's a~stub `im Erwartung' - % (Schönberg) for the \LaTeX 3 bundle and it does what I~want, namely - % defines |\DeclareDocumentCommand|. I~rewrote the code to use the usual - % catcodes (only with |@| a~letter) and not to use the \pk{ldcsetup} - % package (which caused an error of - % undefined \CS |\KV@def|). - % - % Well, I~add the |\protected| prefix to the first macro. -% -% After exchange of some mails with Morten H\o{}gholm and trying -% \pk{xparse} of 2008/08/03 svn 748 (which beautifully spoils the -% catcodes) I~wrap the -% ancient code in a~conditional to avoid name collision if someone -% loads \pk{xparse} before \pk{gmutils} -\gm@testundefined\DeclareDocumentCommand\iftrue - -\unless\ifdefined\@temptokenb -\newtoks\@temptokenb -\fi -\newtoks\xparsed@args +% \division{Some `other' and active stuff} +% Here I~define a~couple of macros expanding to special chars made +% `other'. It's important the \CS are expandable and therefore +% they can occur e.g. inside |\csname›…\endcsname| unlike e.g.\ +% \CS'es |\chardef|ed. +% +% \Define\subs +\foone{\catcode`\_=8 } +{\let\subs=_} -\long\def\DeclareDocumentCommand#1#2#3{%\ - % \begin{enumargs} - % \item command to be defined, - % \item arguments specification, - % \item definition body. - % \end{enumargs} - \@tempcnta\z@ - \toks@{}% - \@temptokena\toks@ - \@temptokenb\toks@ - \@ddc#2X% |X| is the guardian of parsing. - \protected\edef#1{% The |\protected| prefix is my (GM) addition. - \@nx\@ddc@ - {\the\toks@}% - \@xa\@nx\csname\string#1\endcsname - \@nx#1% - }% - \long\@xa\def\csname\string#1\@xa\endcsname - \the\@temptokena{#3}} +% \Define\sups +\foone{\catcode`\^=7 } +{\let\sups=^} -\long\def\DeclareDocumentEnvironment#1#2#3#4{% - \@xa\DeclareDocumentCommand\csname#1\endcsname{#2}{% - \xparsed@args\toks@ - #3}% - \@xa\let\csname end#1\endcsname\@parsed@endenv - \long\@xa\def\csname end\string\\#1\@xa\endcsname - \the\@temptokena{#4}} +\foone{\@makeother\_} +{\def\xiiunder{_}} -\def\@parsed@endenv{% - \@xa\@parsed@endenv@\the\xparsed@args} +\let\all@unders\xiiunder +\foone{\catcode`\_=8 } +{\addtomacro\all@unders{_}} +\foone{\catcode`\_=11 } +{\addtomacro\all@unders{_}} +\foone{\catcode`\_=13 } +{\addtomacro\all@unders{_}} +% \nostanza Now |\all@unders| bears underscores of categories 8, 11, +% 12 and 13. -\def\@parsed@endenv@#1{% - \csname end\string#1\endcsname} +\def\all@stars{*} +\foone{\catcode`\*=11 } +{\addtomacro\all@stars{*}} +\foone{\catcode`\*=13 } +{\addtomacro\all@stars{*}} +%\nostanza And |\all@stars| bears stars of categories 11, 12 and 13. -\def\@ddc@#1#2#3{% - \ifx\protect\@typeset@protect - \@xa\@firstofone - \else - \protect#3\@xa\@gobble - \fi - {\toks@{#2}#1\the\toks@}} -\def\@ddc#1{% - \ifx#1X% - \else - \ifx#1m% - \addto@hook\@temptokenb m% - \else - \toks@\@xa{% - \the\@xa\toks@ - \csname @ddc@\the\@temptokenb\@xa\endcsname - \csname @ddc@#1\endcsname}% - \@temptokenb{}% - \fi - \advance\@tempcnta\@ne - \@temptokena\@xa{% - \the\@xa\@temptokena\@xa##\the\@tempcnta}% - \@xa - \@ddc - \fi} +\ifdefined\XeTeXversion + \chardef\_="005F +\fi -\long\def\@ddc@s#1\toks@{% - \@ifstar - {\addto@hook\toks@\BooleanTrue#1\toks@}% - {\addto@hook\toks@\BooleanFalse#1\toks@}} +\foone{\@makeother\`}% +{\def\backquote{`}} -\long\def\@ddc@m#1\toks@#2{% - \addto@hook\toks@{{#2}}#1\toks@}% -\long\def\@ddc@o#1\toks@{% - \@ifnextchar[%^^A] - {\@ddc@o@{#1}} - {\addto@hook\toks@\NoValue#1\toks@}} +\foone{\catcode`\[=1 \@makeother\{ + \catcode`\]=2 \@makeother\}}% +[% + \def\xiilbrace[{]% + \def\xiirbrace[}]% +]% of |\firstofone| -\long\def\@ddc@o@#1[#2]{% - \addto@hook\toks@{{#2}}#1\toks@} +% Note that \LaTeX's |\@charlb| and |\@charrb| are of catcode 11 +% (`letter'), cf. The \LaTeXe\ Source file k, lines 129--130. -\def\@ddc#1{% - \ifx#1X% - \perhaps@grab@ms - \else - \ifx#1m% - \addto@hook\@temptokenb m% - \else - \toks@\@xa{% - \the\@xa\toks@ - \csname @ddc@x\the\@temptokenb\@xa\endcsname - \csname @ddc@#1\endcsname}% - \@temptokenb{}% - \ifx#1O% - \let\next@ddc\grab@default - \else - \ifx#1C% - \let\next@ddc\grab@default - \fi - \fi - \fi - \advance\@tempcnta\@ne - \@temptokena\@xa{% - \the\@xa\@temptokena\@xa##\the\@tempcnta}% - \@xa - \next@ddc - \fi -}% -\let\next@ddc\@ddc -\def\grab@default#1{% - \toks@\@xa{% - \the\toks@ - {#1}}% - \let\next@ddc\@ddc - \@ddc -} -\long\def\@ddc@O#1#2\toks@{% - \@ifnextchar[%^^A] - {\@ddc@o@{#2}}% - {\addto@hook\toks@{{#1}}#2\toks@}} +% Now, let's define such a~smart |_| (underscore) which will be usual +% |_|${}_8$ in the math mode and |_|\catother\ (`other') outside math. +% \Define\smartunder +% \changes{v0.60}{06/09/05}{\cs{\_} instead of \cs{xiiunder}} +\foone{\catcode`\_=\active} +{% + \newcommand*\smartunder{% + \catcode`\_=\active + \def_{\ifmmode\subs\else\_\fi}}}% We define it as \inverb|\_| not just as +% \inverb|\xiiunder| because some font encodings don't have \inverb|_| at the +% \inverb|\char`\_| position. +% +% \CodeEscapeChar\! +% \Define\bslash \Define\xiibackslash +\foone{\catcode`\!=0 + \@makeother\\} +{!newcommand*!xiibackslash{\}} +%^^A] balancing braces for Emacs +% \CodeEscapeChar\\ -\long\def\@ddc@c#1\toks@{% - \@ifnextchar(%^^A) - {\@ddc@c@#1}% - {\PackageError{gmutils/xparse}{Missing~coordinate~argument}% - {A~value~of~(0,0)~is~assumed}% - \addto@hook\toks@{{00}}#1\toks@}% -} +\let\bslash=\xiibackslash -\long\def\@ddc@c@#1(#2,#3){% - \addto@hook\toks@{{{#2}{#3}}}#1\toks@} -\long\def\@ddc@C#1#2\toks@{% - \@ifnextchar(%^^A) - {\@ddc@c@#2}% - {\addto@hook\toks@{{#1}}#2\toks@}} - -\let\perhaps@grab@ms\relax -\def\grab@ms{% - \toks@\@xa{% - \the\@xa\toks@ - \csname @ddc@x\the\@temptokenb\endcsname - }} +% \begin{oldmc} +\foone{\@makeother\%} +{\def\xiipercent{%}} +% \end{oldmc} -\let\@ddc@m\undefined +\foone{\@makeother\&}% +{\def\xiiand{&}} -\long\def\@ddc@xm#1\toks@#2{% - \addto@hook\toks@{{#2}}#1\toks@} +\foone{\@makeother\ }% +{\def\xiispace{ }} -\long\def\@ddc@xmm#1\toks@#2#3{% - \addto@hook\toks@{{#2}{#3}}#1\toks@} +\foone{\@makeother\#}% +{\def\xiihash{#}} -\long\def\@ddc@xmmm#1\toks@#2#3#4{% - \addto@hook\toks@{{#2}{#3}{#4}}#1\toks@} +% We introduce \cs{visiblespace} from Will Robertson's \pk{xltxtra} if +% available. It's not sufficient |\@ifpackageloaded{xltxtra}| since +% \cs{xxt@visiblespace} is defined only unless |no-verb| option is +% set. 2008/08/06 I~recognised the difference between \cs{xiispace} +% which has to be plain `other' char (used in \cs{xiistring}) and +% something visible to be printed in any font. -\long\def\@ddc@xmmmm#1\toks@#2#3#4#5{% - \addto@hook\toks@{{#2}{#3}{#4}{#5}}#1\toks@} +\AtBeginDocument{% + \ifdefined\xxt@visiblespace + \let\visiblespace\xxt@visiblespace + \def\xxt@visiblespace@fallback{{% + \fontspec{Latin Modern Mono}\textvisiblespace}}% + \else + \let\visiblespace\xiispace + \fi} -\long\def\@ddc@xmmmmm#1\toks@#2#3#4#5#6{% - \addto@hook\toks@{{#2}{#3}{#4}{#5}{#6}}#1\toks@} -\long\def\@ddc@xmmmmmm#1\toks@#2#3#4#5#6#7{% - \addto@hook\toks@{{#2}{#3}{#4}{#5}{#6}{#7}}#1\toks@} +\foone\obeyspaces{\def\gmu@activespace{ }} -\long\def\@ddc@xmmmmmmm#1\toks@#2#3#4#5#6#7#8{% - \addto@hook\toks@{{#2}{#3}{#4}{#5}{#6}{#7}{#8}}#1\toks@} +\foone\obeylines{\def\activeM{^^M}} -\long\def\@ddc@xmmmmmmmm#1\toks@#2#3#4#5#6#7#8#9{% - \addto@hook\toks@{{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}#1\toks@} -\long\def\@ddc@xmmmmmmmmm\the\toks@#1#2#3#4#5#6#7#8#9{% - \addto@hook\toks@{{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}\the\toks@} +% \division{\cs{@ifnextcat}, \cs{@ifnextac}, catcode-independent\ +% \cs{gm@ifstar}, \cs{@ifnextsingle}, \cs{@ifnextgroup}} +% +% As you guess, we |\def| |\@ifnextcat| \agrave~la |\@ifnextchar|, see +% \LaTeXe\ source dated 2003/12/01, file d, lines 253--271. The +% difference is in the kind of test used: while |\@ifnextchar| does +% |\ifx|, |\@ifnextcat| does |\ifcat| which means it looks not at the +% meaning of a~token(s) but at their |\catcode|(s). As you (should) +% remember from \TeXbook, the former test doesn't expand macros while +% the latter does. But in |\@ifnextcat| the peeked token is protected +% against expanding by |\noexpand|. Note that the first parameter is +% not protected and therefore it shall be expanded if it's +% expandable. Because an assignment is involved, you can't test +% whether the next token is an active char. But you can test if the +% next token is |{|$_1$ or |}|$_2$: |\@ifnextcat\bgroup›…|, +% |\@ifnextcat\egroup›…|. -\let\@ddc@x\relax +\long\pdef\@ifnextcat#1#2#3{% +% \changes{v0.75}{2007/01/01}{\cs{let} for \cs[\#]1 changed to +% \cs{def} to allow things like \cs{noexpand\texttilde}} +% \HideDef + \def\reserved@d{#1}% + \def\reserved@a{#2}% + \def\reserved@b{#3}% + \futurelet\@let@token\@ifncat} -\long\def\DeclareDocumentEnvironment#1#2#3#4{% - \@xa\DeclareDocumentCommand\csname#1\endcsname{#2}{% - #3}% - \@namedef{end#1}{#4}% -} -\let\@parsed@endenv\undefined -\let\@parsed@endenv@\undefined -\def\IfSomethingTF#1{\def\something@in{#1}\If@SomethingTF} -\def\IfSomethingT#1#2#3{\def\something@in{#1}% - \If@SomethingTF{#2}{#3}\@empty} - -\def\IfSomethingF#1#2#3{\def\something@in{#1}% - \If@SomethingTF{#2}\@empty{#3}} - -\def\If@SomethingTF#1{% - \def\something@tmp{#1}% - \ifx\something@tmp\something@in - \@xa\@secondofthree - \else - \@xa\def\@xa\something@tmpb\@xa{#1}% - \ifx\something@tmp\something@tmpb - \@xa\@xa\@xa\@thirdofthree +% \ResumeDef +\def\@ifncat{% + \ifx\@let@token\@sptoken + \let\reserved@c\@xifncat \else - \@xa\@xa\@xa\@firstofone - \fi + \ifcat\reserved@d\@nx\@let@token + \let\reserved@c\reserved@a + \else + \let\reserved@c\reserved@b + \fi \fi - {\@xa\If@SomethingTF\@xa{#1}}% -} + \reserved@c} -\long\def\@secondofthree#1#2#3{#2} -\long\def\@thirdofthree#1#2#3{#3} -\def\NoValue{-NoValue-} -\def\NoValueInIt{\NoValue} -\def\IfNoValueTF{\IfSomethingTF\NoValue} -\def\IfNoValueT{\IfSomethingT\NoValue} -\def\IfNoValueF{\IfSomethingF\NoValue} -\def\IfValueTF#1#2#3{\IfNoValueTF{#1}{#3}{#2}} -\let\IfValueT\IfNoValueF -\let\IfValueF\IfNoValueT -\def\BooleanFalse{TF} -\def\BooleanTrue{TT} -\def\IfBooleanTF#1{% - \if#1% - \@xa\@firstoftwo - \else - \@xa\@secondoftwo - \fi -} +{\def\:{\let\@sptoken= } \global\: % this makes |\@sptoken| a space token. -\def\IfBooleanT#1#2{% - \IfBooleanTF{#1}{#2}\@empty -} + % \DefIndex\@xifncat +\def\:{\@xifncat} \@xa\gdef\: {\futurelet\@let@token\@ifncat}} +% Note the trick to get a~macro with no parameter and requiring +% a~space after it. We do it inside a~group not to spoil the general +% meaning of |\:| (which we extend later). +% \dekmedskip +% +% \stanza The next command provides the real \cs{if} test for the next +% token. \emph{It} should be called |\@ifnextchar| but that name is +% assigned for the future \cs{ifx} text, as we know. Therefore we call +% it \cs{@ifnextif}. +% +% \stanza +% Having |\@ifnextcat| defined, let's apply it immediately. Similar +% thing does probably the \pk{xspace} package. +\def\spifletter{\@ifnextcat a{\space}{}} -\def\IfBooleanF#1{% - \IfBooleanTF{#1}\@empty -} -\fi% of |\unless\ifdefined\DeclareDocumentCommand|. +\long\pdef\@ifnextif#1#2#3{% +% \changes{v0.75}{2007/01/01}{\cs{let} for \cs[\#]1 changed to +% \cs{def} to allow things like \cs{noexpand\texttilde}} +% \chgs{2010/3/4 v0.991 inner macro fixed to handle active chars more +% properly (more as \cmd\if\ would do it)} +% \HideDef +% (the future token in |\noexpand|ed, unlike \inhash1) + \def\reserved@d{#1}% + \def\reserved@a{#2}% + \def\reserved@b{#3}% + \futurelet\@let@token\@ifnif} +% \ResumeDef -% \division{Ampulex Compressa-like modifications of macros} -% Ampulex Compressa is a~wasp that performs brain surgery on its -% victim cockroach to lead it to its lair and keep alive for its -% larva. Well, all we do here with the internal \LaTeX\ macros -% resembles Ampulex's actions but here is a~tool for a~replacement of -% part of macro's definition. +\def\@ifnif{% + \ifx\@let@token\@sptoken + \let\reserved@c\@xifnif + \else + \if\reserved@d\@nx\@let@token + \let\reserved@c\reserved@a + \else % |#1| of |\@ifnextif| is not |\if|-equivalent the future + % token. But this may be because the future token is active + % so it \emph{would} be |\if|-equivalent if not passed + % through |\futurelet|. Let's manage this case. + \begingroup + \edef\gmu@tempa{% + \lccode`\@nx~=`\reserved@d + }\gmu@tempa + \lowercase{\endgroup + \ifx~}\@let@token + \let\reserved@c\reserved@a + \else + \let\reserved@c\reserved@b + \fi + \fi + \fi + \reserved@c} + +% \UnDef +{\def\:{\let\@sptoken= } \: % this makes |\@sptoken| a space token. +% \UnDef +\def\:{\@xifnif} \@xa\gdef\: {\futurelet\@let@token\@ifnif}} + +% \dekmedskip % -% The \cs{ampulexdef} command takes its |#2| which has to be a~macro -% and replaces part of its definition delimited with |#5| and |#6| -% with the replacement |#7|. The redefinition may be prefixed with -% |#1|. |#2| may have parameters and for such a~macro you have to set -% the parameters string and arguments string (the stuff to be taken by -% the one-step expansion of the macro) as the optional |[#3]| and -% |[#4]|. . If \cs{ampulexdef} doesn't find the start and end tokens -% in the meaning of the macro, it does nothing to it. You have to -% write |####| instead of |#| or you can use |\ampulexhash| as -% well. For an example use see line \ref{ampulexset}. +% But how to peek at the next token to check whether it's an active +% char? First, we look with |\@ifnextcat| whether there stands a~group +% opener. We do that to avoid taking a~whole |{…}| as the argument +% of the next macro, that doesn't use |\futurelet| but takes the next +% token as an argument, tests it and puts back intact. +% \changes{v0.75}{2007/01/11}{added} +% +\long\pdef\@ifnextac#1#2{% + \@ifnextsingle + {\gm@ifnac{#1}{#2}}% + {#2}} + +\long\def\gm@ifnac#1#2#3{% + \ifcat\@nx~\@nx#3% + \@xa\@firstoftwo + \else\@xa\@secondoftwo + \fi{#1#3}{#2#3}} + +% Yes, it won't work for an active char |\let| to |{|${}_1$, but it ^^A~} +% \emph{will} work for an active char |\let| to a~char of +% catcode${}\neq1$. (Is there anybody on Earth who'd make an active +% char working as |\bgroup| not just recatcode it to $_1$?) +% + +% Having defined such tools, let's redefine |\gm@ifstar| to make it work +% with whatever catcode |*| may be. +% make a~version of |\gm@ifstar| that would work with +% |*|\catletter. + + +\pdef\gmu@lowstar{% + \iffontchar\font"22C6 \char"22C6 \else\gmu@lowstarfake\fi}% we could define it to +% be expandable (with \inverb|^^^^22c6|) but the only goal of it would +% be allowing this low star in |\csname›…\endcsname|. But it would be +% misleading (not everyone can easily distinguish |⁄string*| from |*|) +% so \IMHO\ it's better to raise an error should such an active occur +% in a~|\csname|. +% This macro is intended to be |\let| to an active star only in +% verbatims. For usual text there's + +% Commands around making star low (via |\active|ation) are defined in +% line \ref{def:gmu@star} because they use |\DeclareCommand|. + + +\def\gmu@tempa{*} +\foone{\catcode`\*=\active} +{\def\gmu@tempb{*}% it's defined in line \ref{active star} + % to make |*| defined (when it was undefined, + % \incmd\newcommand's \incs{gm@ifstar} test turned + % true, the next undefined token was gobbled and raised an error). + \let*=\gmu@lowstar} + + + +\edef\gmu@tempa{% + \long\pdef\@nx\gm@ifstar##1##2{% \chgs{2008/12/16 v0.98 renamed from + % \cs{@ifstar} since something + % redefines \cs{@ifstar}}] + \@nx\@ifnextif\gmu@tempa% + {\@nx\@firstoftwo{##1}}% + {% + \@nx\@ifnextchar\@xa\@nx\gmu@tempb + {\@nx\@firstoftwo{##1}}{##2}}% + }% of |\gm@ifstar|. +}\gmu@tempa + + +%\stanza +% A~test whether we can pick a~single token. We have to check whether +% we are not next to |{| and whether we are not next to |}|. + +\long\pdef\@ifnextsingle#1#2{% \chgs{2008/12/11 v0.98 extracted from + % \cs{@ifnextac}} This macro checks whether the next token is able + % to be picked or is it a~braced list of tokens or is it a~group + % closer so there's no token to be picked. + \@ifnextcat\bgroup{#2}{% + \@ifnextcat\egroup{#2}% \chgs{2008/12/11 v0.98 added test for + % \cmd\egroup} + {#1}}} + +\long\pdef\@ifnextgroup#1#2{% Note this macro turns true both before + % a~group opener and before a~group closer. + \@ifnextsingle{#2}{#1}} + + +% now let's apply this to sth. useful (used in \pk{gmverse} and in +% some typesetting, e.g.\ for prof.\ JSB. +\pdef\ignoreactiveM{% + \@ifnextgroup{}{\gmu@checkM}} + +\foone\obeylines{% we know it's a~single token since we use this macro + % only in \incmd\@ifnextgroup's ‘else’. + \long\pdef\gmu@checkM#1{% + \ifx + #1\@xa\ignoreactiveM% + \else\@xa#1\fi}} + + +% +% \stanza Now, define a~test that checks whether the next token is +% a~genuine space, | |${}_{10}$ that is. First define +% a~\CS let such +% a~space. The assignment needs a~little trick (\TeXbook\ appendix D) +% since |\let|'s syntax includes one optional space after |=|. +% +\let\gmu@reserveda\*% +\def\*{% + \let\*\gmu@reserveda + \let\gm@letspace= }% +\* % + +% \Define\@ifnextspace +\def\@ifnextspace#1#2{% + \let\gmu@reserveda\*% + \def\*{% + \let\*\gmu@reserveda + \ifx\@let@token\gm@letspace\afterfi{#1}% + \else\afterfi{#2}% + \fi}% + \futurelet\@let@token\*} +% First use of this macro is for an active |-| that expands to |---| +% if followed by a~space. Another to make dot checking whether is +% followed by |~| without gobbling the space if it occurs instead. +% +% \stanza +% Now a~test if the next token is an active line end. I~use it in +% \pk{gmdoc} and later in this package for active long dashes. + +\foone\obeylines{% + \long\pdef\@ifnextMac#1#2{% + \@ifnextchar^^M{#1}{#2}}} + + +% \division{Storing and restoring the meanings of \CSs} +% +% First a~Boolean switch of globalness of assignments and +% its verifier. +\newif\ifgmu@SMglobal + +\pdef\SMglobal{\gmu@SMglobaltrue} +% The subsequent commands are defined in such a~way that you can +% `prefix' them with |\SMglobal| to get global (re)storing. +% \stanza +% A~command to store the current meaning of a~\CS in another macro to +% temporarily redefine the \CS and be able to set its original meaning +% back (when grouping is not recommended): +% +%\Define\StoreMacro +%\changes{v0.61}{06/09/05}{added.} +%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} +\pdef\StoreMacro{% + \begingroup\makeatletter\gm@ifstar\egStore@MacroSt\egStore@Macro} +% The unstarred version takes a~\CS and the starred version +% a~text, which is intended for special control sequences. For storing +% environments there is a~special command in line \ref{StoreEnvironment}. + +\long\def\egStore@Macro#1{\endgroup\Store@Macro{#1}} +\long\def\egStore@MacroSt#1{\endgroup\Store@MacroSt{#1}} + +\long\def\Store@Macro#1{% + \escapechar92 + \ifgmu@SMglobal\afterfi\global\fi + \@xa\let\csname /gmu/store\string#1\endcsname#1% + \global\gmu@SMglobalfalse} + + +\long\def\Store@MacroSt#1{% + \edef\gmu@smtempa{% + \ifgmu@SMglobal\global\fi + \@nx\let\@xa\@nx\csname/gmu/store\bslash#1\endcsname%\label{SMbslash} + % we add backslash because to ensure compatibility between + % \incs{(Re)StoreMacro} and \incs{(Re)StoreMacro*}, that is. to allow + % writing e.g. \inverb|\StoreMacro\kitten| and then + % \inverb|\RestoreMacro*{kitten}| to restore the meaning of + % \incs{kitten}.\ilrr + \@xa\@nx\csname#1\endcsname} + \gmu@smtempa + \global\gmu@SMglobalfalse}% we wish the globality to be just + % once.\par + +% We make the |\StoreMacro| command a~three-step to allow usage of the +% most inner macro also in the next command. +% +% The starred version, |\StoreMacro*| works with csnames (without the +% backslash). It's first used to store the meanings of robust +% commands, when you may need to store not only |\foo|, but also +% |\csname foo \endcsname|. +% +% +% The next command iterates over a~list of \CSs and stores each of +% them. The \CS'es may be separated with commas but they don't have to. +% \Define\StoreMacros + +\long\pdef\StoreMacros{\begingroup\makeatletter\Store@Macros} +\long\def\Store@Macros#1{\endgroup + \gmu@setsetSMglobal + \let\gml@StoreCS\Store@Macro + \gml@storemacros#1.} +% \label{InnerStore} + +\def\gmu@setsetSMglobal{% + \ifgmu@SMglobal + \let\gmu@setSMglobal\gmu@SMglobaltrue + \else + \let\gmu@setSMglobal\gmu@SMglobalfalse + \fi} + +% And the inner iterating macro: +\long\def\gml@storemacros#1{% + \def\gmu@reserveda{\@nx#1}% My \TeX\ Guru's trick to deal with |\fi| + % and such, i.e., to hide |#1| from \TeX\ when it is processing a~test's + % branch without expanding. + \if\gmu@reserveda.% a~dot finishes storing. + \global\gmu@SMglobalfalse + \else + \if\gmu@reserveda,% The list this macro is put before may + % contain commas and that's O.K., we just continue the work. + \afterfifi\gml@storemacros + \else% what is else this shall be stored. + \gml@StoreCS{#1}% we use a~particular \CS to may |\let| it both to + % the storing macro as above and to the restoring one as + % \gmiflink[letRestore]{below}. + \afterfifi{\gmu@setSMglobal\gml@storemacros}% + \fi + \fi} + +% And for the restoring +%\Define\RestoreMacro +%\changes{v0.61}{06/09/05}{added.} +%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} +\pdef\RestoreMacro{% + \begingroup\makeatletter\gm@ifstar\egRestore@MacroSt\egRestore@Macro} + +\long\def\egRestore@Macro#1{\endgroup\Restore@Macro{#1}} +\long\def\egRestore@MacroSt#1{\endgroup\Restore@MacroSt{#1}} + +\long\def\Restore@Macro#1{% + \escapechar92 + \gmu@ifstored#1{% + \ifgmu@SMglobal\afterfi\global\fi + \@xa\let\@xa#1\csname /gmu/store\string#1\endcsname + \global\gmu@SMglobalfalse}% + {\unless\ifgmu@quiet + \PackageWarning{gmutils}{\@nx#1 is not stored, I do nothing with + it}% + \fi + }% +} + +\long\def\gmu@ifstored#1#2#3{% + \gm@ifundefined{/gmu/store% + \if\relax\@nx#1\else\bslash\fi + \string#1}{#3}{#2}% +} + +\long\pdef\gmu@storeifnotyet#1{% + \if\relax\@nx#1% we check if it's a~\CS + \gmu@ifstored{#1}{}{\StoreMacro#1}% + \fi} + + +\long\def\Restore@MacroSt#1{% + \gm@ifundefined{/gmu/store\bslash#1}% + {\unless\ifgmu@quiet + \PackageWarning{gmutils}{\bslash#1 is not stored. I~do nothing}% + \fi}% + {\edef\gmu@smtempa{% + \ifgmu@SMglobal\global\fi + \@nx\let\@xa\@nx\csname#1\endcsname + \@xa\@nx\csname/gmu/store\bslash#1\endcsname}% cf. the commentary + % in line \ref{SMbslash}. + \gmu@smtempa}% + \global\gmu@SMglobalfalse} + +% \Define\RestoreMacros +\long\pdef\RestoreMacros{\begingroup\makeatletter\Restore@Macros} + +\long\def\Restore@Macros#1{\endgroup + \gmu@setsetSMglobal + \let\gml@StoreCS\Restore@Macro% \gmhypertarget[letRestore]{we} + % direct the core \CS towards restoring and call the same iterating + % macro as in line \ref{InnerStore}. + \gml@storemacros#1.} +% As you see, the |\RestoreMacros| command uses the same iterating +% macro inside, it only changes the meaning of the core macro. + +% And to restore \emph{and} use immediately: +%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} +\def\StoredMacro{\begingroup\makeatletter\Stored@Macro} +\long\def\Stored@Macro#1{\endgroup\Restore@Macro#1#1} + +% To be able to call a~stored \CS without restoring it. +\def\storedcsname#1{%% \changes{v0.88}{2008/08/03}{added} + \csname /gmu/store\bslash#1\endcsname} + + +% 2008/08/03 we need to store also an environment. +\pdef\StoreEnvironment#1{% \label{StoreEnvironment} +% \changes{v0.88}{2008/08/03}{added} + \StoreMacro*{#1}\StoreMacro*{end#1}} + +\pdef\RestoreEnvironment#1{% +% \changes{v0.88}{2008/08/03}{added} + \RestoreMacro*{#1}\RestoreMacro*{end#1}} + + +% It happened (see the definition of |\@docinclude| in \pk{gmdoc.sty}) +% that I~needed to |\relax| a~bunch of macros and restore them after +% some time. Because the macros were rather numerous and I~wanted the +% code more readable, I~wanted to |\do| them. After a~proper defining +% of |\do| of course. So here is this proper definition of |\do|, +% provided as a~macro (a~declaration). +% +% \Define\StoringAndRelaxingDo +% \changes{v0.59}{06/09/04}{added for storing index-related macros in +% \pk{gmdoc}'s \cs{DocInclude}.} +% \changes{v0.61}{06/09/05}{renamed from \cs{MacroStoringDo} and the +% storing cs's prefix changed from \cs[]{@gml@srs}.} +\def\StoringAndRelaxingDo{% + \gmu@SMdo@setscope + \long\def\do##1{% + \gmu@SMdo@scope + \@xa\let\csname /gmu/store\string##1\endcsname##1% + \gmu@SMdo@scope\let##1\relax}} + +\def\gmu@SMdo@setscope{% + \ifgmu@SMglobal\let\gmu@SMdo@scope\global + \else\let\gmu@SMdo@scope\relax + \fi + \global\gmu@SMglobalfalse} + +% And here is the counter-definition for restore. +% +% \Define\RestoringDo +% \changes{v0.59}{06/09/04}{added for restoring index-related macros in +% \pk{gmdoc}'s \cs{DocInclude}.} +% \changes{v0.61}{06/09/05}{renamed from \cs{MacroRestoringDo} and +% relaxing of the storing cs removed.} +\long\def\RestoringDo{% + \gmu@SMdo@setscope + \long\def\do##1{% + \gmu@SMdo@scope + \@xa\let\@xa##1\csname /gmu/store\string##1\endcsname}} +% Note that both |\StoringAndRelaxingDo| and |\RestoringDo| are +% sensitive to the |\SMglobal| `prefix'. + +% And to store a~cs as explicitly named cs, i.e. to |\let| one csname +% another (|\n@melet| not |\@namelet| because the latter is defined +% in Till Tantau's \pk{beamer} class another way) (both arguments +% should be text): +\long\def\n@melet#1#2{% + \edef\gmu@nl@reserveda{% + \let\@xa\@nx\csname#1\endcsname + \@xa\@nx\csname#2\endcsname}% + \gmu@nl@reserveda} + +% The |\global| prefix doesn't work with |\n@melet| so we define the +% alternative. +\long\def\gn@melet#1#2{% + \edef\gmu@nl@reserveda{% + \global\let\@xa\@nx\csname#1\endcsname + \@xa\@nx\csname#2\endcsname}% + \gmu@nl@reserveda} + +\long\pdef\envirlet#1#2{% + \n@melet{#1}{#2}% + \n@melet{end#1}{end#2}% +} + + +% ^^A \StoreMacro\ch@ck +% ^^A % \label{store:ch@ck} + + + %\division{\cs{DeclareCommand} and \cmd\DeclareEnvironment} + % The code of this section is based on the \pk{xparse} + % package version 0.17 dated 1999/09/10, the version available in \TeX + % Live 2007-13, in Ubuntu packages at least. Originally considered a~stub `im Erwartung' + % (Schönberg) for the \LaTeX 3 bundle, it evolved to quite a~nice + % tool I~think. + % + % I~rewrote the ancient \pk{xparse}'s code to use the usual + % catcodes (only with |@| a~letter) and not to use the \pk{ldcsetup} + % package (which caused an error of + % undefined \CS\ |\KV@def|). + % Then I~added the |\protected| prefix to the first macro. And I~added + % my concept of |S|/|T| arg.\ spec. And of |b| and |B| spec. And the + % |Q| argument type. And made \cmd\DeclareEnvironment\ makes the + % arguments passed also to the end macro. +% +% After a~short deliberation I~rename the command to +% \cs{DeclareCommand} which is much shorter than original +% \cs{DeclareDocumentCommand} and more adequate at least +% in my case: I~don't only use this powerful declaration for +% ‘document’ commands. +% +% ^^A % After exchange of some mails with Morten H\o{}gholm and trying +% ^^A % \pk{xparse} of 2008/08/03 svn 748 (which beautifully spoils the +% ^^A % catcodes) I~wrap the +% ^^A % ancient code in a~conditional to avoid name collision if someone +% ^^A % loads \pk{xparse} before \pk{gmutils} +% +% In the args specification you can use: +% \begin{itemize} +% \item [\texttt{m}] for mandatory argument (braced or not), +% \item [\env{O\arg{default}}] for optional argument (in square +% brackets) with default value \ (which is passed as |#|\ +% if the argument is missing), +% \item [\texttt{o}] equivalent of |O{\NoValue}|: optional argument +% (in square brackets) lack of which makes the \cs{NoValue} macro +% passed as |#|\. You can check it with +% \possfil |\If›[No›]Value›(T⁄|F⁄|TF›){\#⁄}|, +% \item [\texttt{s}] for optional star (if star is present, it becomes +% respective |#|\, or else |\NoValue| is at the |#|\ (unlike in \pk{xparse}!). +% \item [\texttt{S}\arg{list}{default}] for a~Single token, checks whether on the +% respective position there's an unbraced token one of \ and +% returns it on |#|\ if present or \arg{default} if absent. The +% \arg{default} is a braced optional. If absent, |\NoValue| is the default. +% ^^A Then that +% ^^A % token can become |#|\<$n+1$>. +% \item [\texttt{T}] as ‘Token’, just an alias for |S|. +% +% Like in \pk{xparse}, |s| is a~shorthand for |S{*}|, but +% \emph{unlike} in \pk{xparse}, in the parsed arguments you get |*| or +% |\NoValue| as |#|\. You can now declare +%\begin{verbatim} +%\DeclareCommand\mimbla{S{+-}m}{% +% \leavevmode +% \ifx#1+\raise\fi +% \ifx#1-\lower\fi +% \ifx#1\NoValue\@tempdima=\fi +% 7pt \hbox{#2}% +% } +%\end{verbatim} +% and after |\mimbla+{raised} \mimbla-{lowered} \mimbla {untouched}| +% get:\par +% \fooatletter{\DeclareCommand\mimbla{S{+-}m}{\leavevmode\ifx#1+\raise\fi\ifx#1-\lower\fi\ifx#1\NoValue\@tempdima=\fi7pt\hbox{#2}}\mimbla+{raised}} +%\mimbla-{lowered} \mimbla {untouched} +% +% This example is rather silly but shows that you spend only one |#| +% for two symbols while in \pk{xparse} you would spend two. What if +% you wanted 10 options for the optional symbol? Here it's no +% problem. And with any number $k$ of tokens on the list the next |#| is +% always $n+1$ not $n+k+1$. +% +% \item [\texttt{Q}\arg{list}] as ‘se\textbf Quence’, a~sequence of +% symbols from \; for the fundamental usage see line +% \ref{Q-type}. More clearly, an argument specified with +% |Q|\arg{tokens} is a~word over the alphabet +% \${}\cup{\tt\visiblespace}$ where {\tt\visiblespace} +% is ignored and shall not be passed in the respective \hash{\}. +% +% \item [\texttt{c}] for an optional argument in +% parentheses. Historically it comes from a ‘coordinate’ argument and +% may serve as such: if you declare \TextUsage\DCcoordinate, then +% its catcher will be redefined to check for presence of a comma and pass +% the argument as |{|\arg{before comma}{after comma}|}| if comma +% present. |\NoValue| is passed if absent. By default +% \TextUsage\DCnocoordinate\ is executed that defines the |c| type +% argument as just an optional in parentheses. +% +% \item [\texttt C\arg{default}] as |c|, with default value. +% +% \item [\texttt b] for for an \emph{optional} argument in curly +% braces. That's strange for anyone acquainted with \LaTeX\ and +% contrary to its basic convention, but practised by Til Tantau in the +% \pk{beamer} class. If missing, |\NoValue| is passed as |#|\ and +% therefore all the tests |If›[No›]Value›(T⁄|F⁄|TF›)| apply. +% +% \item [\texttt B\arg{default}] for a~braced \emph{optional} argument with +% the default value \. +% +% \item [\texttt K\arg{\#-string}\metachar{[}\arg{replacement}\metachar{]}] +% for a~\emph{mandatory} \textbf Knuthian delimited or undelimited macro +% parameters. This concept comes from Stephen Hicks' suggestion at +% Bacho\TeX\ 2009 of implementing arguments delimited with +% |#{|. ^^A} +% So, in the mandatory first argument to |K| you give +% an arbitrary parameters string as described in Chapter 20 of +% \TB. If you don't provide the replacement, only |#1| of those +% parameters will be passed to the core macro of your command as +% |#|\. In both arguments you use single |#| char. +% +% \item [\texttt G\arg{pair of tokens}\metachar{[}{default value}\metachar{]}] a \textbf General +% catcher of an optional. For instance, to declare an optional in +% angles (used e.g.\ in Till Tantau's \pk{beamer}), declare +% |G{<>}|. Again, if second argument is absent, |\NoValue| is assumed. +% \item[\texttt{A}] (for ‘angles’) a~shorthand for |G{<>}| (accepts +% the second braced as the default value). +% +% \item [\texttt{\string\afterassignment}\arg{register}] a +% pseudo-argument that in fact \emph{interrupts} parsing arguments to +% let an assignment to \. The default \ is |\@tempcnta|. For +% example, +%\begin{verbatim} +% \DeclareCommand\llf{\afterassignment} +% {{\lastlinefit\@tempcnta\par}} +%\end{verbatim} +% defines |\llf| to be a command that expects a value for a numerical +% assignment, assigns it to (|\@tempcnta| and then to) the |\lastlinefit| +% special register and executes |\par| with that setting inside a +% group. +% +% Actually, \ may be empty |{}| and then each +% time our command is used the left side of the assignment has to +% be given explicitly and may even be different each time. +% +% Doesn't add anything to the arguments' list. +% +% \emph{This pseudo-argument type should be considered experimental.} +% +% \end{itemize} +% +% +% \stanza +% +% Note that you could limit acceptable values of a~mandatory or an +% optional-in-brackets argument +% to a~list inside definition of the command, using |\IfAmong›…\among…| +% defined in line \ref{IfAmong}. +% +% The |S|/|T|, |s| and |Q| arguments are always `long', they allow +% |\par| as their value that is. They have to be unbraced to be parsed so +% there's no danger of “runaway argument”. +% +% By default, \TextMarginize*{\long!lL} all the |c|, |C|, |o|, |O|, |m|, |b| and +% |B| are ‘short’, they don't allow |\par| in them that +% is. Note however that |\par| is allowed in the default values. If +% you wish to allow |\par| for all the arguments, you can say +% |\DeclareCommand\mycommand!|… — the optional |!| makes all +% the arguments ‘long’. Instead of |!| you can use |L| or |l| for +% ‘long’ or just |\long| itself. +% +% In the arguments specification string you can write |>›[{›]⁄›[}›]| +% to make subsequent argument ‘long’ or ignored: +% +% Any of \TextUsage*{Pp!lL\long\par} to make a particular argument ‘long’, +% allowing |\par| in it that is, and/or any of \TextUsage*{iI} to make the +% argument ignored (just gobbled). +% +% (Note that also the |c| and |C| arguments may be made ‘long’. That's +% because I use them not as coordinates but as just another kind of +% optional argument. +% +% The concept of ignored arguments came to my head when I was +% declaring a command with three braced optionals and put optional +% stars only to distinguish the braced optionals. +% +% For example, after +% \begin{verbatim} +% \DeclareCommand\GLBTQKi{% +% G{&&}{\#1 default} +% >LB{\#2 default} +% >iT{*\ht} +% Q{0123456789}{0} +% K{#1\par#2\par}{{\text{#1}\over\text{#2}}} +% \end{verbatim} +% and you get |\GLBTQKi| 4-argument with: +% \begin{enumargs} +% \dc G{&&} optional short in a pair of |&| with |\NoValue| as the default, +% \dc >LB optional long in curly braces, +% \dc >iT{*\ht} star or |\ht| control sequence, +% \dc Q{0123456789}{0} optional sequence of decimal digits with +% default 0, +% \dc K{#1\par#2\par}{{\text{#1}\over\text{#2}}} mandatory sequence +% of two arguments both delimited with |\par|, that will be passed +% the inner macro as |{\text{#1}\over\text{#2}}|. +% \end{enumargs} +% +% \stanza The arguments may be tested inside the command with +% \TextUsage\IfLong|{#⁄}|\arg{what if long}{what if short}. The +% test looks for |\par| at any level of nesting (|{\par}|---|\par| in +% braces will not hide) since it |\detokenize|s +% its argument. +% +% ^^A % \stanza +% ^^A % +% ^^A % There's an idea that came to my mind but I~did not +% ^^A % implement it: +% ^^A % \begin{itemize} +% ^^A % \item [\texttt{>B}] spec prefix for +% ^^A % mandatory argument to check whether that argument is braced. +% ^^A % \end{itemize} +% ^^A % The |B| and |b| argument types partially fulfil it. +% +% \stanza If you wish \TextMarginize*{\global\outer} to define your +% command |\global|ly, you can specify +% |\DeclareCommand\mycommand\global|. If you wish to forbid usage of +% your command in arguments of macros, add the |\outer| prefix. As +% with original \TeX's |\def| and like, the prefixes are allowed in +% any order and in any number only here they come between the +% command's name and the arguments specification. You can also add +% |\long|, as we mentioned above, and, for the symmetry, also +% |\protected|, although the latter is \emph{always} added since the +% command is not expandable. +% +% \stanza Handling of white spaces with optionals seems to me too +% complicated compared to the estimated weight of the problem and +% I~haven't faced it so far so I~don't provide anything. But!---but +% there are some commands that should be invisible in the typeset +% text, such as indexing commands and font declarations. For those +% there is a~working \LaTeX\ mechanism of |\@bsphack|---|\@esphack| +% and to use it I~provide yet another ‘prefix’: +% if you type \TextMarginize*{iIwW\sphack} |W| or +% |w| (for ‘white’) or |I| or |i| (for ‘invisible’) or, if you prefer +% a~prefix-like, |\sphack|\qfootnote{I~don't define the \cmd\sphack\ +% control sequence and don't assume it's defined. I~use it only +% as a~marker and my use of it doesn't create an entry in the +% hash table.} +% between the \CS to be defined and arguments +% spec, |\@bsphack| and |\@esphack| will be +% added in proper places. +% +% \stanza The original inner macros of the ancient \pk{xparse} had +% names like |\@dc@o| etc. According to my \TeX\ Guru's advice +% I~changed them to |\ArgumentCatcher@|\ to make the error +% messages less confusing. Well, I~don't know if they are but +% \possfil|\ArgumentCatcher@PO| looks better than |\@dc@PO| doesn't it? +% +% Talking of messages, there's a~Boolean switch +% \TextUsage\IfDCMessages. Its default setting is +% \TextUsage\DCMessagesfalse\ but if you set +% \TextUsage\DCMessagestrue, every |\command| created with my +% |\DeclareCommand| will issue a~message “Parsing arguments +% for |\command|” at the beginning of its execution. +% +% If you are positive \TextMarginize{.qQ} that no such message will +% ever be useful, you can suppress the very placing of it in the +% command's definition with an optional argument to +% \cs{Dec\-la\-re\-comm\-and} with all other ‘prefixes’, |.| or |q| +% or |Q| for ‘quiet’. +% +% \stanza +% To sum up, |\DeclareCommand| takes the following arguments: +% \begin{enumargs} +% \dc >Pm the command to be defined (can be even |\par| if you +% really wish), +% +% \dc Q{\long\global\outer\protected!lL.qQiIwW\sphack} optional +% \eTeX's prefix\:(es) and/or symbols for making all the arguments +% long (|!|, |l| or |L|) and/or to suppress placing of the diagnostic +% message in the definition (|.|, |q|, |Q|) and/or for placing +% |\@sphack|---|\@esphack| (|i|, |I|, |w|, |W|, |\sphack|), +% +% \dc >Pm the arguments +% specification (can contain |\par| as you see), +% +% \dc >Pm the definition body. You refer to the arguments with +% |#|\ and can test their presence and absence with +% |\If›[No›]Value›(T⁄|F⁄|TF›){#⁄}| and if the argument was specified +% with the |>P| prefix (allows |\par| in itself), you can test it +% with |\IfLong{#⁄}|\arg{if long}{if short}. You are also +% provided the |\IfAmong›…\among| and |\IfIntersect| tests defined +% earlier in this package to process the arguments, especially of +% the |S|/|T| and |Q| type. +% +% \end{enumargs} +% +%\stanza +% There is also the \TextUsage\DeclareEnvironment\ command to +% define environments with sophisticated optionals. It takes the +% arguments analogous to those of |\DeclareCommand|. +% +% The |iIwW\sphack| specifier however acts different: it doesn't add +% |\@bsphack| nor |\@esphack| but only |\@ignoretrue| to the +% end macro so the spaces following |\end{myenvir}| will be +% ignored. (I~tried the space hack but it's problematic (“bad space +% factor” error) if an environment begins in the vertical mode and +% ends in horizontal. +% +% \stanza +% So the arguments to +% \cs{Decl\-are\-Env\-iron\-ment} are: +% \begin{enumargs} +% +% \dc Pm the environment's name; you may wonder why it allows +% \cmd\par; it's to allow environments like +% \inverb|\string\par|---I~met such an environment once. +% +% \dc Q{\long\outer\global\protected!lL.qQiIwW\sphack} to prefix +% \possfil the +% command (note that |\outer| prefix will actually not work since +% the command is called with |\csname|), make all the +% arguments ‘long’ (|\long|, |!|, |l| or |L|), not to place the message +% issuer in the command (|.|, |q|, |Q|) or to make the +% environment ignores spaces following its end (|iIwW\sphack|). +% +% \dc Pm the arguments specification (both for the begin and for the +% end macros) +% +% \dc Pm the begin definition, +% +% \dc Pm the end definition; it can use the same parameters +% (\hash{\}'s) as the begin definition. Note however that there +% is only one +% specification of the arguments and both begin and end have to have 9 +% parameters in total at most. +% +% \end{enumargs} +% +% + +\unless\ifdefined\@temptokenb +\newtoks\@temptokenb +\fi + +\newif\if@dc@alllong@ % for an option of all arguments long. +\newif\if@dc@quiet@ % for suppressing the message of using of +% declared command. + +\newif\IfDCMessages % a~global switch to suppress the message about +% parsing. + + +\def\@dc@long@yes{P} + +\newtoks\@dc@arguments + +\newcount\@dc@catchernum +\newcount\@dc@argnum + +\newif\if@dc@ignore + + +% \UnPdef +\long\pdef\DeclareCommand#1#2#3{% ^^B It's the draft version just + % ^^B~to declare the true one, which is defined in line \ref{DC:final}. + % \begin{enumargs} + % \item command to be defined, + % \item arguments specification, + % \item definition body. + % \end{enumargs} + % \chgs[\DeclareCommand]{2008/12/05 v0.98 added the \env{S}/\env{T} spec parsing, the + % \env{s} spec parsing rewritten to be a~shorthand for + % \env{S\{*\}}, unused code removed} + % + \@dc@catchernum\z@ + \@dc@argnum\z@ + \toks@{}% in this register we will store the created sequence of + % argument catchers. + % ^^A Later, in the working declared command, + % ^^A % \incs{toks@} bears \inverb|{#1}{#2}{#3}…|. + \@temptokena\toks@ % in this register we will store the sequence of \inverb|#1#2…|. + \@temptokenb\toks@ % in this register we will store the sequences of + % \inverb|m|'s. + % ^^A \@temptokenc\toks@ % this register will bear the sequence of tests + % ^^A % for `longness' of arguments. + \emptify\@dc@long@ + \@dc@ignorefalse + \@dc#2X% |X| is the sentinel of parsing. + \protected\edef#1{% + \@nx\@dc@ {\the\toks@}% + \@xa\@nx\csname\string#1\endcsname + \@nx #1% + }% + \edef\gmu@reserveda{% + \long\def\@xa\@nx\csname\string#1\endcsname + \the\@temptokena{% + % ^^A \the\@temptokenc + \unexpanded{#3}}}% + \gmu@reserveda}% of the ‘draft’ |\DeclareCommand|. + + +\long\def\@dc@ + #1% the argument catchers in a~pair of braces (their arguments + % may contain \incmd\par\ so the macro is long). + #2% |\\thecommand| + #3% |\thecommand| + {% + \ifx\protect\@typeset@protect + \@xa\@firstofone + \else + \protect#3\@xa\@gobble + \fi + {\@dc@arguments{#2}#1\the\@dc@arguments}} + + +\def\@dc#1{% The main parsing macro. + \ifx#1X% if we meet the sentinel we stop. Note there may be some + % \inverb|m|'s in \incs{@temptokenb} and we might not to care about + % them since + % they denote mandatory arguments and as such they will + % be grabbed by \nlperc|\\⁄|. However, if any of them + % contains \incs{par} (while it shouldn't), then it wouldn't be + % noticed since \inverb|\\⁄| is always + % long. Therefore: + \@dc@add@ms + \else + \ifx#1>% + \let\next@dc\grab@prefix + \else % not |X| neither |>| + \if@dc@alllong@\let\@dc@long@\@dc@long@yes\fi + \ifx#1\afterassignment\@dc@ignoretrue\fi % if we parse the + % assigned pseudo-argument, we don't want to add anything to the + % % arguments' toks register so we apply general mechanism of + % % ignoring an argument. + \ifx#1\gobblespace\@dc@ignoretrue\fi % again, as above for + % ignoring spaces. + \ifnum \ifx#1m0\else1\fi \ifx\@dc@long@\@empty 0\else 2\fi + \if@dc@ignore 1\else0\fi = 0 % we check + % whether \inverb|#1| is \inverb|m| and not prefixed. + \addto@hook\@temptokenb m% as you see, \incs{@temptokenb} serves as + % a~storage of |m|'s. + \else % (not |m|) or prefixed + \@dc@add@ms + \if@dc@ignore\addtotoks\toks@{\@dc@ignorearg}\fi + \@xa\addtotoks\@xa\toks@\@xa{% + \csname ArgumentCatcher@\@dc@long@\detokenize{#1}\endcsname}% the argument catcher's name + % is \inverb|\ArgumentCatcher@›[P›]⁄|. + \@temptokenb{}% + \fi% of |\if| short |m| or not + \advance\@dc@catchernum\@ne + \unless\if@dc@ignore + \advance\@dc@argnum\@ne + \@temptokena\@xa{% + \the\@xa\@temptokena\@xa##\the\@dc@argnum}% + \else + \@dc@ignorefalse + \fi + \IfAmong#1\among{ABCO}% + {\let\next@dc\grab@default}% + {\IfAmong#1\among{GQST}% + {\let\next@dc\grab@defaults}% G, Q, S and T have second argument, + % braced optional, which is the default value (|\NoValue| by default). + {\gmu@if x {K#1}% + {\let\next@dc\@dc@define@K}% + {\gmu@if x {\afterassignment#1}% + {\let\next@dc\dc@grab@afterass}% + {\let\next@dc\@dc}% + }% + }% + }% + \unless\ifx\next@dc\@dc@define@K + \emptify\@dc@long@ + \fi + \fi % of |\if#1>|. + \@xa\next@dc + \fi +}% + +\def\@dc@add@ms{% + \@xa\@ifempty\@xa{\the\@temptokenb}% + {}% + {\toks@\@xa{% + \the\@xa\toks@ + \csname ArgumentCatcher@\the\@temptokenb\endcsname}}} + + +\long\def\grab@default#1{% the default value or the list of tokens for + % \inenv{S} may contain \incs{par} (why not?), that's why we make + % this macro \incs{long}. + \toks@\@xa{\the\toks@{#1}}% + \let\next@dc\@dc + \@dc +} + +\long\def\grab@defaults#1{% default (when default is absent) + \toks@\@xa{\the\toks@{#1}}% + \@ifnextchar\bgroup + {\grab@default}% + {\grab@default{\NoValue}}% +} + +\def\dc@grab@afterass{% + \@ifnextchar\bgroup + {\grab@default}% + {\grab@default{\@tempcnta}}% +} + + +\long\def\@dc@addargum{% + \addtotoks\@dc@arguments} + +\StoreMacro\@dc@addargum -%^^A \showthe\catcode`: -%^^A \showthe\catcode`_ -%^^A -%^^A \gmu@storespecials -%^^A -%^^A \RequirePackage{xparse}[2008/08/03] -%^^A -%^^A % This should not happen but well, it did: the catcodes changed the -%^^A % \pk{expl3} way leaked so I~fix them here. -%^^A \gmu@septify -%^^A \@makeother\: -%^^A \catcode`_=8 -%^^A \catcode`\ =10 +\pdef\@dc@ignorearg{% + \long\def\@dc@addargum##1{% + \RestoreMacro\@dc@addargum}} +% Parsing of Knuthian parameters string is easier to implement with +% full-feature |\DeclareCommand| so we postpone it till line \ref{K@parse} -\DeclareDocumentCommand\ampulexdef{O{}mO{}O{}mmm}{%^^B - % \begin{enumargs*} - % \opt definition prefix, empty by default, - % \mand macro to be redefined, - % \opt \cs{def} parameters string, empty by default, - % \opt definition body parameters to be taken in a~one-step - % expansion of the redefined macro, empty by default, - % \mand start token(s), - % \mand end token(s) - % \mand replacement. - % \end{enumargs*} - % \changes{v0.93}{2008/08/29}{added} - % \changes{v0.94}{2008/09/07}{made \pk{xparse}-ish and - % \cs{ampulexset} removed} - % For the example of usage see \ref{ampulexset}. - \def\gmu@tempa{#5}% - \def\gmu@tempb{#6}% - \def\gmu@tempc{#7}% we wrap the start, end and replacement tokens in - % macros to avoid unbalanced \incs{if}s. - \edef\gmu@tempd{% - \long\def\@nx\gmu@tempd - ####1\all@other\gmu@tempa - ####2\all@other\gmu@tempb - ####3\@nx\gmu@tempd{% - \@ifempty{####3}{\hidden@iffalse}{\hidden@iftrue}}}% - % - \gmu@tempd% it defines \incs{gmu@tempc} to produce an open \incs{if} - % depending on whether the start and end token(s) are found in the - % meaning of \inverb|#2|. - % - \edef\gmu@tempe{% - \@nx\gmu@tempd\all@other#2% - \all@other\gmu@tempa - \all@other\gmu@tempb\@nx\gmu@tempd - }% - % - \gmu@tempe% we apply the checker and it - % produces an open \incs{if}. - \edef\gmu@tempd{% - \long\def\@nx\gmu@tempd - ####1\@xa\unexpanded\@xa{\gmu@tempa}% - ####2\@xa\unexpanded\@xa{\gmu@tempb}% - ####3\@nx\ampulexdef{% we define a~temporary - % macro with the parameters delimited with the `start' and `end' parameters - % of \incs{ampulexdef}. - \@nx\unexpanded{####1}% - \@nx\@xa\@nx\unexpanded - \@nx\@xa{\@nx\gmu@tempc}%we replace the part of the redefined - % macro's meaning with the replacement text. - \@nx\unexpanded{####3}}}% -%^^A\show\gmu@tempd - \gmu@tempd -%^^A\show\gmu@tempd + +\def\grab@prefix#1{% + \IfIntersect{#1}{\long!lL\par Pp}% + {\def\@dc@long@{P}}{}% + \IfIntersect{#1}{Ii}% + {\@dc@ignoretrue}{}% + \@dc +} + +\long\def\ArgumentCatcher@o#1\@dc@arguments{% parsing of an optional with no default + \@ifnextchar[%^^A] + {\def\@dc@parse@next{#1}\ArgumentCatcher@o@}%\ + % the last macro has to be short so + % we can't give it all the arguments' catchers since some default may + % contain \incs{par}. Therefore we hide all the argument catchers in + % \incs{@dc@parse@next}. + {\@dc@addargum\NoValue#1\@dc@arguments}} + +\def\ArgumentCatcher@o@[#1]{% + \@dc@addargum{{#1}}\@dc@parse@next\@dc@arguments} + +\long\def\ArgumentCatcher@Po#1\@dc@arguments{% parsing of an optional with no default. + \@ifnextchar[%^^A] + {\ArgumentCatcher@Po@{#1}}% + {\@dc@addargum\NoValue#1\@dc@arguments}} + +\long\def\ArgumentCatcher@Po@#1[#2]{% + \@dc@addargum{{#2}}#1\@dc@arguments} + +\long\def\ArgumentCatcher@O#1#2\@dc@arguments{% parsing of optional with default value.\ + % \begin{enumargs} + % \mand the default value, + % \mand the tail of args parser. + % \end{enumargs} % - \edef\gmu@tempf{#4}% - \edef\gmu@tempe{% - #1\def\@nx#2#3{% - \@xa\@xa\@xa\gmu@tempd\@xa#2\gmu@tempf\ampulexdef}}% - \gmu@tempe - \fi} + \@ifnextchar[%^^A] + {\def\@dc@parse@next{#2}\ArgumentCatcher@o@}% note that even when an + % optional is short, its default may contain \incs{par}. + {\@dc@addargum{{#1}}#2\@dc@arguments}} -\def\ampulexhash{####}% for your convenience (not to count the hashes). -% For the heavy debugs I~was doing while preparing \pk{gmdoc}, as -% a~last resort I~used |\showlists|. But this command alone was -% usually too little: usually it needed setting |\showboxdepth| and -% |\showboxbreadth| to some positive values. So, -% -%^^A \Define\gmshowlists -\def\gmshowlists{\showboxdepth=1000 \showboxbreadth=1000 \showlists} -% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}} +\long\def\ArgumentCatcher@PO#1#2\@dc@arguments{% parsing of optional with default value.\ + % \begin{enumargs} + % \mand the default value, + % \mand the tail of args parser. + % \end{enumargs} + % + \@ifnextchar[%^^A] + {\ArgumentCatcher@Po@#2}% note that even when an + % optional is short, its default may contain \incs{par}. + {\@dc@addargum{{#1}}#2\@dc@arguments}} -\newcommand\nameshow[1]{\@xa\show\csname#1\endcsname} -\newcommand\nameshowthe[1]{\@xa\showthe\csname#1\endcsname} -% Note that to get proper |\showthe\my@dimen14| in the `other' |@|'s -% scope you write |\nameshowthe{my@dimen}14|\,. +\long\def\ArgumentCatcher@b#1\@dc@arguments{% parsing of an optional braced short argument. + \@ifnextcat\bgroup + {\def\@dc@parse@next{#1}\ArgumentCatcher@m@}%\ + % the last macro has to be short so + % we can't give it all the arguments' parsers since some default may + % contain \incs{par}. Therefore we hide all the argument catchers in \incs{@dc@parse@next}. + {\@dc@addargum\NoValue#1\@dc@arguments}} -% Standard |\string| command returns a~string of `other' chars except -% for the space, for which it returns | |$_{10}$. In \pk{gmdoc} -% I~needed the spaces in macros' and environments' names to be always -% \catother, so I~define -% \Define\xiistring -% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}} -\def\xiistring#1{% - \if\@nx#1\xiispace - \xiispace - \else - \string#1% - \fi} +\long\def\ArgumentCatcher@Pb#1\@dc@arguments{% parsing of a~braced and + % long optional with \incmd\NoValue\ default. + \@ifnextcat\bgroup + {\ArgumentCatcher@Pm#1\@dc@arguments}% + {\@dc@addargum\NoValue#1\@dc@arguments}% +} +\long\def\ArgumentCatcher@B#1#2\@dc@arguments{% parsing of a~braced optional with default value.\ + % \begin{enumargs} + % \mand the default value, + % \mand the tail of args catchers. + % \end{enumargs} + % + \@ifnextcat\bgroup + {\def\@dc@parse@next{#2}\ArgumentCatcher@m@}% note that even when an + % optional is short, its default may contain \incs{par}. + {\@dc@addargum{{#1}}#2\@dc@arguments}} -% \division{\cs{@ifnextcat}, \cs{@ifnextac}} -% -% As you guess, we |\def| |\@ifnextcat| \agrave~la |\@ifnextchar|, see -% \LaTeXe\ source dated 2003/12/01, file d, lines 253--271. The -% difference is in the kind of test used: while |\@ifnextchar| does -% |\ifx|, |\@ifnextcat| does |\ifcat| which means it looks not at the -% meaning of a~token(s) but at their |\catcode|(s). As you (should) -% remember from \TeXbook, the former test doesn't expand macros while -% the latter does. But in |\@ifnextcat| the peeked token is protected -% against expanding by |\noexpand|. Note that the first parameter is -% not protected and therefore it shall be expanded if it's -% a~macro. Because an assignment is involved, you can't test whether -% the next token is an active char. +\long\def\ArgumentCatcher@PB#1#2\@dc@arguments{% parsing of a~braced + % and long optional with default value.\ + % \begin{enumargs} + % \mand the default value, + % \mand the tail of args catchers. + % \end{enumargs} + % + \@ifnextcat\bgroup + {\ArgumentCatcher@Pm#2\@dc@arguments}% + {\@dc@addargum{{#1}}#2\@dc@arguments}} -\long\def\@ifnextcat#1#2#3{% -% \changes{v0.75}{2007/01/01}{\cs{let} for \cs[\#]1 changed to -% \cs{def} to allow things like \cs{noexpand\*}} -% \HideDef - \def\reserved@d{#1}% - \def\reserved@a{#2}% - \def\reserved@b{#3}% - \futurelet\@let@token\@ifncat} -% \ResumeDef -\def\@ifncat{% - \ifx\@let@token\@sptoken - \let\reserved@c\@xifncat - \else - \ifcat\reserved@d\@nx\@let@token - \let\reserved@c\reserved@a - \else - \let\reserved@c\reserved@b - \fi +\long\def\ArgumentCatcher@S@% parsing of a~Single continued: +#1% the list to search |#4| on, +#2% the default value, +#3% the tail of args parsers, +#4% the token we search in |#1| (it's an unbraced +% single token as we checked in line \ref{dc@S:bgroup}). +{% + \IfAmong#4\among{#1}% + {\@dc@addargum{{#4}}#3\@dc@arguments}% + {\@dc@addargum{{#2}}#3\@dc@arguments#4}% +} + +\long\def\ArgumentCatcher@S % parsing of a~\textbf Single\ + % token. It's always long since we look for a~single unbraced token\ + % so there is no danger of “runaway argument”. +#1% the list we search optional token on, +#2% the default value, +#3% the tail of args parser. +\@dc@arguments{% + \@ifnextsingle + % \label{dc@S:bgroup} + {\ArgumentCatcher@S@{#1}{#2}{#3}}% + {\@dc@addargum{{#2}}#3\@dc@arguments}% if we parse an + % opening or closing brace, then we are sure it's not any expected + % Single. +} + + +\let\ArgumentCatcher@PS\ArgumentCatcher@S % as above: we always act `long' with single tokens. +\let\ArgumentCatcher@T\ArgumentCatcher@S % we allow |T| (for Token) as +% an alias of |S|. + + +\edef\ArgumentCatcher@s{% + \@nx\ArgumentCatcher@S{\@xa\@nx\all@stars}{\@nx\NoValue}}% the |s| arg spec is +% a~shorthand for \inverb|S{*}|. Except the star may be of any +% category from $\{11,12,13\}$. +\let\ArgumentCatcher@Ps\ArgumentCatcher@s + +\long\def\ArgumentCatcher@Q% parsing of a~se\textbf Quence\ + % of tokens from the list. It's always long since we look for unbraced tokens\ + % so there is no danger of “runaway argument”. +#1% the list we search optional tokens on, +#2% the default value, +#3% the tail of args parser. +\@dc@arguments % delimiter +{% + \def\@dc@parse@next{#3}% + \emptify\@dc@seQuence + \ArgumentCatcher@Q@{#1}{#2}} + +% \Define\ArgumentCatcher@PQ +\let\ArgumentCatcher@PQ\ArgumentCatcher@Q + +\long\def\ArgumentCatcher@Q@#1#2{% list, default + % ^^A \typeout{@@@@ AC@Q@, toks@: \the\@dc@arguments}% + \@ifnextsingle + {\ArgumentCatcher@Q@@{#1}{#2}}% + {\@dc@seQuence@finish{#2}}% +} + +\long\def\ArgumentCatcher@Q@@#1#2#3{% list, default, token to be checked\\ + % we only launch this macro when not + % before opening curly brace. \inverb|#1| is the list of acceptable + % values, \inverb|#2| the default value, \inverb|#3| is the token to + % be sought on the list. + \IfAmong #3\among{#1}% + {\addtomacro\@dc@seQuence#3% + \ArgumentCatcher@Q@{#1}{#2}}% + {\@dc@seQuence@finish{#2}#3}% +} + +\long\def\@dc@seQuence@finish#1{% + % ^^A \typeout{@@@@ l.\the\inputlineno\space \@xa\unexpanded\@xa{\@dc@seQuence}}% + \ifx\@dc@seQuence\@empty\def\@dc@seQuence{#1}\fi + \@xa\@dc@addargum\@xa{\@xa{\@dc@seQuence}}% + % ^^A \typeout{@@@@ finish, toks@: \the\@dc@arguments}% + \@dc@parse@next\@dc@arguments } + + +\long\def\ArgumentCatcher@c#1\@dc@arguments{% + \@ifnextchar(%^^A) + {\def\@dc@parse@next{#1}\ArgumentCatcher@c@}% + {% + % ^^A \PackageError{gmutils/gmparse}{Missing coordinate argument}% + % ^^A {A value of (0,0) is assumed}% + \@dc@addargum{{\NoValue}}#1\@dc@arguments}% +} + +\def\DCcoordinate{% + \def\ArgumentCatcher@c@(##1){% + \IfAmong,\among{##1}% + {\@xa\@dc@addargum\@dc@commasep##1\@dc@commasep}% + {\@dc@addargum{{##1}}}\@dc@parse@next\@dc@arguments}% + % \stanza + \def\@dc@commasep##1,##2\@dc@commasep{{{{##1}{##2}}}}% + % \stanza + \long\def\ArgumentCatcher@Pc@(##1){% + \IfAmong,\among{##1}% + {\@xa\@dc@addargum\@dc@commasep##1\@dc@commasep}% + {\@dc@addargum{{##1}}}\@dc@parse@next\@dc@arguments}% +} + +\def\DCnocoordinate{% + \def\ArgumentCatcher@c@(##1){% + \@dc@addargum{{##1}}\@dc@parse@next\@dc@arguments}% + % \stanza + \long\def\ArgumentCatcher@Pc@(##1){% + \@dc@addargum{{##1}}\@dc@parse@next\@dc@arguments}% +} + +\DCnocoordinate + +\long\def\ArgumentCatcher@C#1#2\@dc@arguments{% + \@ifnextchar(%^^A) + {\def\@dc@parse@next{#2}\ArgumentCatcher@c@}% + {\@dc@addargum{{#1}}#2\@dc@arguments}} + + +\long\def\ArgumentCatcher@Pc#1\@dc@arguments{% + \@ifnextchar(%^^A) + {\def\@dc@parse@next{#1}\ArgumentCatcher@Pc@}% + {\@dc@addargum{{\NoValue}}#1\@dc@arguments}% +} + +\long\def\ArgumentCatcher@PC#1#2\@dc@arguments{% + \@ifnextchar(%^^A) + {\def\@dc@parse@next{#2}\ArgumentCatcher@Pc@}% + {\@dc@addargum{{#1}}#2\@dc@arguments}} + + +\long\def\ArgumentCatcher@Pm#1\@dc@arguments#2{% + \@dc@addargum{{#2}}#1\@dc@arguments} + +\def\gmu@hashes#1#2{% this is a~fully expandable loop analogous to + % that of The % \eTeX\ Manual p.~9. + \ifnum#1<#2% + ####\number#1 + \expandafter\gmu@hashes + \expandafter{\number\numexpr#1+1\expandafter}% + \expandafter{\number#2\expandafter}% + \fi}% of |\gmu@hashes|. + +\def\gmu@hashesbraced#1#2{% + \ifnum#1<#2% + {####\number#1}% + \expandafter\gmu@hashesbraced + \expandafter{\number\numexpr#1+1\expandafter}% + \expandafter{\number#2\expandafter}% + \fi}% of |\gmu@hashesbraced|. + +\@tempcnta=1 +\@whilenum\@tempcnta<9\do{% + \edef\gmu@ms{\romannumeral\numexpr\@tempcnta*1000 }% + % + % ^^A \typeout{@@@@ gmutils.sty: defining \bslash + % ^^A ArgumentCatcher@\gmu@ms}% + \edef\gmu@tempa{% + \long\def\@xa\@nx\csname + ArgumentCatcher@\gmu@ms + \endcsname + ##1\@nx\@dc@arguments{\def\@nx\@dc@parse@next{##1}% + \@xa\@nx\csname + ArgumentCatcher@\gmu@ms @% + \endcsname}% + % + \def\@xa\@nx\csname + ArgumentCatcher@\gmu@ms @% + \endcsname + \gmu@hashes1{\numexpr\@tempcnta+1}% + {\@nx\@dc@addargum{% + \gmu@hashesbraced1{\numexpr\@tempcnta+1}}% + \@nx\@dc@parse@next\@nx\@dc@arguments + }% of \incs{ArgumentCatcher@\@}. + }% of |\edef|. + \gmu@tempa + \advance\@tempcnta1\relax +}% of the loop. + +% The loop above defines 8 pairs of macros as we see thanks to the +% code below: +\if 1 1 +\@tempcnta\@ne +\@whilenum\@tempcnta<9\do{% + \edef\gmu@ms{\romannumeral\numexpr\@tempcnta*1000}% + \typeout{\bslash ArgumentCatcher@\gmu@ms:% + ^^J\@xa\meaning\csname ArgumentCatcher@\gmu@ms\endcsname}% + \typeout{\bslash ArgumentCatcher@\gmu@ms @:% + ^^J\@xa\meaning\csname ArgumentCatcher@\gmu@ms @\endcsname}% + \advance\@tempcnta\@ne +} +\fi +% The code above produces on the terminal: +%\begin{verbatim} +% \ArgumentCatcher@m: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@m@ +% \ArgumentCatcher@m@: +% macro:#1->\addto@hook \@dc@arguments {{#1}}\@dc@parse@next \@dc@arguments +% \ArgumentCatcher@mm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mm@ +% \ArgumentCatcher@mm@: +% macro:#1#2->\addto@hook \@dc@arguments {{#1}{#2}}\@dc@parse@next \@dc@arguments +% \ArgumentCatcher@mmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmm@ +% \ArgumentCatcher@mmm@: +% macro:#1#2#3->\addto@hook \@dc@arguments {{#1}{#2}{#3}}\@dc@parse@next \@dc@arguments +% \ArgumentCatcher@mmmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmmm@ +% \ArgumentCatcher@mmmm@: +% macro:#1#2#3#4->\addto@hook \@dc@arguments {{#1}{#2}{#3}{#4}}\@dc@parse@next \@dc@arguments +% \ArgumentCatcher@mmmmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmmmm@ +% \ArgumentCatcher@mmmmm@: +% macro:#1#2#3#4#5->\addto@hook \@dc@arguments {{#1}{#2}{#3}{#4}{#5}}\@dc@parse@next \to +% ks@ +% \ArgumentCatcher@mmmmmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmmmmm@ +% \ArgumentCatcher@mmmmmm@: +% macro:#1#2#3#4#5#6->\addto@hook \@dc@arguments {{#1}{#2}{#3}{#4}{#5}{#6}}\@dc@parse@ne +% xt \@dc@arguments +% \ArgumentCatcher@mmmmmmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmmmmmm@ +% \ArgumentCatcher@mmmmmmm@: +% macro:#1#2#3#4#5#6#7->\addto@hook \@dc@arguments {{#1}{#2}{#3}{#4}{#5}{#6}{#7}}\@dc@pa +% rse@next \@dc@arguments +% \ArgumentCatcher@mmmmmmmm: +% macro:#1\@dc@arguments ->\def \@dc@parse@next {#1}\ArgumentCatcher@mmmmmmmm@ +% \ArgumentCatcher@mmmmmmmm@: +% macro:#1#2#3#4#5#6#7#8->\addto@hook \@dc@arguments {{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}}\@ +% dc@parse@next \@dc@arguments +%\end{verbatim} + + +\def\ArgumentCatcher@mmmmmmmmm\the\@dc@arguments +#1#2#3#4#5#6#7#8#9{% yes, it has to be + % delimited (well, actually: started) by \inverb|\the\@dc@arguments| not + % only \incs{@dc@arguments}. And it doesn't need to be long and launch inner + % short macro because there's nothing more to catch. + \@dc@addargum{% + {#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}\the\@dc@arguments} + + +\long\def\ArgumentCatcher@Pm#1\@dc@arguments#2{% catcher of a~long mandatory. + \@dc@addargum{{#2}}#1\@dc@arguments} + + +\long\def\ArgumentCatcher@K % a~Knuthian delimited or undelimited +% arguments parsed and passed to the command's body in a~digest +% (Knuthian replacement) +#1% the particular Knuthian macro +#2% the tail of args parser. +\@dc@arguments % tail delimiter +{\def\@dc@parse@next{#2}#1} + +\let\ArgumentCatcher@PK\ArgumentCatcher@K + +\long\def\gmu@twostring#1#2{\string#1\string#2} + +\long\def\ArgumentCatcher@G % general catcher +#1% left and right delimiter +#2% default value +#3% the tail of args parser. +\@dc@arguments % tail delimiter +{% + \edef\@dc@Gname{ArgumentCatcher@G\gmu@twostring#1}% + \unless\ifcsname \@dc@Gname \endcsname + \@xa\def\csname \@dc@Gname\@xa\endcsname + \@dc@Gparams#1{\@dc@addargum{{##2}}##1\@dc@arguments}% \fi - \reserved@c} + \@xa\@ifnextchar\@firstoftwo#1% + {\def\dc@parse@next{#3}% we hide possible |\par|s. + \csname\@dc@Gname\endcsname\dc@parse@next}% + {\@dc@addargum{{#2}}#3\@dc@arguments}% +} -{\def\:{\let\@sptoken= } \global\: % this makes |\@sptoken| a space token. - % \DefIndex\@xifncat -\def\:{\@xifncat} \@xa\gdef\: {\futurelet\@let@token\@ifncat}} -% Note the trick to get a~macro with no parameter and requiring -% a~space after it. We do it inside a~group not to spoil the general -% meaning of |\:| (which we extend later). -% \dekmedskip -% -% \stanza The next command provides the real \cs{if} test for the next -% token. \emph{It} should be called |\@ifnextchar| but that name is -% assigned for the future \cs{ifx} text, as we know. Therefore we call -% it \cs{@ifnextif}. +\long\def\ArgumentCatcher@PG % general catcher +#1% left and right delimiter +#2% default value +#3% the tail of args parser. +\@dc@arguments % tail delimiter +{% + \edef\@dc@Gname{ArgumentCatcher@PG\gmu@twostring#1}% + \unless\ifcsname \@dc@Gname \endcsname + \long\@xa\def\csname \@dc@Gname\@xa\endcsname + \@dc@Gparams#1{\@dc@addargum{{##2}}##1\@dc@arguments}% + \fi + \@xa\@ifnextchar\@firstoftwo#1% + {\csname\@dc@Gname\endcsname{#3}}% + {\@dc@addargum{{#2}}#3\@dc@arguments}% +} -\long\pdef\@ifnextif#1#2#3{% -% \changes{v0.75}{2007/01/01}{\cs{let} for \cs[\#]1 changed to -% \cs{def} to allow things like \cs{noexpand\*}} -% \HideDef - \def\reserved@d{#1}% - \def\reserved@a{#2}% - \def\reserved@b{#3}% - \futurelet\@let@token\@ifnif} -% \ResumeDef -\def\@ifnif{% - \ifx\@let@token\@sptoken - \let\reserved@c\@xifnif +\long\def\@dc@Gparams#1#2{##1#1##2#2}% expands to parameters string +% with \inhash1 delimited with first argument and \inhash2 delimited +% with second. In fact it's intended to pass \inhash1 further (it will +% always be braced) and to catch an argument put in a~pair of tokens +% given \incmd\@dc@Gparams\ as the arguments. + +\long\def\ArgumentCatcher@A{\ArgumentCatcher@G{<>}} +\long\def\ArgumentCatcher@PA{\ArgumentCatcher@PG{<>}} + +\long\def\ArgumentCatcher@a{\ArgumentCatcher@G{<>}{\NoValue}} +\long\def\ArgumentCatcher@Pa{\ArgumentCatcher@PG{<>}{\NoValue}} + + +\def\NoValue{-NoValue-} + +\long\def\IfNoValueTF#1{% % \chgs{2008/12/1 v0.98 the \pk{xparse} tests for + % the presence of value redefined and much simplified (43 \CS'es + % less). Moreover, they are now fully expandable: \cmd\IfNoValueTF, + % \cmd\IfNoValueT, \cmd\IfNoValueF, \cmd\IfValueTF, \cmd\IfValueT, + % \cmd\IfValueF} + % + \@xa\ifx\@firstofmany#1\@empty\@@nil\NoValue \afterfi\@firstoftwo + \else\afterfi\@secondoftwo + \fi} + +\long\def\IfNoValueT#1#2{\IfNoValueTF{#1}{#2}\@empty} + +\long\def\IfNoValueF#1#2{\IfNoValueTF{#1}\@empty{#2}} + +\long\def\IfValueTF#1#2#3{\IfNoValueTF{#1}{#3}{#2}} + +\long\def\PutIfValue#1{\IfValueT{#1}{#1}} + +% \Define\IfValueT +\let\IfValueT\IfNoValueF + +% \Define\IfValueF +\let\IfValueF\IfNoValueT + +\long\pdef\IfLong#1{%\ + % \begin{enumargs} + % \item the argument to check for |\par|, + % \item what if |\par| found, + % \item what if |\par| not found. + % \end{enumargs} + % + \edef\gmu@reserveda{\detokenize{#1}}% + \edef\gmu@reserveda{% + \IfAmong\string\par\@nx\among{\gmu@reserveda}}% + \gmu@reserveda} + + +% |\afterassignment| pseudo-argument + +\long\@namedef{ArgumentCatcher@\detokenize{\afterassignment}}% +#1% register used in the assignment +#2% the tail of args parser. +\@dc@arguments{% + \def\@dc@parse@next{% + \@dc@addargum\NoValue % to make ignoring mechanism work + #2\@dc@arguments}% + \afterassignment\@dc@parse@next + #1}% optional space and |=| is left at user's discretion. In fact, +% \inhash1 may be empty and then each +% time our command is used the left side of the assignment has to +% be given explicitly and may even be different each time. + +\n@melet{ArgumentCatcher@P\detokenize{\afterassignment}} +{ArgumentCatcher@\detokenize{\afterassignment}} + +% |\gobblespace| pseudo-argument: useful between optional and +% Knuthian-type arguments and after all parsing. Equivalent +% |>iT{\somedummymacro}|. At first I wanted mark it |\ignorespaces| +% but the gobbling doesn't expand macros: it doesnt't use +% |\ignorespaces| but |\@ifnextchar|'s space trick. + +\long\@namedef{ArgumentCatcher@\detokenize{\gobblespace}}% +{\ArgumentCatcher@S{\dc@gobblespace@dummy}{\NoValue}} + +\n@melet{ArgumentCatcher@P\detokenize{\gobblespace}} +{ArgumentCatcher@\detokenize{\gobblespace}} + +\def\dc@gobblespace@dummy{\dc@gobblespace@dummy} + +\let\gobblespace\dc@gobblespace@dummy + + +% end of catchers' definitions + + +\DeclareCommand\DeclareCommand % This is the final version by now.\ + % Note we introduce the ‘prefixes’ at the \inhash2 position only at \ + % this point so we have yet to prefix every argument specifier\ + % separately. Note also we only here ‘teach’ |\DeclareCommand| to + % pass the name of its main argument in the |\dc@bsname| macro. +{>Pm % (1) command to be defined (may be \incs{par} if you + % really wish), + Q{\global\protected\outer\long!lL.qQiIwW\sphack\envhack}%\ + % \label{Q-type} % (2) an optional + % se\textbf Quence of \eTeX's prefixes and/or |!| or |l| or |L| + % for ‘all + % long’ and/or |.| or |q| or + % |Q| for `quiet' (message about calling the command is + % suppressed) and/or % |i| or |I| as ‘invisible’ or |W| or |w| as + % ‘white’ or |\sphack| to make the command ‘invisible’ in + % the leading with the \incs{@bsphack}…\incs{@esphack}\qfootnote{To + % deal with an ‘invisible’ environment, there is one more + % acceptable value of this argument: \cmd\envhack, which + % suppresses placing \cs{@bsphack}---\cs{@esphack} and places + % \cs{@ignoretrue} instead in the end macro.}, + >Pm % (3) arguments specification (may contain \incmd\par), + >Pm % (4) the definition body; may contain nearly anything including + % \incmd\par\ and tests for presence/absence of arguments + % \nlperc|\If›[No›]Value›(T⁄|F⁄|TF›)| and for their longness \incmd\IfLong; + % you refer to the arguments with \inverb|#|\. +}{% \label{DC:final} % + % \chgs{2008/12/05 v0.98 added the \cs{@bsphack}---\cs{@esphack} option} + % \chgs{2008/12/07 v0.98 added the \env{Q\arg{tokens}} argument type + % (a~word over the alphabet \)} + % + % ^^A \edef\@detokena{\detokenize{{#1} {#2} {#3} {#4} {#5} {#6}}}% + % ^^A \typeout{\@detokena}% + % + \edef\dc@bsname{\string#1}% we'll use it in K-type arg.\ catcher and + % to allow \inhash1${}=={}$\incs{par} + % (\incs{Pack\+age\+Warn\+ing} is short and \incs{typeout} too!). + \gm@testdefined#1\iftrue + \IfDCMessages + \PackageWarning{gmutils (gmparse)}{Redefining command \dc@bsname\space + with \string\DeclareCommand}% + \fi \else - \if\reserved@d\@nx\@let@token - \let\reserved@c\reserved@a - \else - \let\reserved@c\reserved@b + \IfDCMessages + \typeout{^^J\string\DeclareCommand\dc@bsname\space (new)^^J}% \fi \fi - \reserved@c} + % + % First we parse the declaration options to know whether all the + % arguments are to be long and whether we should suppress the + % message ``Parsing arguments for…''.\nostanza + \@dc@alllong@false + \@dc@quiet@false + % ^^A \typeout{@@@@ \the\inputlineno\space DC \xiihash1: \@nx#1}% + \IfIntersect{#2}{\long!lL}{% + % ^^A \typeout{@@@ \@nx #1 \space intersect with !lL }% + \@dc@alllong@true}{}% + \IfIntersect{#2}{.qQ}{\@dc@quiet@true}{}% + \IfIntersect{#2}{iIwW\sphack}% + {% if `invisibility' is specified: \UnDef + \def\@dc@bsphack@{\@nx\@bsphack}% \UnDef + \def\@dc@esphack@{\@nx\@esphack}% + }% + {\emptify\@dc@bsphack@\emptify\@dc@esphack@}% if `invisibility' is not specified. + \IfAmong\envhack\among{#2}% + {% but if we define an environment: + \emptify\@dc@bsphack@\emptify\@dc@esphack@}% + {% and if we don't define an environment: + \emptify\@dc@env@argstoend}% + \relaxen\@dc@global@ \relaxen\@dc@outer@ + \IfAmong\outer\among{#2}{\let\@dc@outer@\outer}{}% + \IfAmong\global\among{#2}{\let\@dc@global@\global}{}% + % We initialise the scratch count and toks registers before parsing + % of the arguments specifiers.\nostanza + \@dc@catchernum\z@ + \@dc@argnum\z@ + \toks@{}% + \@temptokena\toks@ + \@temptokenb\toks@ + % We parse the arguments specifiers:\nostanza + \@dc#3X% |X| is the sentinel of parsing.\par + % Now we define the basic macro:\nostanza + \@dc@outer@\@dc@global@ % possibly the prefixes, + \protected\edef#1{% always |\protected| \balsmiley( ;-) + \@dc@bsphack@ % perhaps |\@bsphack| + \unless\if@dc@quiet@ + \unexpanded{% + \IfDCMessages + \typeout}{Parsing arguments for \dc@bsname.}% + \@nx\fi + \fi + \@nx\@dc@{\the\toks@}% in the braces appear the argument catchers. + \@xa\@nx\csname\dc@bsname\endcsname + \ifx\@dc@outer@\outer + \@xa\@nx\csname \@xa\gobble\string#1 \endcsname % note the blank + % space after \inhash1! If the command is to be \incmd\outer, we + % can't put it itself, so we put another, whose name is the same + % plus a~space. Anyway, since \inhash1 becomes \incmd\protected, + % this case will never be executed. + \else \@nx #1% + \fi + }% \UnDef + \edef\gmu@reserveda{% + \@dc@global@ % perhaps |\global| + \long\def\@xa\@nx\csname\string#1\endcsname% for a~command + % \incmd\command, define \incs{\bslash command}\ilrr + \the\@temptokena% it's |#1#2#3…| + {% the definition body: + \@dc@env@argstoend % if we define an environment, this macro + % will provide passing the arguments to the end macro (see + % line \ref{@dc@env@argstoend}). + % ^^A \IfNoValueTF{#1}% + % ^^A {\@dc@test@long\@nx#2{\the\@temptokena}}{}% + \unexpanded{#4}% + \@dc@esphack@}% + }% of |\edef|. + \gmu@reserveda +}% of |\DeclareCommand|. + +% Now we have a~convenient tool to implement parsing of a~Knuthian +% argument(s). + +% Knuthian argument's default replacement +\def\@dc@K@defaultrepl{##1} +% 2009/11/22 inner pair of braces removed (as leading to additional +% group causing errors). + +\DeclareCommand\@dc@define@K\long{mb}{% \label{K@parse} + % first we add the particular \CS to the toks register:\nostanza + \edef\gmu@tempa{% + \unexpanded{\toks@\@xa}% + {\@nx\the\toks@{% + \@xa\@nx\csname\dc@bsname @K\the\@dc@catchernum\endcsname}}% + }\gmu@tempa + % and define this macro: \nostanza + \edef\gmu@tempa{% + \def\@xa\@nx\csname\dc@bsname @K\the\@dc@catchernum\endcsname + \unexpanded{#1}{% + \@nx\@dc@addargum{{% + \IfValueTF{#2}{\unexpanded{#2}}{\@xau{\@dc@K@defaultrepl}}% + }}% we add the Knuthian + % replacement to the toks register as \inhash n. + \@nx\@dc@parse@next\@dc@arguments}% and continue parsing. + }% of |\edef|. Now we execute this temporary macro, which means we \incmd\def|\⁄@K⁄| + \@dc@global@ % set properly before |\@dc#3X|. + \if P\@dc@long@\relax\long\fi + \gmu@tempa + % ^^A \nameshow{\dc@bsname @K\the\@dc@catchernum}% + % Now we clean up and continue construction of arguments parser. \nostanza + \emptify\@dc@long@ + \@dc +} + + +\DeclareCommand\DeclareEnvironment\long +{m% Pm the environment's name; you may wonder why it allows + % \incmd\par. Once I~met an environment with a~name containing + % \nlperc|\string\par|. + Q{\outer\global\protected\long!lL.qQiIwW\sphack\envhack}% \ + % a~sequence of \eTeX's prefixes and/or specifiers to make all the + % arguments ‘long’ (\incmd\long, |!|, + % |l| or |L|) + % and/or not to place the message issuer in the command + % (\inverb|.|, \inverb|q|, \inverb|Q|) and/or to make the + % environment ignore spaces following its end (|i|, |I|, |w|, |W| + % or \incmd\sphack), + m % the arguments specification (both for the begin and the + % end definitions), + m % the begin definition, + m % the end definition; it \emph{can} contain any + % \inverb|#|\---the arguments of the environment are passed + % to it, too. +}{% + \def\@dc@env@argstoend{% \label{@dc@env@argstoend} \UnDef + \edef + \@xa\@nx\csname \bslash#1(arguments)\endcsname + {\unexpanded{% + \@xa\@xa\@xa\unexpanded\@xa\@xa\@xa{\@xa\@gobble\the\@dc@arguments}% + }% of outer |\unexpanded|, + }% of |\edef|'s body. + % \nostanza Note that |\@dc@env@argstoend| will be put in an + % |\edef| and the arguments bearer it sets will be defined as custom for + % this particular environment (its name contains the name of the + % environment) and inside the environment's group + % and will bear a~list of tokens \arg{arg.1}{arg.2}\mch… not + % the \CS\ |\@dc@arguments| so it's robust to nested environments + % and even to \cs{DeclareEnvironment}'s occurrences inside the + % environment.\fullpar \nostanza + }% of |\@dc@env@argstoend|. + % + \def\gmu@reserveda{\envhack}% we add the information we define an + % environment. + \IfValueT{#2}% + {\addtomacro\gmu@reserveda{#2}}% we pass all the ‘prefixes’ to + % \incs{Decl\+are\+Comm\+and} + % \stanza + \@xa\DeclareCommand\csname#1\@xa\endcsname + \gmu@reserveda{#3}{#4}% + % + %\nostanza Now the begin definition is done. Let's get down to the + %end definition. \nostanza + % + \@dc@global@ % note this \CS was for sure redefined by the last + % \incs{Decl\+are\+Com\+m\+and} (and by nothing else) and that's + % exactly what we want. + \@nameedef{end#1}% It's |\edef| inside. + {\@nx\@xa\@xa\@nx\csname\bslash end#1\endcsname + \@xa\@nx\csname \bslash#1(arguments)\endcsname}% + % \nostanza We |\edef| the |\end|\ macro to be + % \[|\expandafter\\end⁄\\⁄(arguments)|\] + % (it's |\expandafter| and two control sequences, the latter with + % |(arguments)| in its name). + % + \IfIntersect{#2}{iIwW\sphack}% + {\@dc@global@\@xa\addtomacro + \csname end#1\endcsname{\@ignoretrue}}{}% + \edef\gmu@reserveda{% \UnDef + \@dc@global@\long\def % the inner end macro is always \incmd\long\ + % and perhaps defined \incmd\global ly. + \@xa\@nx\csname\bslash end#1\endcsname + \the\@temptokena% it's |#1#2#3›…|---the inner end macro takes the + % same number of parameters as the begin macro. + {% the definition body + % ^^A \IfNoValueTF{#1}% + % ^^A {\@dc@test@long\@nx#2{\the\@temptokena}}{}% + \unexpanded{#5}}% + }% of |\edef|. + \gmu@reserveda +} + + +% ^^A \unless\ifdefined\DeclareDocumentCommand +% ^^A \let\DeclareDocumentCommand\DeclareCommand +% ^^A \fi +% ^^A +% ^^A \unless\ifdefined\DeclareDocumentEnvironment +% ^^A \let\DeclareDocumentEnvironment\DeclareEnvironment +% ^^A \fi + + + +% \division{Ampulex Compressa-like modifications of macros} +% Ampulex Compressa is a~wasp that performs brain surgery on its +% victim cockroach to lead it to its lair and keep alive for its +% larva. Well, all we do here with the internal \LaTeX\ macros +% resembles Ampulex's actions but here is a~tool for a~replacement of +% part of macro's definition. +% +% The \cs{ampulexdef} command takes its |#2| which has to be a~macro +% and replaces part of its definition delimited with |#5| and |#6| +% with the replacement |#7|. The redefinition may be prefixed with +% |#1|. |#2| may have parameters and for such a~macro you have to set +% the parameters string and arguments string (the stuff to be taken by +% the one-step expansion of the macro) as the optional |[#3]| and +% |[#4]|. . If \cs{ampulexdef} doesn't find the start and end tokens +% in the meaning of the macro, it does nothing to it. You have to +% write |####| instead of |#| or you can use |\ampulexhash| as +% well. For an example use see line \ref{ampulexset}. -% \UnDef -{\def\:{\let\@sptoken= } \: % this makes |\@sptoken| a space token. -% \UnDef -\def\:{\@xifnif} \@xa\gdef\: {\futurelet\@let@token\@ifnif}} +%^^A \showthe\catcode`: +%^^A \showthe\catcode`_ +%^^A +%^^A \gmu@storespecials +%^^A +%^^A \RequirePackage{xparse}[2008/08/03] +%^^A +%^^A % This should not happen but well, it did: the catcodes changed the +%^^A % \pk{expl3} way leaked so I~fix them here. +%^^A \gmu@septify +%^^A \@makeother\: +%^^A \catcode`_=8 +%^^A \catcode`\ =10 -% \dekmedskip -% -% But how to peek at the next token to check whether it's an active -% char? First, we look with |\@ifnextcat| whether there stands a~group -% opener. We do that to avoid taking a~whole |{...}| as the argument -% of the next macro, that doesn't use |\futurelet| but takes the next -% token as an argument, tests it and puts back intact. -% \changes{v0.75}{2007/01/11}{added} -% -\long\pdef\@ifnextac#1#2{% - \@ifnextcat\bgroup{#2}{\gm@ifnac{#1}{#2}}} -\long\def\gm@ifnac#1#2#3{% - \ifcat\@nx~\@nx#3\afterfi{#1#3}\else\afterfi{#2#3}\fi} +\DeclareCommand\ampulexdef\long +{Q{\outer\long\global\protected} % (1) (optional) prefix\:(es); + % allowed is any sequence of them in any order, just like for the + % original \TeX's \incmd\def. + S{\def\edef\gdef\xdef\pdef} % (2) (optional) kind of definition; if + % not specified, \incmd\def\ will be used. + m % (3) macro to be redefined, + O{} % (4) \cs{def}'s parameters string; empty by default, + O{} % (5) definition body's parameters to be taken in a~one-step + % expansion of the redefined macro; empty by default, + m % (6) start token(s), + m % (7) end token(s) + m % (8) the replacement +}{%^^B + % \changes{v0.93}{2008/08/29}{added} + % \changes{v0.94}{2008/09/07}{made \pk{xparse}-ish and + % \cs{ampulexset} removed} + % \chgs{2008/12/7 v0.98 first argument (the prefix) made of the + % \env{Q} type} + % For the example of usage see \ref{ampulexset}. \HideDef + \def\gmu@tempa{#6}% + \def\gmu@tempb{#7}% + \def\gmu@tempc{#8}% we wrap the start, end and replacement tokens in + % macros to avoid unbalanced \incs{if}s. \ResumeDef + \edef\gmu@tempd{% + \long\def\@nx\gmu@tempd + ####1\detoken@xa\gmu@tempa + ####2\detoken@xa\gmu@tempb + ####3\@nx\gmu@tempd{% + \unexpanded{% \chgs[\ampulexdef]{2008/11/30 v0.98 a~bug fixed: + % added \cs{unexpanded}} + \@ifempty{##3}{\hidden@iffalse}{\hidden@iftrue}}}}% + % + \gmu@tempd% it defines \incs{gmu@tempc} to produce an open \incs{if} + % depending on whether the start and end token(s) are found in the + % meaning of \inverb|#3|. + % + \edef\gmu@tempe{% + \@nx\gmu@tempd\all@other#3% note that |#3| may have parameters so + % we have to look at its meaning not at its one-level expansion, + % which could produce an ‘extra \cmd\}’ error. + \detoken@xa\gmu@tempa + \detoken@xa\gmu@tempb\@nx\gmu@tempd + }% + % + \gmu@tempe% we apply the checker and it + % produces an open \incs{if}. + \edef\gmu@tempd{% + \long\def\@nx\gmu@tempd + ####1\@xa\unexpanded\@xa{\gmu@tempa}% + ####2\@xa\unexpanded\@xa{\gmu@tempb}% + ####3\@nx\ampulexdef{% we define a~temporary + % macro with the parameters delimited with the `start' and `end' parameters + % of \incs{ampulexdef}.\fullpar + \@nx\unexpanded{####1}% + \@nx\@xa\@nx\unexpanded + \@nx\@xa{\@nx\gmu@tempc}%we replace the part of the redefined + % macro's meaning with the replacement text. + \@nx\unexpanded{####3}}}% +%^^A\show\gmu@tempd + \gmu@tempd +%^^A\show\gmu@tempd + % + \edef\gmu@tempf{#5}% + \edef\gmu@tempe{% + \IfValueT{#1}{#1}\IfValueTF{#2}{#2}{\def}% + \@nx#3#4{% + \@xa\@xa\@xa\gmu@tempd\@xa#3\gmu@tempf\ampulexdef}}% + \gmu@tempe + \fi} -% Yes, it won't work for an active char |\let| to |{|${}_1$, but it -% \emph{will} work for an active char |\let| to a~char of -% catcode${}\neq1$. (Is there anybody on Earth who'd make an active -% char working as |\bgroup|?) -% -% \stanza Now, define a~test that checks whether the next token is -% a~genuine space, | |${}_{10}$ that is. First define -% a~\CS let such -% a~space. The assignment needs a~little trick (\TeXbook\ appendix D) -% since |\let|'s syntax includes one optional space after |=|. -% -\let\gmu@reserveda\*% -\def\*{% - \let\*\gmu@reserveda - \let\gm@letspace= }% -\* % +\def\ampulexhash{####}% for your convenience (not to count the hashes). -% \Define\@ifnextspace -\def\@ifnextspace#1#2{% - \let\gmu@reserveda\*% - \def\*{% - \let\*\gmu@reserveda - \ifx\@let@token\gm@letspace\afterfi{#1}% - \else\afterfi{#2}% - \fi}% - \futurelet\@let@token\*} -% First use of this macro is for an active |-| that expands to |---| -% if followed by a~space. Another to make dot checking whether is -% followed by |~| without gobbling the space if it occurs instead. +% For the heavy debugs I~was doing while preparing \pk{gmdoc}, as +% a~last resort I~used |\showlists|. But this command alone was +% usually too little: usually it needed setting |\showboxdepth| and +% |\showboxbreadth| to some positive values. So, % -% \stanza -% Now a~test if the next token is an active line end. I~use it in -% \pk{gmdoc} and later in this package for active long dashes. +\def\gmshowlists{\showboxdepth=1000 \showboxbreadth=1000 \showlists} +% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}} -\foone\obeylines{% - \long\pdef\@ifnextMac#1#2{% - \@ifnextchar^^M{#1}{#2}}} -% \division{\cs{afterfi} and pals} -% It happens from time to time that you have some sequence of macros -% in an |\if...| and you would like to expand |\fi| before expanding -% them (e.g., when the macros should take some tokens next to |\fi...| -% as their arguments. If you know how many macros are there, you may -% type a~couple of |\expandafter|s and not to care how terrible it -% looks. But if you don't know how many tokens will there be, you -% seem to be in a~real trouble. There's the Knuthian trick with -% |\next|. And here another, revealed to me by my \TeX\ Guru. -% -% I~think the situations when the Knuthian (the former) trick is not -% available are rather seldom, but they are imaginable at least: the -% |\next| trick involves an assignment so it won't work e.g.\ in -% |\edef|. -% -%^^A % One warning: those macros peel the braces off, i.e., -%^^A % \[|\if..\afterfi{\@makeother\^^M}\fi|\] -%^^A % causes a~leakage of -%^^A % |^^M|\catother. To avoid pollution write -%^^A % \[|\if..\afterfi{\bgroup\@makeother\^^M\egroup}\fi|\,.\] -% +\newcommand\nameshow[1]{\@xa\show\csname#1\endcsname} +\newcommand\nameshowthe[1]{\@xa\showthe\csname#1\endcsname} +% Note that to get proper |\showthe\my@dimen14| in the `other' |@|'s +% scope you write |\nameshowthe{my@dimen}14|\,. -\def\longafterfi{% - \long\def\afterfi##1##2\fi{\fi##1}} -\longafterfi -% And two more of that family: -\long\def\afterfifi#1#2\fi#3\fi{\fi\fi#1} -% \changes{v0.94}{2008/09/09}{\cs{if} removed from parameters' string} -\long\def\afteriffifi#1#2\fi#3\fi{\fi#1} -% Notice the refined elegance of those macros, that cover both `then' -% and `else' cases thanks to |#2| that is discarded. +% Standard |\string| command returns a~string of `other' chars except +% for the space, for which it returns | |$_{10}$. In \pk{gmdoc} +% I~needed the spaces in macros' and environments' names to be always +% \catother, so I~define +% \Define\xiistring +% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}} +\long\def\xiistring#1{% + \if\@nx#1\xiispace + \xiispace + \else + \afterfi{\string#1}% to make the same error as bare |\string| + % would cause in case of empty \inhash1. + \fi} -\long\def\afterififfififi#1#2\fi#3\fi#4\fi{\fi#1} -\long\def\afteriffififi#1#2\fi#3\fi#4\fi{\fi\fi#1} -\long\def\afterfififi#1#2\fi#3\fi#4\fi{\fi\fi\fi#1} +%The next macro is applied to a~|\detokenized| nonempty string to convert the spaces into +% ‘other’. \nostanza +\def\@xiispaces#1 #2\@@nil{% + #1% + \ifx\@xiispaces#2\@xiispaces + \else + \xiispace + \afterfi{\@xiispaces#2\@@nil}% + \fi} % \division{Environments redefined} @@ -1043,10 +2650,17 @@ pagella, fontspec=quiet]{gmdocc} % % \Define\@begnamedgroup \long\def\@begnamedgroup#1{% + \edef\@prevgrouplevel{\the\currentgrouplevel}% added 2009/03/24 to + % handle special pseudo-environments that don't increase + % \incmd\currentgrouplevel (such as \inenv{document}). Note it's + % |\edef|ed \emph{outside} the environment's group. \@ignorefalse% not to ignore blanks after group \begingroup\@endpefalse + \edef\@prevenvir{\@currenvir}% Note we |\edef| it inside the group + % (for obvious reason), unlike the ‘previous’ grouplevel. \edef\@currenvir{#1}% We could do recatcoding - % through\inverb|\string| but all the name `other' could affect + % through\inverb|\string| or \nlperc\cmd\detokenize\ but all the name + % `other' and 10 could affect % a~thousand packages so we don't do that and we'll recatcode in % a~testing macro, see line \ref{@ifenvir}. \edef\@currenvline{\on@line}% @@ -1058,8 +2672,8 @@ pagella, fontspec=quiet]{gmdocc} % Let us make it the starred version of |\begin|. % \begin{DoIndex}{\begin} % \Define\begin -% \Define*\begin* -\def\begin{\@ifstar{\@begnamedgroup}{% +% \Define*{\begin*} +\def\begin{\gm@ifstar{\@begnamedgroup}{% \@begnamedgroup@ifcs}} % \end{DoIndex} @@ -1080,7 +2694,7 @@ pagella, fontspec=quiet]{gmdocc} % is |\ifx|-equivalent |\@currenvir|. However, in standard \LaTeX\ it % works not quite as I~would expect: Since the idea of environment is % to open a~group and launch the \CS named in the |\begin|'s -% argument. That last thing is done with |\csname...\endcsname| so +% argument. That last thing is done with |\csname…\endcsname| so % the catcodes of chars are irrelevant (until they are |\active|, % ${}_1$, ${}_2$ etc.). Thus should be also in the |\end|'s test and % therefore we ensure the compared texts are both expanded and made @@ -1088,16 +2702,72 @@ pagella, fontspec=quiet]{gmdocc} % % First a~(not expandable) macro that checks whether current % environment is as given in |#1|. Why is this macro |\long|?---you -% may ask. It's |\long| to allow evironments such as |\string\par|. +% may ask. It's |\long| to allow environments such as |\string\par|. % -\long\def\@ifenvir#1#2#3{%\label{@ifenvir} +\long\def\@ifenvir#1{%\label{@ifenvir}\ + % \begin{enumargs} + % \mand enquired environment name which will be confronted with + % \incs{@currenvir} + % \mand what if true (if the names are + % equivalent\qfootnote{The names are checked whether they produce + % the same \cmd\csname. They don't have to have the same + % catcodes.}) + % \mand what if false + % \end{enumargs} + % % \changes{v0.92}{2008/08/07}{added} - \edef\gmu@reserveda{\@xa\string\csname\@currenvir\endcsname}% - \edef\gmu@reservedb{\@xa\string\csname#1\endcsname}% - \ifx\gmu@reserveda\gmu@reservedb\afterfi{#2}% - \else\afterfi{#3}% +\@ifedetokens{\@currenvir}{#1}} + + +\long\pdef\@ifedetokens#1#2{% + % \begin{enumargs} + % \item first list of tokens to be expanded and detokenized + % \item second list + % \item if agree + % \item else + % \end{enumargs} + % + % \chgs{2009/04/21 v0.99 moved to a~separate macro from + % \cmd\@ifenvir\ and made symmetric to both arguments} + % \chgs{2008/12/01 v0.98 rewritten not to make entries in the hash + % table, thanks to \cmd\detokenize\ and made robust to open \cs{if}s + % in the arguments thanks to substitution of explicit parameters + % with \cmd\@firstoftwo\ and \cmd\@secondoftwo} + \edef\gmu@tempa{#1}% to get |#1| fully expanded. + \edef\gmu@reserveda{\@xa\detokenize\@xa{\gmu@tempa}}% with our + % brave new \incs{begin}, \incs{@currenvir} is fully expanded, + % remember? + \edef\gmu@tempa{#2}% to get |#2| fully expanded. + \edef\gmu@reservedb{\@xa\detokenize\@xa{\gmu@tempa}}% + \ifx\gmu@reserveda\gmu@reservedb\@xa\@firstoftwo + \else\@xa\@secondoftwo \fi} +\def\@ifjobname#1{\@ifedetokens{\jobname}{#1}} + +\long\def\@ifprevenvir#1{%\label{@ifenvir}\ + % \begin{enumargs} + % \mand enquired environment name which will be confronted with + % \incs{@prevenvir} + % \mand what if true (if the names are + % equivalent\qfootnote{The names are checked whether they produce + % the same \cmd\csname. They don't have to have the same + % catcodes.}) + % \mand what if false + % \end{enumargs} + % + % \changes{v0.92}{2009/09/04}{added} +\@ifedetokens{\@prevenvir}{#1}} + + + +% Note that |\@ifjobname| and |\@ifenvir| are expandable and in an +% |\edef| they expand to +% \[|\@ifedetokens{⁄}{⁄}|\] and +% \[|\@ifedetokens{⁄}{⁄}|\] resp. which may be +% useful for some \TeX vert. + + \def\@checkend#1{\@ifenvir{#1}{}{\@badend{#1}}} % \changes{v0.92}{2008/08/07}{shortened thanks to \cs{@ifenvir}} % Thanks to it you may write |\begin{macrocode*}| with |*|\catother @@ -1111,11 +2781,31 @@ pagella, fontspec=quiet]{gmdocc} % also |\end{macrocode\star}| where |\star| is defined as `other' star % or letter star. +% \division{Storing and restoring the catcodes of specials} +% +% \Define\gmu@restorespecials +\DeclareCommand\gmu@storespecials{o}{% we provide a~possibility of + % adding stuff. For usage see line \ref{@storespecials}. + \def\do##1{\catcode`\@nx##1=\the\catcode`##1\relax}% + \edef\gmu@restorespecials{% + \dospecials\do\^^M}\IfValueT{#1}{#1}} + +\pdef\gmu@septify{% restoring the standard catcodes of specials. The + % name is the opposite of `sanitize' ^^A( + % :-)\,. It restores also the original catcode of \inverb|^^M|. + \def\do{\relax\catcode`}% + \do\ 10\do\\0\do\{1\do\}2\do\$3\do\&4% + \do\#6\do\^7\do\_8\do\%14\do\~13\do\^^M5\relax + %\nostanza |%% \let\do\@makeother|\\ + % |%% \do0\do1\do2\do3\do4\do5\do6\do7\do8\do9\relax|\nostanza +} + + %\division{From \pk{relsize}} % -%\changes{v0.58}{06/09/02}{Relative fontsize change macros added} +%\changes{v0.58}{06/09/02}{Relative font size change macros added} % % As file \pk{relsize.sty}, v3.1 dated July 4, 2003 states, \LaTeXe\ % version of these macros was written by Donald Arseneau @@ -1126,7 +2816,7 @@ pagella, fontspec=quiet]{gmdocc} % I~take only the basic, non-math mode commands with the assumption % that there are the predefined font sizes. % -% You declare the font size with \TextUsage\relsize\marg{n} where +% You declare the font size with \TextUsage\relsize\arg{n} where % \ gives the number of steps ("mag-step" = factor of 1.2) to % change the size by. E.g., $n = 3$ changes from |\normalsize| to % |\LARGE| size. Negative $n$ selects smaller fonts. @@ -1142,8 +2832,8 @@ pagella, fontspec=quiet]{gmdocc} \ifmmode \@nomath\relsize\else \begingroup \@tempcnta % assign number representing current font size - \ifx\@currsize\normalsize 4\else % funny order is to have most ... - \ifx\@currsize\small 3\else % ...likely sizes checked first + \ifx\@currsize\normalsize 4\else % funny order is to have most … + \ifx\@currsize\small 3\else % …likely sizes checked first \ifx\@currsize\footnotesize 2\else \ifx\@currsize\large 5\else \ifx\@currsize\Large 6\else @@ -1168,6 +2858,7 @@ pagella, fontspec=quiet]{gmdocc} \providecommand*\rs@size@warning[2]{\PackageWarning{gmutils (relsize)}{% Size requested is too #1.\MessageBreak Using #2 instead}} + \providecommand*\rs@unknown@warning{\PackageWarning{gmutils (relsize)}{Current font size is unknown! (Why?!?)\MessageBreak Assuming \string\normalsize}} @@ -1177,94 +2868,13 @@ pagella, fontspec=quiet]{gmdocc} \DeclareRobustCommand*\smaller[1][\@ne]{\relsize{-#1}} \DeclareRobustCommand*\textlarger[2][\@ne]{{\relsize{+#1}#2}} \DeclareRobustCommand*\textsmaller[2][\@ne]{{\relsize{-#1}#2}} -\pdef\largerr{\relsize{+2}} -\pdef\smallerr{\relsize{-2}} - - -% \division{Some `other' stuff} -% Here I~define a~couple of macros expanding to special chars made -% `other'. It's important the \CS are expandable and therefore -% they can occur e.g. inside |\csname...\endcsname| unlike e.g. -% \CS'es |\chardef|ed. -% -% \Define\subs -\foone{\catcode`\_=8 }% -{\let\subs=_} - -\foone{\@makeother\_}% -{\def\xiiunder{_}} - -\ifdefined\XeTeXversion - \def\xiiunder{\char"005F }% - \let\_\xiiunder -\fi - -\foone{\catcode`\[=1 \@makeother\{ - \catcode`\]=2 \@makeother\}}% -[% - \def\xiilbrace[{]% - \def\xiirbrace[}]% -]% of |\firstofone| - -% Note that \LaTeX's |\@charlb| and |\@charrb| are of catcode 11 -% (`letter'), cf. The \LaTeXe\ Source file k, lines 129--130. - - - -% Now, let's define such a~smart |_| (underscore) which will be usual -% |_|${}_8$ in the math mode and |_|\catother\ (`other') outside math. -% \Define\smartunder -% \changes{v0.60}{06/09/05}{\cs{\_} instead of \cs{xiiunder}} -\foone{\catcode`\_=\active} -{% - \newcommand*\smartunder{% - \catcode`\_=\active - \def_{\ifmmode\subs\else\_\fi}}}% We define it as |\_| not just as -% |\xiiunder| because some font encodings don't have |_| at the -% |\char`\_| position. -% -% \CodeEscapeChar\! -% \Define\bslash \Define\xiibackslash -\foone{\catcode`\!=0 - \@makeother\\} -{!newcommand*!xiibackslash{\}} -%^^A] balancing braces for Emacs -% \CodeEscapeChar\\ - -\let\bslash=\xiibackslash - - -% \begin{oldmc} -\foone{\@makeother\%} -{\def\xiipercent{%}} -% \end{oldmc} - -\foone{\@makeother\&}% -{\def\xiiand{&}} - -\foone{\@makeother\ }% -{\def\xiispace{ }} - -\foone{\@makeother\#}% -{\def\xiihash{#}} - -% We introduce \cs{visiblespace} from Will Robertson's \pk{xltxtra} if -% available. It's not sufficient |\@ifpackageloaded{xltxtra}| since -% \cs{xxt@visiblespace} is defined only unless |no-verb| option is -% set. 2008/08/06 I~recognized the difference between \cs{xiispace} -% which has to be plain `other' char (used in \cs{xiistring}) and -% something visible to be printed in any font. - -\AtBeginDocument{% - \ifdefined\xxt@visiblespace - \let\visiblespace\xxt@visiblespace - \else - \let\visiblespace\xiispace - \fi} +\pdef\largerr{\relsize{+2}} +\pdef\smallerr{\relsize{-2}} -%\division{Metasymbols} -% I~fancy also another Knuthian trick for typesetting \ + +%\division{Meta-symbols} +% I~fancy also another Knuthian trick for typesetting \ % in \TeXbook. So I~repeat it here. The inner |\meta| macro is % copied verbatim from \pk{doc}'s v2.1b documentation dated 2004/02/09 % because it's so beautifully crafted I~couldn't resist. I~only don't @@ -1273,7 +2883,7 @@ pagella, fontspec=quiet]{gmdocc} % % \begin{quotation} % The new implementation fixes this problem by defining -% |\meta| in a radically different way: we prevent hypenation by defining a |\language| +% |\meta| in a radically different way: we prevent hyphenation by defining a |\language| % which has no patterns associated with it and use this to typeset the words within % the angle brackets. % \end{quotation} @@ -1282,62 +2892,129 @@ pagella, fontspec=quiet]{gmdocc} %^^A~ \newlanguage\l@nohyphenation %^^A~\fi \pdef\meta#1{% -% \begin{quotation} -% Since the old implementation of |\meta| could be used in math we better ensure -% that this is possible with the new one as well. So we use |\ensuremath| around -% |\langle| and |\rangle|. However this is not enough: if |\meta@font@select| below -% expands to |\itshape| it will fail if used in math mode. For this reason we hide -% the whole thing inside an |\nfss@text| box in that case. -% \end{quotation} - \ensuremath\langle - \ifmmode \@xa \nfss@text \fi - {% + % \begin{quotation} + % Since the old implementation of |\meta| could be used in math we better ensure + % that this is possible with the new one as well. So we use |\ensuremath| around + % |\langle| and |\rangle|. However this is not enough: if |\meta@font@select| below + % expands to |\itshape| it will fail if used in math mode. For this reason we hide + % the whole thing inside an |\nfss@text| box in that case. + % \end{quotation} + {\meta@fontsetting\ensuremath\langle}% + \ifmmode\@xa\nfss@text\fi + {% this has to be a~begin-group because \incmd{\nfss@text} becomes + % \incmd\hbox\ in math mode. + \gmu@activespaceblank \meta@font@select -% Need to keep track of what we changed just in case the user changes font inside -% the argument so we store the font explicitly. -%^^A~% \DefIndex\meta@hyphen@restore -%^^A \edef\meta@hyphen@restore{% -%^^A \hyphenchar\the\font\the\hyphenchar\font}% -%^^A \hyphenchar\font\m@ne -%^^A \language\l@nohyphenation + % Need to keep track of what we changed just in case the user changes font inside + % the argument so we store the font explicitly. + % ^^A~% \DefIndex\meta@hyphen@restore + % ^^A \edef\meta@hyphen@restore{% + % ^^A \hyphenchar\the\font\the\hyphenchar\font}% + % ^^A \hyphenchar\font\m@ne + % ^^A \language\l@nohyphenation #1\/% -%^^A~ \meta@hyphen@restore - }\ensuremath\rangle + % ^^A~ \meta@hyphen@restore + }% + {\meta@fontsetting\ensuremath\rangle}% +}% of |\meta|. + +\pdef\gmu@activespaceblank{% + \@xa\def\gmu@activespace{\space\ignorespaces}% note the + % subtle perversity of this definition: if we meet more than one + % subsequent active spaces, then the first of them will + % typeset \incmd\space and its \incmd\ignorespaces\ will + % gobble \incmd\space\ of the second and will stop at + % \incs{ignorespaces} and this \incs{ignorespaces} will gobble + % the next \incs{space} and so on. } -% \DefIndex\meta@font@select +\def\meta@fontsetting{\color{red!50!black}} + +\def\meta@font@select{\meta@fontsetting\it} % \changes {v0.76}{06/9/21}{\cs{itshape} changed to an explicit and % violent \cs{it} to work as expected in \cs{cs}'s argument} % But I~define |\meta@font@select| as the brutal and explicit |\it| % instead of the original |\itshape| to make it usable e.g.\ in the % \pk{gmdoc}'s |\cs| macro's argument. -\def\meta@font@select{\it} -% The below |\meta|'s drag\footnote{Think of the drags that transform ^^B -% a~very nice but rather standard `auntie' (`Tante' in Deutsch) into ^^B( -% a~most adorable Queen ;-)\,.} is a~version of \TeXbook's one. -% \Define*{\<...>} + +% The below |\meta|'s drag\qfootnote{Think of the drags that transform +% a~very nice but rather standard `auntie' (`Tante' in Deutsch) into +% \balsmiley( a~most adorable Queen ;-)\,.} is a~version of +% \TeXbook's one. \Define*[\<⁄kern⁄string-3pt›…>]{\<›…>} \def\<#1>{\meta{#1}} +\pdef\metachar#1{\begingroup\metacharfont #1\endgroup} +\def\metacharfont{\meta@fontsetting\rm} + +% ^^A\gmshowlists + % \division{Macros for printing macros and filenames} % % First let's define three auxiliary macros analogous to |\dywiz| from % \pk{polski.sty}: a~shorthands for |\discretionary| that'll stick to % the word not spoiling its hyphenability and that'll won't allow -% a~linebreak just before nor just after themselves. The +% a~line break just before nor just after themselves. The % |\discretionary| \TeX\ primitive has three arguments: |#1| `before % break', |#2| `after break', |#3| `without break', remember? % \Define\discre \Define\discret -\def\discre#1#2#3{\leavevmode\kern0sp% +\pdef\discre#1#2#3{\leavevmode\kern0sp% \discretionary{#1}{#2}{#3}\penalty10000\hskip0sp\relax} -\def\discret#1{\leavevmode\kern0sp% - \discretionary{#1}{#1}{#1}\penalty10000\hskip0sp\relax} + +\pdef\discret#1{\discre{#1}{#1}{#1}} % A~tiny little macro that acts like |\-| outside the math mode and % has its original meaning inside math. -\def\:{\ifmmode\afterfi{\mskip\medmuskip}\else\afterfi{\discret{}}\fi} +\def\:{% + \ifmmode\afterfi{\mskip\medmuskip}% + \else\afterfi{\discre{\null}{}{}}% \incs{null} to get + % \incs{hyphenpenalty} not \incs{exhyphenpenalty}. + \fi} + + + +\let\gmu@discretionaryhyphen\- % for the cases when we don't redefine + % \incs\- but use \incs\UrlFix -\newcommand*{\vs}{\discre{\visiblespace}{}{\visiblespace}} + +\DeclareCommand\bihyphen{O{*}}{% a~redefinition of |\-| that makes it + % optional-argument to allow further hyphenation + \DeclareCommand\gmu@discretionaryhyphen{T{#1}ca}{% + \IfValueT{##2}{% + \@ifempty{##2}{}{% + \def\gmu@bihyphen@char{##2}}% + }% + \IfValueT{##3}{% + \@ifempty{##3}{}{% + \def\gmu@bihyphen@corr{##3}}% + }% + \IfValueTF{##1}\discre\discretionary + {% before break + \IfValueTF{##2}{% + \@ifempty{##2}{\gmu@bihyphen@char}{##2}% + }{% + \ifnum\hyphenchar\font>\z@ + \char\hyphenchar\font + \fi}}% end of before break + {%after break + \IfValueT{##3}{% + \@ifempty{##3}{\gmu@bihyphen@corr}{##3}% + }% + }% + {% without break + }% almost as in \TB: unlike \TB, we allow hyphenchars + % $\ge255$ as we are \XeTeX. + }% of |\DeclareCommand\-| + \gmu@storeifnotyet\-% original |\-| is a~\TeX's + % primitive, therefore we should store it. + \let\-\gmu@discretionaryhyphen + \let\@dischyph\gmu@discretionaryhyphen % to override \pk{framed.sty} +}% of |\bihyphen| + + +\relaxen\gmu@bihyphen@corr + +\pdef\vs{\discre{\visiblespace}{}{\visiblespace}} % Then we define a~macro that makes the spaces visible even if used in % an argument (i.e., in a~situation where re|\catcode|ing has no @@ -1349,7 +3026,7 @@ pagella, fontspec=quiet]{gmdocc} \ifx\relax#1\relax\else#1\fi \ifx\relax#2\relax\else\vs\penalty\hyphenpenalty\gm@pswords#2\@@nil\fi}% note % that in the recursive call of \incs{gm@pswords} the argument string is -% not extended with a~guardian space: it has been already by +% not extended with a~sentinel space: it has been already by % \incs{printspaces}.\ilrr \pdef\sfname#1{\textsf{\printspaces{#1}}} @@ -1386,24 +3063,114 @@ pagella, fontspec=quiet]{gmdocc} % calls |\ttfamily| not |\tt| to be usable in headings which are % boldface sometimes. % -% \Define\cs -\DeclareRobustCommand*{\cs}[2][\bslash]{{% - \def\-{\discretionary{{\rmfamily-}}{}{}}% - \def\{{\char`\{}\def\}{\char`\}}\ttfamily #1#2}} +% +\DeclareCommand\cs{O{\type@bslash\penalty\@M\hskip\z@skip}}{%\ + % \begin{enumargs} + % \dc O{\bslash} the control sequence's prefix, by default it's + % \inverb|\| allowing hyphenation of subsequent word, + % \dc m the control sequence or anything to be typeset in + % typewriter font. + % ^^A this argument is long to allow \inverb|\cmd\par| + % ^^A % that expands to |\cs{\string\par}| or so. + % \end{enumargs} + % \chgs{2008/12/12 v0.98 added \cs{verbatim@specials}} + % \chgs{2008/12/12 v0.98 made \cmd\- switch to \cmd\normalfont\ + % because \IMHO\ this underlines the fact that a~\CS\ belongs to the + % narrative. \cmd\hyphenchar\ set to 45 as in usual texts} + \begingroup + \ifdefined\verbatim@specials\verbatim@specials\fi + \edef\-{\discretionary{% + \ifdefined\gmv@hyphen\gmv@hyphen + \else\unexpanded{{\normalfont-}}% + \fi}{}{}}% + \def\{{\type@lbrace\yeshy}\def\}{\char`\}}% + \narrativett + \edef\narrativett@storedhyphenchar{\the\hyphenchar\font}% + \hyphenchar\font=\ifdefined\gmv@hyphenchar\gmv@hyphenchar + \else "A6 \fi + \cs@inner{#1}} + +\pdef\cs@inner#1#2{% + #1#2% + \hyphenchar\font=\narrativett@storedhyphenchar\relax + \endgroup} + +\def\narrativett{\ttfamily}% such name because I~introduce it to +% distinguish the narrative verbatims from the code in \pk{gmdoc}. -% \Define\env +\long\pdef\env{\cs[]} % \changes{v0.66}{06/09/29}{the braces removed} -\pdef\env#1{\cs[]{#1}} -% And for the special sequences like |^^A|: +% And for the special sequences like |^^A|:\nostanza \foone{\@makeother\^} - {\pdef\hathat#1{\cs[^^]{#1}}} + {\pdef\hathat{\cs[^^]}} + +\AtBeginDocument{% + \@ifpackageloaded{gmdoc}{\def\hash{\cs[\#]}}{}} + +% And one for encouraging line breaks e.g., before long verbatim words. +\def\possfil{\hfil\penalty1000\hfilneg} + +\def\possvfil{\vfil + \penalty\numexpr + \gmu@minnum{\clubpenalty+\widowpenalty}{9999}% + %^^A\gmu@maxnum + %^^A {\ifnum\widowpenalty<\@M + %^^A \gmu@minnum{\widowpenalty+1}{9999}\relax + %^^A \else1000% + %^^A \fi}% + %^^A {\ifnum\clubpenalty<\@M + %^^A \gmu@minnum{\clubpenalty+1}{9999}\relax + %^^A \else1000% + %^^A \fi}% + \relax % eaten by |\gmu@maxnum| + \relax % eaten by |\numexpr| + \vfilneg} + +\long\def\gmu@extremnum#1#2#3{%\ + % \begin{enumargs} + % \item inequality sign + % \item left side of comparison + % \item right side of comparison + % \end{enumargs} + \@xa\ifx\@firstofmany#3\@@nil\relax % this complicated test is to + % allow arguments beginning with some \incs{if⁄<…>} as in + % \incs{possvfil} e.g. + \@xa\@firstoftwo + \else\@xa\@secondoftwo + \fi + {#2}% + {% + \ifnum\numexpr#2\relax#1\numexpr#3\relax + \@xa\@firstoftwo + \else\@xa\@secondoftwo + \fi + {\gmu@extremnum#1{#2}}% + {\gmu@extremnum#1{#3}}% + }% +} +\def\gmu@maxnum{\gmu@extremnum>} +\def\gmu@minnum{\gmu@extremnum<} -% And one for encouraging linebreaks e.g., before long verbatim words. -% \Define\possfil -\newcommand*\possfil{\hfil\penalty1000\hfilneg} +% \division{Typesetting arguments and commands} +% +% We define a~conditional and iterating command \TextUsage\arg\ that +% in math mode does what it used to do was in math and outside math it +% typesets mandatory, optional and picture (parenthesed) and angled +% arguments and optional stars. You can +% write \[|\arg[gefilte]*(mit){baigele}|\] to get +% \[\hbox{\arg[gefilte]*{fisz}(mit){bajgele}}\] +% or even +% \[|\verb+\MoltoAdagio⁄⁄arg*{Dankgesang}[die Gottheit]+|\] +% (where |⁄⁄| is the escape char in verbatims) to +% get \[|\MoltoAdagio⁄arg*{Dankgesang}[die Gottheit]|\] (in +% der lydischen Tonart). +% +% For more complicated arguments configurations consider using +% \pk{gmdoc}'s environment \env{enumargs}. +% \stanza % The five macros below are taken from the \pk{ltxdoc.dtx}. % % \begin{quotation}|\cmd{\foo}| Prints |\foo| verbatim. It may be used inside moving @@ -1411,264 +3178,145 @@ pagella, fontspec=quiet]{gmdocc} % syntax. (This second form may even be used when |\foo| is % |\outer|).\end{quotation} % -% \Define\cmd -\def\cmd#1{\cs{\@xa\cmd@to@cs\string#1}} -% \DefIndex\cmd@to@cs + +\long\def\cmd#1{\@xa\cs\@xa{\@xa\cmd@to@cs\string#1}}% it has to be +% un\incs{protected}! It has so many \incmd\expandafter s to allow +% \inverb|\cmd\par| and still keep the \incmd\cs\ command ‘short’. + \def\cmd@to@cs#1#2{\char\number`#2\relax} +% \nostanza It can be short since it never gets actual control +% sequence as an argument only a~string of ‘other’ tokens (and maybe spaces). % |\marg{text}| prints \marg{text}, `mandatory argument'. % \Define\marg -\def\marg#1{{\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}} +\pdef\marg#1{{\narrativett\type@lbrace}\meta{#1}{\narrativett\char`\}}} % |\oarg{text}| prints \oarg{text}, `optional argument'. % Also |\oarg[text]| does that. +% \HideAllDefining % \Define\oarg -\def\oarg{\@ifnextchar[\@oargsq\@oarg} +\pdef\oarg{\@ifnextchar[\@oargsq\@oarg} %^^A] -\def\@oarg#1{{\ttfamily[}\meta{#1}{\ttfamily]}} -\def\@oargsq[#1]{\@oarg{#1}} +\pdef\@oarg#1{{\narrativett[}\meta{#1}{\narrativett]}} +\pdef\@oargsq[#1]{\@oarg{#1}} % |\parg{te,xt}| prints \parg{te,xt}, `picture mode argument'. % \Define\parg -\def\parg{\@ifnextchar(\@pargp\@parg} +\pdef\parg{\@ifnextchar(\@pargp\@parg} %^^A) -\def\@parg#1{{\ttfamily(}\meta{#1}{\ttfamily)}} +\def\@parg#1{{\narrativett(}\meta{#1}{\narrativett)}} \def\@pargp(#1){\@parg{#1}} -% But we can have all three in one command. -% \Define\arg -\AtBeginDocument{% - \let\math@arg\arg - \def\arg{\ifmmode\math@arg\else\afterfi{% - \@ifnextchar[%^^A] - \@oargsq{\@ifnextchar(%^^A) - \@pargp\marg}}\fi}% -} - -% Now you can write -%\begin{verse} -% |\arg{mand. arg}| to get \arg{mand. arg},\\ -% |\arg[opt. arg]| for \arg[opt. arg] and\\ -% |\arg(pict. arg)| for \arg(pict. arg).\\ -% And |$\arg(1+i) = \pi/4$| for $\arg(1+i) = \pi/4$. -% \end{verse} -% - -% \division{Storing and restoring the meanings of \CSs} -% -% First a~Boolean switch of globalness of assignments and -% its verifier. -\newif\ifgmu@SMglobal - -\pdef\SMglobal{\gmu@SMglobaltrue} -% The subsequent commands are defined in such a~way that you can -% `prefix' them with |\SMglobal| to get global (re)storing. -% \stanza -% A~command to store the current meaning of a~\CS in another macro to -% temporarily redefine the \CS and be able to set its original meanig -% back (when grouping is not recommended): -% -%\Define\StoreMacro -%\changes{v0.61}{06/09/05}{added.} -%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} -\pdef\StoreMacro{% - \begingroup\makeatletter\@ifstar\egStore@MacroSt\egStore@Macro} -% The unstarred version takes a~\CS and the starred version -% a~text, which is intended for special control sequences. For storing -% environments there is a~special command in line \ref{StoreEnvironment}. - -\long\def\egStore@Macro#1{\endgroup\Store@Macro{#1}} -\long\def\egStore@MacroSt#1{\endgroup\Store@MacroSt{#1}} - -\long\def\Store@Macro#1{% - \escapechar92 - \ifgmu@SMglobal\afterfi\global\fi - \@xa\let\csname /gmu/store\string#1\endcsname#1% - \global\gmu@SMglobalfalse} - - -\long\def\Store@MacroSt#1{% - \edef\gmu@smtempa{% - \ifgmu@SMglobal\global\fi - \@nx\let\@xa\@nx\csname/gmu/store\bslash#1\endcsname%\label{SMbslash} - % we add backslash because to ensure compatibility between - % \incs{(Re)StoreMacro} and \incs{(Re)StoreMacro*}, that is. to allow - % writing e.g. \inverb|\StoreMacro\kitten| and then - % \inverb|\RestoreMacro*{kitten}| to restore the meaning of - % \incs{kitten}.\ilrr - \@xa\@nx\csname#1\endcsname} - \gmu@smtempa - \global\gmu@SMglobalfalse}% we wish the globality to be just - % once.\par - -% We make the |\StoreMacro| command a~three-step to allow usage of the -% most inner macro also in the next command. -% -% The starred version, |\StoreMacro*| works with csnames (without the -% backslash). It's first used to store the meanings of robust -% commands, when you may need to store not only |\foo|, but also -% |\csname foo \endcsname|. -% -% -% The next command iterates over a~list of \CSs and stores each of -% them. The \CS may be separated with commas but they don't have to. -% \Define\StoreMacros +\pdef\aarg{\@ifnextchar<\@aarga\@aarg} +\def\@aarg#1{{\narrativett<}\meta{#1}{\narrativett>}} +\def\@aarga<#1>{\@aarg{#1}} -\long\pdef\StoreMacros{\begingroup\makeatletter\Store@Macros} -\long\def\Store@Macros#1{\endgroup - \gmu@setsetSMglobal - \let\gml@StoreCS\Store@Macro - \gml@storemacros#1.} -% \label{InnerStore} +\def\@verbaarga#1#2>{\@aarg{#2}\arg@dc} -\def\gmu@setsetSMglobal{% - \ifgmu@SMglobal - \let\gmu@setSMglobal\gmu@SMglobaltrue - \else - \let\gmu@setSMglobal\gmu@SMglobalfalse - \fi} +\foone{\catcode`>\active}{% + \def\@verbaargact#1#2>{\@aarg{#2}\arg@dc}% +} -% And the inner iterating macro: -\long\def\gml@storemacros#1{% - \def\gmu@reserveda{\@nx#1}% My \TeX\ Guru's trick to deal with |\fi| - % and such, i.e., to hide |#1| from \TeX\ when it is processing a~test's - % branch without expanding. - \if\gmu@reserveda.% a~dot finishes storing. - \global\gmu@SMglobalfalse - \else - \if\gmu@reserveda,% The list this macro is put before may - % contain commas and that's O.K., we just continue the work. - \afterfifi\gml@storemacros - \else% what is else this shall be stored. - \gml@StoreCS{#1}% we use a~particular \CS to may |\let| it both to - % the storing macro as above and to the restoring one as - % \gmiflink[letRestore]{below}. - \afterfifi{\gmu@setSMglobal\gml@storemacros}% +\foone{\@makeother\{\@makeother\}% + \catcode`[=\@ne\catcode`]=\tw@} +[% ^^A{ + \def\@verbmargm#1#2}[% for an argument in curly braces in a verbatim, where + % the braces are not groupers and not necessary ‘other’. We'll know + % by \incmd{\@ifnextif} that the future token is an opening + % brace. Note this macro has 2nd parameter delimited with ‘other’ + % closing brace (so may not act correctly when braces are nested + % (then hide them with special verbatim groupers)). + \marg[#2]% + \arg@dc + ]% +]% of |\foone| + +% \ResumeAllDefining +\DeclareCommand\arg@dc!{% + % \chgs{200/03/04 v0.991 added rcognising of verbatim braces and + % angles} + s % (1) + o % (2) + c % (3) + b % (4) + a % (5) + S{\arg} % (6) just gobbled (for backwards compatibility) +}{% This command iterates while it + % has arguments and typesets them in brackets, parentheses or curly + % braces. Note it gobbles subsequent |\arg|s and just iterates. + \def\next{0}% + \IfValueT{#1}% + {\metachar[\scanverb{*}\metachar]\def\next{1}}% + \IfValueT{#2}{\@oarg{#2}\def\next{1}}% + \IfValueT{#3}{\@parg{#3}\def\next{1}}% + \IfValueT{#4}{\marg{#4}\def\next{1}}% + \IfValueT{#5}{\aarg{#5}\def\next{1}}% + \@ifnextchar\egroup{\endgroup}{% + \if1\next\@xa\arg@dc + \else % it's crucial that we look for verbatim braces \emph{after} + % we checked there were no \inhash4, otherwise there would + % be an error. + \def\next{% + \@ifnextif\xiilbrace{\@verbmargm}% + {% not active or other lbrace + \@ifnextif<{% then we look for angles + \ifnum\catcode`>=\active + \@xa\@verbaargact + \else\@xa\@verbaarga + \fi}% + {% and if not angles neither verbatim braces, then + \endgroup % if we have no more arguments to typeset, we + % close the group opened in line \ref{queer.group} + }% + }% + }% + \@xa \next \fi - \fi} - -% And for the restoring -%\Define\RestoreMacro -%\changes{v0.61}{06/09/05}{added.} -%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} -\pdef\RestoreMacro{% - \begingroup\makeatletter\@ifstar\egRestore@MacroSt\egRestore@Macro} - -\long\def\egRestore@Macro#1{\endgroup\Restore@Macro{#1}} -\long\def\egRestore@MacroSt#1{\endgroup\Restore@MacroSt{#1}} - -\long\def\Restore@Macro#1{% - \escapechar92 - \ifgmu@SMglobal\afterfi\global\fi - \@xa\let\@xa#1\csname /gmu/store\string#1\endcsname - \global\gmu@SMglobalfalse} - -\long\def\Restore@MacroSt#1{% - \edef\gmu@smtempa{% - \ifgmu@SMglobal\global\fi - \@nx\let\@xa\@nx\csname#1\endcsname - \@xa\@nx\csname/gmu/store\bslash#1\endcsname}% cf. the commentary - % in line \ref{SMbslash}. - \gmu@smtempa - \global\gmu@SMglobalfalse} - -% \Define\RestoreMacros -\long\pdef\RestoreMacros{\begingroup\makeatletter\Restore@Macros} - -\long\def\Restore@Macros#1{\endgroup - \gmu@setsetSMglobal - \let\gml@StoreCS\Restore@Macro% \gmhypertarget[letRestore]{we} - % direct the core \CS towards restoring and call the same iterating - % macro as in line \ref{InnerStore}. - \gml@storemacros#1.} -% As you see, the |\RestoreMacros| command uses the same iterating -% macro inside, it only changes the meaning of the core macro. - -% And to restore \emph{and} use immediately: -%\changes{v0.67}{06/10/11}{enriched with \cs{makeatletter}} -\def\StoredMacro{\begingroup\makeatletter\Stored@Macro} -\long\def\Stored@Macro#1{\endgroup\Restore@Macro#1#1} - -% To be able to call a~stored \CS without restoring it. -\def\storedcsname#1{%% \changes{v0.88}{2008/08/03}{added} - \csname /gmu/store\bslash#1\endcsname} - - -% 2008/08/03 we need to store also an environment. -\pdef\StoreEnvironment#1{% \label{StoreEnvironment} -% \changes{v0.88}{2008/08/03}{added} - \StoreMacro*{#1}\StoreMacro*{end#1}} - -\pdef\RestoreEnvironment#1{% -% \changes{v0.88}{2008/08/03}{added} - \RestoreMacro*{#1}\RestoreMacro*{end#1}} - + }% of not egroup +}% of |\arg@dc| -% It happended (see the definition of |\@docinclude| in \pk{gmdoc.sty}) -% that I~needed to |\relax| a~bunch of macros and restore them after -% some time. Because the macros were rather numerous and I~wanted the -% code more readable, I~wanted to |\do| them. After a~proper defining -% of |\do| of course. So here is this proper definition of |\do|, -% provided as a~macro (a~declaration). -% -% \Define\StoringAndRelaxingDo -% \changes{v0.59}{06/09/04}{added for storing index-related macros in -% \pk{gmdoc}'s \cs{DocInclude}.} -% \changes{v0.61}{06/09/05}{renamed from \cs{MacroStoringDo} and the -% storing cs's prefix changed from \cs[]{@gml@srs}.} -\long\def\StoringAndRelaxingDo{% - \gmu@SMdo@setscope - \long\def\do##1{% - \gmu@SMdo@scope - \@xa\let\csname /gmu/store\string##1\endcsname##1% - \gmu@SMdo@scope\let##1\relax}} -\def\gmu@SMdo@setscope{% - \ifgmu@SMglobal\let\gmu@SMdo@scope\global - \else\let\gmu@SMdo@scope\relax - \fi - \global\gmu@SMglobalfalse} - -% And here is the counter-definition for restore. -% -% \Define\RestoringDo -% \changes{v0.59}{06/09/04}{added for restoring index-related macros in -% \pk{gmdoc}'s \cs{DocInclude}.} -% \changes{v0.61}{06/09/05}{renamed from \cs{MacroRestoringDo} and -% relaxing of the storing cs removed.} -\long\def\RestoringDo{% - \gmu@SMdo@setscope - \long\def\do##1{% - \gmu@SMdo@scope - \@xa\let\@xa##1\csname /gmu/store\string##1\endcsname}} -% Note that both |\StoringAndRelaxingDo| and |\RestoringDo| are -% sensitive to the |\SMglobal| `prefix'. +% Now define the front-end macro of the |\arg| command:\nostanza +\foone{\obeylines}{% + \AtBeginDocument{% + \let\math@arg\arg % + \pdef\arg{\ifmmode\math@arg % + % \chgs{200/03/04 v0.991 added rcognising of verbatim braces and angles} + \else\afterfi{% + \begingroup % + % \label{queer.group} + \ifdefined\@ifQueerEOL\@ifQueerEOL{% + \def^^M{\unskip\space}% in the ‘queer’ \ac{EOL}s scope we + % keep line end active in case we have + % \incmd\arg\nlpercent\arg{arg.} ending a~line: the next + % char peeper touches line end or, if the line end was $_5$, + % gobbles the space it turns into so the comment layer would + % ‘leak’ to the code layer. + }{}\fi % + \arg@dc}% + \fi}% of |\arg|, + }% of |\AtBeginDocument|, +}% of |\foone|. +% \chgs{2008/12/07 v0.98 made iterating thanks to \cmd\DeclareCommand\cs{arg@dc}} -% And to store a~cs as explicitly named cs, i.e. to |\let| one csname -% another (|\n@melet| not |\@namelet| becasuse the latter is defined -% in Till Tantau's \pk{beamer} class another way) (both arguments -% should be text): -\def\n@melet#1#2{% - \edef\gmu@nl@reserveda{% - \let\@xa\@nx\csname#1\endcsname - \@xa\@nx\csname#2\endcsname}% - \gmu@nl@reserveda} -% The |\global| prefix doesn't work with |\n@melet| so we define the -% alternative. -\def\gn@melet#1#2{% - \edef\gmu@nl@reserveda{% - \global\let\@xa\@nx\csname#1\endcsname - \@xa\@nx\csname#2\endcsname}% - \gmu@nl@reserveda} +% Now you can write +%\begin{verse} +% |\arg{mand.\ arg} [opt.\ arg] (pict.\ arg)| \\ +% to get \arg{mand.\ arg} [opt.\ arg] (pict.\ arg). (Yes, with only one |\arg|!)\\ +% And |$\arg(1+i) = \pi/4$| for $\arg(1+i) = \pi/4$. +% \end{verse} +% +\DeclareCommand\cat{Q{'"0123456789ABCDEF}}{% + ${}_{\the\numexpr#1}\m@th$\@ifnextcat a\space{}} % \division{Not only preamble!} % Let's remove some commands from the list to erase at begin document! % Primarily that list was intended to save memory not to forbid % anything. Nowadays, when memory is cheap, the list of only-preamble -% commands should be rethought \IMO. +% commands should be rethought \IMHO. % \Define\not@onlypreamble @@ -1706,29 +3354,29 @@ pagella, fontspec=quiet]{gmdocc} % change makes any two \CS's |\ifx|-different. The first it % causes a~problem with is standard \LaTeX's |\nocite| that checks % |\ifx\@onlypreamble\document|. So hoping this is a~rare problem, we -% circumvent in with. 2008/08/29 a~bug is reported by Edd Barrett that +% circumvent it. 2008/08/29 a~bug is reported by Edd Barrett that % with \pk{natbib} an `extra \}' error occurs so we wrap the fix in % a~conditional. - +% % \changes[\nocite]{v0.93}{2008/08/29}{a~bug fixed: with \pk{natbib} % an `extra \}' error. Now it fixes only the standard version of % \cs{nocite}} \def\gmu@nocite@ampulex{% we wrap the stuff in a~macro to hide an open - % \incs{if}. And not to make the begin-input hook not too large. - % \label{ampulexset} the first is the + % \incs{if}. And not to make the begin-input hook too large. + % \label{ampulexset} the first optional argument is the % parameters string and the second the argument for one-level - % expansion of \incs{nocite} so it has to consist of two times less - % hashes than the first. Both hash strings are doubled to pass the - % first \incs{def}. - \ampulexdef[]\nocite[####1][{{####1}}]% note the double brace - % around \inverb|#3|. + % expansion of \incs{nocite}. Both hash strings are doubled to pass + % the % first \incs{def}. + \ampulexdef\nocite[####1][{{####1}}]% note the double brace + % around \inhash3. \ifx {\@onlypreamble\document}% \iftrue} -\AtBeginDocument\gmu@nocite@ampulex + +\AtBeginDocument{\gmu@nocite@ampulex}% % \division{Third person pronouns} @@ -1736,41 +3384,56 @@ pagella, fontspec=quiet]{gmdocc} % Is a~reader of my documentations `she' or 'he' and does it make % a~difference? % -% Not to favour any gender in the personal pronouns, define -% commands that'll print alternately masculine and feminine -% pronoun of third person. By `any' I~mean not only typically -% masculine and typically feminine but the entire amazingly rich -% variety of people's genders, \emph{including} those who do not -% describe themselves as `man' or `woman'. -% -% One may say two pronouns -% is far too little to cover this variety but I~could point Ursula's -% K.\ LeGuin's \textit{The Left Hand Of Darkness} as another acceptable -% answer. In that moody and moderate SF novel the androgynous -% persons are usually referred to as `mister', `sir' or `he': the -% meaning of reference is extended. Such an extension also my -% automatic pronouns do suggest. It's \emph{not} political -% correctness, it's just respect to people's diversity. -% \DefIndex*{gm@PronounGender} -% \let\do\Define -% \do\gm@atppron \do\heshe \do\hisher \do\himher \do\hishers -% \do\HeShe \do\HisHer \do\HimHer \do\HisHers -\newcounter{gm@PronounGender} - -\newcommand*\gm@atppron[2]{% - \stepcounter{gm@PronounGender}% remember |\stepcounter| is global. - \ifodd\value{gm@PronounGender}#1\else#2\fi} - -\newcommand*\heshe{\gm@atppron{he}{she}} -\newcommand*\hisher{\gm@atppron{his}{her}} -\newcommand*\himher{\gm@atppron{him}{her}} -\newcommand*\hishers{\gm@atppron{his}{hers}} - -\newcommand*\HeShe{\gm@atppron{He}{She}} -\newcommand*\HisHer{\gm@atppron{His}{Her}} -\newcommand*\HimHer{\gm@atppron{Him}{Her}} -\newcommand*\HisHers{\gm@atppron{His}{Hers}} +% Previous versions of this documentation were consequently +% alternating ’he’ and ’she’ and provided specific macros for that +% purpose. Now I'm not that queer and gender so I take what is +% normally used, ’they’ that is. +% +% (The issue of human sexes and genders (certainly much more numerous +% than 2) is complex and delicate and a \TeX\ macro package is +% probably not the best place to discuss it.) +% ^^A % Not to favour any gender in the personal pronouns, define +% ^^A % commands that'll print alternately masculine and feminine +% ^^A % pronoun of third person. By `any' I~mean not only typically +% ^^A % masculine and typically feminine but the entire amazingly rich +% ^^A % variety of people's genders, \emph{including} those who do not +% ^^A % describe themselves as `man' or `woman'. +% ^^A % +% ^^A % One may say two pronouns +% ^^A % is far too little to cover this variety but I~could point Ursula's +% ^^A % K.\ LeGuin's \textit{The Left Hand Of Darkness} as another acceptable +% ^^A % answer. In that moody and moderate \acro{SF} novel the androgynous +% ^^A % persons are usually referred to as `mister', `sir' or `he': the +% ^^A % meaning of reference is extended. Such an extension also my +% ^^A % automatic pronouns do suggest. It's \emph{not} political +% ^^A % correctness, it's just respect to people's diversity. +% ^^A % \DefIndex*{gm@PronounGender} +% ^^A % \let\do\Define +% ^^A % \do\gm@atppron \do\heshe \do\hisher \do\himher \do\hishers +% ^^A % \do\HeShe \do\HisHer \do\HimHer \do\HisHers +% ^^A \newcounter{gm@PronounGender} ^^A ^^A +% ^^A \newcommand*\gm@atppron[2]{% +% ^^A +% ^^A \stepcounter{gm@PronounGender}% remember |\stepcounter| is global. +% ^^A \ifodd\value{gm@PronounGender}#1\else#2\fi} +% ^^A \newcommand*\heshe{\gm@atppron{he}{she}} +% ^^A \newcommand*\hisher{\gm@atppron{his}{her}} +% ^^A \newcommand*\himher{\gm@atppron{him}{her}} +% ^^A \newcommand*\hishers{\gm@atppron{his}{hers}} +% ^^A \newcommand*\HeShe{\gm@atppron{He}{She}} +% ^^A \newcommand*\HisHer{\gm@atppron{His}{Her}} +% ^^A \newcommand*\HimHer{\gm@atppron{Him}{Her}} +% ^^A \newcommand*\HisHers{\gm@atppron{His}{Hers}} + +\def\heshe{they} +\def\hisher{their} +\def\himher{them} +\def\hishers{theirs} +\def\HeShe{They} +\def\HisHer{Their} +\def\HimHer{Them} +\def\HisHers{Theirs} % \division{Improvements to \pk{mwcls} sectioning commands} % @@ -1879,7 +3542,7 @@ pagella, fontspec=quiet]{gmdocc} \protected@edef\HeadingNumber{\csname the#1\endcsname\relax}% \else \let\HeadingNumber\@empty - \gm@hyperrefstepcounter + % ^^A \gm@hyperrefstepcounter it's nonsense \fi% of |\ifHeadingNumbered| %% \if\mw@HeadingRunIn @@ -1954,7 +3617,7 @@ pagella, fontspec=quiet]{gmdocc} \def\mw@secdef#1#2#3#4{% ^^B % \begin{enumargs} % \item the heading name, -% \item the command distinctor, +% \item the command distincter, % \item the meaning, % \item the number of argument to error message. % \end{enumargs} @@ -2097,23 +3760,25 @@ pagella, fontspec=quiet]{gmdocc} % my employer, ``Wiedza Powszechna'' Editions. \@ifnotmw{}{% We define this declaration only when in \pk{mwcls}. -\def\WPheadings{% +\DeclareCommand\WPheadings{T{\chapter}}{% \SetSectionFormatting[breakbefore,wholewidth] {part}{\z@\@plus1fill}{}{\z@\@plus3fill}% % - \gm@ifundefined{chapter}{}{% - \SetSectionFormatting[breakbefore,wholewidth] + \IfValueF{#1}{% + \gm@ifundefined{chapter}{}{% + \SetSectionFormatting[breakbefore,wholewidth] {chapter} {66\p@}% |{67\p@}|% for Adventor/Schola 0,95. {\FormatHangHeading{\LARGE}} {27\p@\@plus0,2\p@\@minus1\p@}% - }% - % + }% + }% of unless |#1| + % \SetTwoheadSkip{section}{27\p@\@plus0,5\p@}% \SetSectionFormatting{section} {24\p@\@plus0,5\p@\@minus5\p@}% ^^A {24\p@\@plus5\p@\@minus2\p@} {\FormatHangHeading {\Large}} - {10\p@\@plus0,5\p@}% ed. Krajewska of ``Wiedza Powszechna'', as + {10\p@\@plus0,5\p@}% ed.\ Krajewska of ``Wiedza Powszechna'', as % we understand her, wants the skip between a~heading and text % to be rigid. % @@ -2187,16 +3852,17 @@ pagella, fontspec=quiet]{gmdocc} % handle \pk{mwcls}-like sectionings i.e., those written with two % optionals. \def\gm@secini{gm@la}% + \StoreMacros{\partmark\chaptermark\sectionmark\subsectionmark\subsubsectionmark\paragraphmark}% % \Define\gm@secxx \def\gm@secxx#1#2[#3]#4{% \ifx\gm@secstar\@empty - \n@melet{gm@true@#1mark}{#1mark}% a~little trick to allow + % \nostanza a~little trick to allow % a~special version of the heading just to the running head. \@namedef{#1mark}##1{% we redefine \cs{\mark} to gobble its % argument and to launch the stored true marking command on the % appropriate argument. - \csname gm@true@#1mark\endcsname{#2}% - \n@melet{#1mark}{gm@true@#1mark}% after we've done what we + \storedcsname{#1mark}{#2}% + \RestoreMacro*{#1mark}% after we've done what we % wanted we restore original |\#1mark|.\ilrr }% \def\gm@secstar{[#3]}% if |\gm@secstar| @@ -2232,7 +3898,7 @@ pagella, fontspec=quiet]{gmdocc} % command because someone may test it. \n@melet{\gm@secini#1}{#1}% \@namedef{#1}{% - \@ifstar{\def\gm@secstar{*}\gm@sec{#1}}{% + \gm@ifstar{\def\gm@secstar{*}\gm@sec{#1}}{% \def\gm@secstar{}\gm@sec{#1}}}}% }% @@ -2298,7 +3964,9 @@ pagella, fontspec=quiet]{gmdocc} \let\oldLaTeX\LaTeX \let\oldLaTeXe\LaTeXe -\def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@} +\pdef\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@} +\StoreMacro\TeX +\AtBeginDocument{\RestoreMacro\TeX} \newcommand*\DeclareLogo[3][\relax]{% \begin{enumargs*} % \opt is for non-\LaTeX\ spelling and will be used in the @@ -2322,7 +3990,7 @@ pagella, fontspec=quiet]{gmdocc} % \DeclareDefining\DeclareLogo \DeclareLogo\LaTeX{% {% -%^^A\typeout{***** LaTeX logo of GM ^^J}\show\relax + % ^^A\typeout{***** LaTeX logo of GM ^^J}\show\relax L% \setbox\z@\hbox{\check@mathfonts \fontsize\sf@size\z@ @@ -2331,7 +3999,8 @@ pagella, fontspec=quiet]{gmdocc} \kern-.57\wd\z@ \sbox\tw@ T% \vbox to\ht\tw@{\copy\z@ \vss}% - \kern-.2\wd\z@}% originally $-,15$\,em for T. + \kern-.2\wd\z@% originally $-,15$\,em for T. + }% {% \ifdim\fontdimen1\font=\z@ \else @@ -2430,10 +4099,10 @@ pagella, fontspec=quiet]{gmdocc} \lower.5ex\hbox{E}\kern-.1667em\relax}{% \lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\relax}% \LaTeX}} -% As you see, if \TeX\ doesn't recognize \nlpercent\cs{re\+flect\+box} +% As you see, if \TeX\ doesn't recognise \cs{reflectbox} % (\pk{graphics} isn't loaded), the first |E| will not be reversed. % This version of the command is intended for non-\XeTeX\ usage. With -% \XeTeX, you can load the \pk{xltxtra} package (e.g. with the +% \XeTeX, you can load the \pk{xltxtra} package (e.g.\ with the % \pk{gmutils} |\XeTeXthree| declaration) and then the reversed |E| % you get as the Unicode Latin Letter Reversed E. @@ -2441,52 +4110,52 @@ pagella, fontspec=quiet]{gmdocc} % \changes{v0.96}{2008/10/10}{added} % \division{Expandable turning stuff all into `other'} +% ^^A +% ^^A % While typesetting a~Unicode file contents with \pk{inputenc} package +% ^^A % I~got a~trouble with some Unicode sequences that expanded to +% ^^A % unexpandable \CSs: they couldn't be used within +% ^^A % |\csname…\endcsname|. My \TeX Guru advised to use |\meaning| to +% ^^A % make all the name `other'. So---here we are. +% ^^A % +% ^^A % Don't use them in |\edef|s, they would expand not quite. +% ^^A % \Define\unex@namedef \Define\unex@nameuse +% ^^A +% ^^A + +% A shorthand. Note that it takes an undelimited argument not +% requires \. + +\long\def\detoken@xa#1{\detokenize\@xa{#1}} + +% The next macro originates from the ancient era when I didn't know +% about \eTeX's |\detokenize|. A try to redefine it to +% |\detokenize\@xa{#1}| resulted in error so (v0.991) I leave it and +% use as is. +% +% Note however it acts different than |\detoken@xa| for a macro with +% parameters: while |\detoken@xa| produces and ‘extra |}|’ error, +% |\all@other| expands to the detokenised meaning. \Define\all@other + \long\def\all@other#1{\@xa\gm@gobmacro\meaning#1} + + % The |\gm@gobmacro| macro above is applied to gobble the |\meaning|'s + % beginning, |long macro:->| all `other' that is. + % \Define\gm@gobmacro + \edef\gmu@tempa{% + \def\@nx\gm@gobmacro##1\@xa\@gobble\string\macro:##2->{}} + \gmu@tempa -% While typesetting a~unicode file contents with \pk{inputenc} package -% I~got a~trouble with some Unicode sequences that expanded to -% unexpandable \CSs: they could'nt be used within -% |\csname...\endcsname|. My \TeX Guru advised to use |\meanig| to -% make all the name `other'. So---here we are. -% -% Don't use them in |\edef|s, they would expand not quite. -% \Define\unex@namedef \Define\unex@nameuse - - -% The next macro is intended to be put in |\edef|s with a~macro -% argument. The meaning of the macro will be made all `other' and the -% words '(long) macro:->' gobbled. -%\Define\all@other -\long\def\all@other#1{\@xa\gm@gobmacro\meaning#1} - -% The |\gm@gobmacro| macro above is applied to gobble the |\meaning|'s -% beginnig, |long macro:->| all `other' that is. Use of it: -% \Define\gm@gobmacro -\edef\gmu@tempa{% - \def\@nx\gm@gobmacro##1\@xa\@gobble\string\macro:##2->{}} -\gmu@tempa - -%^^A % In the next two macros' names, `unex' stands both for not expanding -%^^A % the argument(s) and for disastrously partial unexpandability of the -%^^A % macros themselves. -%^^A -%^^A \long\def\unex@namedef#1#2{% -%^^A \edef@other\gmu@reserveda{#1}% -%^^A \@xa\long\@xa\def\csname\gmu@reserveda\endcsname{#2}} -%^^A -%^^A -%^^A \long\def\unex@nameuse#1{% -%^^A \edef@other\gmu@reserveda{#1}% -%^^A \csname\gmu@reserveda\endcsname} % \division{Brave New World of \XeTeX} -\newcommand\@ifXeTeX[2]{% +\def\@ifXeTeX{% two-argument command \ifdefined\XeTeXversion - \unless\ifx\XeTeXversion\relax\afterfifi{#1}\else\afterfifi{#2}\fi - \else\afterfi{#2}\fi} + \unless\ifx\XeTeXversion\relax\afterfifi\@firstoftwo\else\afterfifi\@secondoftwo\fi + \else\afterfi\@secondoftwo\fi} +\def\XeTeXifprefix{% to be used as prefix to an |\if›…| test. + \@ifXeTeX{}{\unless}} -\DeclareDocumentCommand\XeTeXthree{o}{% \ +\DeclareCommand\XeTeXthree{o}{% \ % \changes{v0.90}{2008/8/4}{adjusted % to the redefinition of % \cs{verb} in \pk{xlxtra} 2008/07/29} @@ -2503,10 +4172,16 @@ pagella, fontspec=quiet]{gmdocc} \@ifpackageloaded{gmverb}{\RestoreMacro\verb}{}% \AtBeginDocument{% \RestoreMacro\LaTeX\RestoreMacro*{LaTeX }% my version of the - % \LaTeX\ logo has been stored just - % after defining, in line \ref{SMLaTeX}. \ilrr - \RestoreMacro\eTeX}% - }{}} + % \LaTeX\ logo has been stored just + % after defining, in line \ref{SMLaTeX}. \ilrr + \RestoreMacro\eTeX}% + % \stanza + \pdef\adddefaultfontfeatures##1{% + \addtomacro\zf@default@options{#1,}} + }% of |\@ifXeTeX|'s first argument, + {}% |\@ifXeTeX|'s second argument, +}% of |\XeTeXthree|'s body. + % \indent The |\udigits| declaration causes the digits to be typeset % uppercase. I~provide it since by default I~prefer the lowercase @@ -2521,17 +4196,17 @@ pagella, fontspec=quiet]{gmdocc} % \subdivision{Fractions} -\def\Xedekfracc{\@ifstar\gmu@xedekfraccstar\gmu@xedekfraccplain} +\def\Xedekfracc{\gm@ifstar\gmu@xedekfraccstar\gmu@xedekfraccplain} % (plain) The starless version turns the font feature |frac| on. % - % (*) But nor my modification of Minion Pro neither \TeX\ Gyre + % (\*) But nor my modification of Minion Pro neither \TeX\ Gyre % Pagella doesn't feature the % |frac| font feature properly so, with the starred version of the % declaration we use the characters from the font where available % (see the |\@namedef|s below) and the |numr| and |dnom| features % with the fractional slash otherwise (via |\gmu@dekfracc|). % - % (**) But Latin Modern Sans Serif Quotation doesn't support the + % (\*\*) But Latin Modern Sans Serif Quotation doesn't support the % numerator and denominator positions so we provide the double % star version for it, which takes the char from font if it exist % and typesets with lowers and kerns otherwise. @@ -2556,21 +4231,26 @@ pagella, fontspec=quiet]{gmdocc} \gmu@xefraccdef{3/4}{"BE}% \gmu@xefraccdef{1/3}{"2153}% \gmu@xefraccdef{2/3}{"2154}% + \gmu@xefraccdef{1/5}{"2155}% + \gmu@xefraccdef{2/5}{"2156}% + \gmu@xefraccdef{3/5}{"2157}% + \gmu@xefraccdef{4/5}{"2158}% + \gmu@xefraccdef{1/6}{"2159}% + \gmu@xefraccdef{5/6}{"215A}% \gmu@xefraccdef{1/8}{"215B}% \gmu@xefraccdef{3/8}{"215C}% \gmu@xefraccdef{5/8}{"215D}% \gmu@xefraccdef{7/8}{"215E}% \pdef\dekfracc@args##1/##2{% - \def\gm@duppa{##1/##2}% - \gm@ifundefined{gmu@xefracc\all@other\gm@duppa}{% + \gm@ifundefined{gmu@xefracc\detokenize{##1/##2}}{% \gmu@dekfracc{##1}/{##2}}{% - \csname gmu@xefracc\all@other\gm@duppa\endcsname}% + \csname gmu@xefracc\detokenize{##1/##2}\endcsname}% \if@gmu@mmhbox\egroup\fi }% of |\dekfracc@args|. - \@ifstar{\let\gmu@dekfracc\gmu@dekfraccsimple}{}% + \gm@ifstar{\let\gmu@dekfracc\gmu@dekfraccsimple}{}% } -\def\gmu@xedekfraccplain{% `else' of the main |\@ifstar| +\def\gmu@xedekfraccplain{% `else' of the main |\gm@ifstar| \pdef\dekfracc@args##1/##2{% \ifmmode\hbox\fi{% \addfontfeature{Fractions=On}% @@ -2588,8 +4268,8 @@ pagella, fontspec=quiet]{gmdocc} \dekfracc@args} -\def\gmu@numeratorkern{\kern-.05em\relax} -\let\gmu@denominatorkern\gmu@numeratorkern +\def\gmu@numeratorkern{\kern-.055em\relax} +\def\gmu@denominatorkern{\kern-.05em\relax} % What have we just done? We defined two versions of the @@ -2602,32 +4282,66 @@ pagella, fontspec=quiet]{gmdocc} % The unstarred version makes use of the Fraction font feature and % therefore is much simpler. % -% Note that in the first argument of |\@ifstar| we wrote 8 (eight) +% Note that in the first argument of |\gm@ifstar| we wrote 8 (eight) % |#|s to get the correct definition and in the second argument `only' % 4. (The \LaTeXe\ Source claims that that is changed in the `new -% implementation' of |\@ifstar| so maybe it's subject to change.) +% implementation' of |\gm@ifstar| so maybe it's subject to change.) % A~simpler version of |\dekfracc| is provided in line \ref{2292}. % \subdivision{\cs{resizegraphics}} -\def\resizegraphics#1#2#3{% % \changes{v0.94}{2008/10/4}{\cs{includegraphics} +\pdef\resizegraphics#1#2#3{% % \changes{v0.94}{2008/10/4}{\cs{includegraphics} % works well in \XeTeX\ so I~remove the complicated version % with \cs{XeTeXpicfile}} + % 2009/11/17 works bad with a file whose name contains spaces so I + % return \cmd\XeTeXpicfile \resizebox{#1}{#2}{% - \includegraphics{#3}}} + \edef\gmu@tempa{\@nx\csname XeTeX\@nx\@ifendswithpdf{% + \@xa\string\csname#3\endcsname}{pdf}{pic}file\@nx\endcsname}% + \gmu@tempa "#3"\relax}} + +\edef\gmu@tempa{% + \def\@nx\@ifendswithpdf##1{% + \unexpanded{% + \ifnum + \if\relax\gmu@pdfdetector}##1% + \detokenize{pdf}\unexpanded{\relax0\else1\fi}% we expand to 1 if + % \inhash1 ends with lowercase ‘pdf’ of cat. 12 + \unexpanded{\if\relax\gmu@PDFdetector}##1% + \detokenize{PDF}\unexpanded{\relax0\else1\fi}% we expand to 1 if + % \inhash1 ends with uppercase ‘PDF’ of cat. 12 + >0 + \unexpanded{\@xa\@firstoftwo\else\@xa\@secondoftwo\fi}% + }% of |\@ifendswithpdf| + % + % \stanza + % + \def\@nx\gmu@pdfdetector##1\detokenize{pdf}{}% + \def\@nx\gmu@PDFdetector##1\detokenize{PDF}{}% +}\gmu@tempa + + +\pdef\textsuperscript@@#1{% + \@textsuperscript{\selectfont#1}}% +\def\@textsuperscript#1{% + {\m@th\ensuremath{^{\mbox{\fontsize\sf@size\z@#1}}}}} + +\let\textsuperscript@@\textsuperscript \def\GMtextsuperscript{% \@ifXeTeX{% - \def\textsuperscript##1{{% - \addfontfeature{VerticalPosition=Numerator}##1}}% + \DeclareCommand\textsuperscript{sm}{% + \IfValueTF{##1}{\textsuperscript@@{##2}}% + {% + \begingroup + \addfontfeature{VerticalPosition=Numerator}##2% + \endgroup}}% }{\truetextsuperscript}} \def\truetextsuperscript{% - \pdef\textsuperscript##1{% - \@textsuperscript{\selectfont##1}}% - \def\@textsuperscript##1{% - {\m@th\ensuremath{^{\mbox{\fontsize\sf@size\z@##1}}}}}} + \let\textsuperscript\textsuperscript@@ +} %^^A %\subdivision{Proper loading of \pk{tikz}} %^^A \def\xetikz{\def\pgfsysdriver{pgfsys-dvipdfm.def}% @@ -2636,31 +4350,73 @@ pagella, fontspec=quiet]{gmdocc} % \subdivision{Settings for mathematics in main font} I~used these % terrible macros while typesetting E.~Szarzyński's \textit{Letters} % in 2008. The \TextUsage\gmath\ declaration introduces math-active -% digits and binary operators and redefines greek letters and parentheses, the +% digits and binary operators and redefines Greek letters and parentheses, the % \TextUsage\garamath\ declaration redefines the quantifiers and is % more Garamond Premier Pro-specific. +% So, when you set default fonts (in the preamble), put +% \TextUsage\gmath\ to set what possible from them to math. This sets +% the |normal| math version. If you want to use another set of fonts +% elsewhere in your document and have according math for them, set +% them ‘for a~while’ in the preamble and in their scope declare +% |\gmath⁄arg[version]|. Then put |\mathversion{normal}| right after +% |\begin{document}| and |\gmath[⁄]| where you want those +% other fonts. +% +% |\gmath| takes second optional argument, in parentheses, +% which should be (sth.\ that expands to) a |\fontspec| font selecting +% command. A font selected by this command will be declared and used +% when some char in basic font is missing and only else the default +% math font will be left for such a char. +% +% So, \[|\gmath⁄arg[version](rescue font«(spec-ification)»)|\] +% +% Note that |\gmath| without first optional argument has always to +% come first because otherwise it overwrite settings of your math +% version. \def\gmu@getfontstring{% \xdef\gmu@fontstring{% \gmu@fontstring@}} \def\gmu@fontstring@{% - \@xa\@xa\@xa\gmu@quotedstring\@xa\meaning\the\font\@@nil} + \@xa\@xa\@xa\gmu@fontstring@@\@xa\meaning\the\font\@@nil} + + %^^A \edef\gmu@tempa{% + %^^A \def\@nx\gmu@fontstring@@ + %^^A \detokenize{select font }##1\@nx\@@nil + %^^A {##1}% + %^^A }\gmu@tempa -\def\gmu@quotedstring#1"#2"#3\@@nil{"#2"} +\def\gmu@fontstring@@#1"#2"#3\@@nil{"#2"} \def\gmu@getfontscale#1Scale#2=#3,{% \ifx\gmu@getfontscale#3\else - \gdef\gmu@fontscale{[#3] }% - \afterfi\gmu@getfontscale\fi + \def\gmu@tempa{MatchLowercase}% + \def\gmu@tempb{#3}% + \ifx\gmu@tempa\gmu@tempb + \gmu@calc@scale{5}% + \@xa\@firstoftwo + \else + \def\gmu@tempa{MatchUppercase}% + \ifx\gmu@tempa\gmu@tempb + \gmu@calc@scale{8}% + \afterfifi\@firstoftwo + \else\afterfifi\@secondoftwo + \fi + \fi + {\xdef\gmu@fontscalebr{[\gmu@fontscale] }}% + {\xdef\gmu@fontscalebr{[#3] }}% + \afterfi\gmu@getfontscale + \fi } \def\gmu@getfontdata#1{% - \global\emptify\gmu@fontscale + \global\emptify\gmu@fontscalebr \begingroup #1% + %^^A\typeout{@@@@ \@xa\meaning\the\font}% \@xa\@xa\@xa\gmu@getfontscale \csname zf@family@options\f@family\endcsname ,Scale=\gmu@getfontscale,% @@ -2671,43 +4427,100 @@ pagella, fontspec=quiet]{gmdocc} \def\gmu@stripchar#1"{"} -\def\gmath@getfamnum{% - \edef\gmath@famnum{\@xa\gmu@stripchar\meaning\gmath@fam}% - % ^^A \edef\gmath@famnum{\ifnum\gmath@famnum<"10 0\fi\gmath@famnum} +\DeclareCommand\gmath@getfamnum{C{\gmath@fam}}{% + \edef\gmath@famnum{\@xa\gmu@stripchar\meaning#1}% } %\incs{XeTeXmathcode}\ \arg[=] \ \ \ -\pdef\gmathbase{% +\DeclareCommand\gmathFams{o % the name of math version + C{\NoValue} % ‘rescue’ font. Will be accessible via + % \inverb|\symgmathRoman⁄| (math family) and + % \inverb|\gmath@fontt⁄| (font). +}{% + %^^A\AtBeginDocument{\setbox0=\hbox{$\showthe\textfont0 $}}% + \IfValueT{#1}{% + \DeclareMathVersion{#1}% this sets the defaults so no need to + % define them explicitly + % ^^A \SetSymbolFont{operators}{#1}{OT1}{qpl}{m}{n}% + % ^^A %^^A\SetSymbolFont{letters} {#1}{OML}{qpxmi} {m}{it}% + % ^^A \SetSymbolFont{symbols}{#1}{OMS}{pxsy}{m}{n}% + % ^^A \SetSymbolFont{largesymbols}{#1}{OMX}{pxex}{m}{n}% + }% of if |#1| given + % \gmu@getfontdata{\rmfamily\itshape}% % \edef\gmu@tempa{% - \@nx\DeclareSymbolFont{letters}{\encodingdefault}{gmathit}{m}{it}% - \@nx\DeclareFontFamily{\encodingdefault}{gmathit}{% + \IfValueTF{#1}{\@nx\SetSymbolFont{letters}{#1}}% + {\@nx\DeclareSymbolFont{letters}}% + {\encodingdefault}{gmathit\PutIfValue{#1}}{m}{it}% + \IfValueT{#1}{% + \@nx\DeclareSymbolFont{letters#1}% + {\encodingdefault}{gmathit\PutIfValue{#1}}{m}{it}% + }% + \@nx\DeclareFontFamily{\encodingdefault}{gmathit\PutIfValue{#1}}{% \skewchar\font\gmu@theskewchar\space}% - \@nx\DeclareFontShape{\encodingdefault}{gmathit}{m}{it}{% - <-> \gmu@fontscale \gmu@fontstring}{}% - }\gmu@tempa\typeout{@@@ gmathit (letters): \meaning\gmu@tempa}% + \@nx\DeclareFontShape{\encodingdefault}{gmathit\PutIfValue{#1}}{m}{it}{% + <-> \gmu@fontscalebr \gmu@fontstring}{}% + \IfValueT{#1}{% + \@nx\SetMathAlphabet\@nx\mathit{#1}{\encodingdefault}{gmathit#1}{m}{it}}% + }\gmu@tempa % + \IfValueT{#2}{% + \gmu@getfontdata{#2\gmu@ifstored{\upshape}{\storedcsname{upshape}}{\upshape}}% + \edef\gmu@tempa{% + \@nx\DeclareSymbolFont{gmathRoman\PutIfValue{#1}}% + {\encodingdefault}{gmathRm\PutIfValue{#1}}{m}{n}% + \@nx\DeclareFontFamily{\encodingdefault}{gmathRm\PutIfValue{#1}}{% + \skewchar\font\gmu@theskewchar\space}% + \@nx\DeclareFontShape{\encodingdefault}{gmathRm\PutIfValue{#1}}{m}{n}{% + <-> \gmu@fontscalebr \gmu@fontstring}{}% + }\gmu@tempa + \@xa\font\csname gmath@fontt\PutIfValue{#1}\endcsname + =\gmu@fontstring\relax + % \stanza + \gmu@getfontdata{#2\gmu@ifstored{\itshape}{\storedcsname{itshape}}{\itshape}}% + \edef\gmu@tempa{% + \@nx\DeclareSymbolFont{gmathItalic\PutIfValue{#1}}% + {\encodingdefault}{gmathIt\PutIfValue{#1}}{m}{n}% + \@nx\DeclareFontFamily{\encodingdefault}{gmathIt\PutIfValue{#1}}{% + \skewchar\font\gmu@theskewchar\space}% + \@nx\DeclareFontShape{\encodingdefault}{gmathIt\PutIfValue{#1}}{m}{n}{% + <-> \gmu@fontscalebr \gmu@fontstring}{}% + }\gmu@tempa + }% of if |#2| given + % \stanza \gmu@getfontdata{\rmfamily\upshape}% \edef\gmu@tempa{% - \@nx\DeclareSymbolFont{gmathroman}{\encodingdefault}{gmathrm}{m}{n}% - \@nx\DeclareFontFamily{\encodingdefault}{gmathrm}{% + \IfValueTF{#1}{\@nx\SetSymbolFont{gmathroman}{#1}}% + {\@nx\DeclareSymbolFont{gmathroman}}% + {\encodingdefault}{gmathrm\PutIfValue{#1}}{m}{n}% + \@nx\DeclareFontFamily{\encodingdefault}{gmathrm\PutIfValue{#1}}{% \skewchar\font\gmu@theskewchar\space}% - \@nx\DeclareFontShape{\encodingdefault}{gmathrm}{m}{n}{% - <-> \gmu@fontscale \gmu@fontstring}{}% - }\gmu@tempa\typeout{@@@ gmathrm (upright symbols): - \meaning\gmu@tempa}% - \font\gmath@font=\gmu@fontstring\relax - % - \DeclareDocumentCommand\gmath@do{mom}{%\ - % \begin{enumargs*} - % \mand the character or \CS\ to be declared, - % \opt the Unicode to be assigned, - % \mand math type (\CS like \cs{mathord} etc.) - % \end{enumargs*} + \@nx\DeclareFontShape{\encodingdefault}{gmathrm\PutIfValue{#1}}{m}{n}{% + <-> \gmu@fontscalebr \gmu@fontstring}{}% + \IfValueT{#1}{% + \@nx\SetMathAlphabet\@nx\mathrm{#1}{\encodingdefault}{gmathrm#1}{m}{n}}% + }\gmu@tempa + % ^^A \typeout{@@@ gmathrm (upright symbols): + % ^^A \meaning\gmu@tempa}% + \@xa\font\csname gmath@font\PutIfValue{#1}\endcsname + =\gmu@fontstring\relax + \gmathfamshook +} + +\emptify\gmathfamshook + +\DeclareCommand\gmathbase{oC{\NoValue}}{% + \gmathFams[#1](#2)% + \DeclareCommand\gmath@do{% + m % (1) the character or \CS\ to be declared, + o % (2) the Unicode to be assigned, + m % (3) math type (\CS like \cs{mathord} etc.) + C{\gmath@fam} % font family + }{%\ % - \gmath@getfamnum + \gmath@getfamnum(##4)% \IfValueTF{##2}{% \edef\gmu@tempa{% = \mathchar@type##3\space @@ -2715,6 +4528,7 @@ pagella, fontspec=quiet]{gmdocc} % ^^A\the\XeTeXcharglyph "##2\relax}% \if\relax\@nx##1% + \gmu@ifstored{##1}{}{\StoreMacro##1}% \edef\gmu@tempa{% \XeTeXmathchardef \@nx##1\gmu@tempa}% \else @@ -2722,7 +4536,7 @@ pagella, fontspec=quiet]{gmdocc} \XeTeXmathcode `##1 \gmu@tempa} \fi% }% - {% + {% no value of |##2| \edef\gmu@tempa{% \XeTeXmathcode `##1 = \mathchar@type##3\space @@ -2731,31 +4545,63 @@ pagella, fontspec=quiet]{gmdocc} `##1\relax}% }% \gmu@tempa - \typeout{@@@@ \@nx##1}% - \typeout{@@@@ \meaning\gmu@tempa}% + % ^^A \typeout{@@@@ \@nx##1}% + % ^^A \typeout{@@@@ \@xa\detokenize\@xa{\gmu@tempa}}% }% of \incs{gmath@do} % - \DeclareDocumentCommand\gmath@doif{mmmoo}{%\ - % \begin{enumargs*} - % \mand the Unicode of char enquired, - % \item the char or \CS\ to be declared, - % \item math type \CS (\cs{mathord} etc.), - % \opt second-choice Unicode (taken if first-choice is absent), - % \opt third-choice Unicode (as above if second-choice is absent - % from font). - % \end{enumargs*} - % - \iffontchar\gmath@font"##1 \gmath@do##2[##1]##3% - \else\IfValueT{##4}{% - \iffontchar\gmath@font"##4 \gmath@do##2[##4]##3% - \else\IfValueT{##5}{% - \iffontchar\gmath@font"##5 \gmath@do##2[##5]##3% + \DeclareCommand\gmath@doif{% + m % (1) the Unicode hex of char enquired, + m % (2) the char or \CS\ to be declared, + m % (3) math type \CS (\cs{mathord} etc.), + o % (4) second-choice Unicode (taken if first-choice is absent), + o % (5) third-choice Unicode (as above if second-choice is absent from font). + B{\gmath@fam} % (6) never used in this package. Why? + C{\NoValue} + }{% + \gmu@storeifnotyet{##2}% + \@xa\let\@xa\gmath@ft\csname + gmath@font% + \ifx\gmath@fam##6\else t\fi + \gmath@version + \endcsname + \iffontchar\gmath@ft"##1 \gmath@do##2[##1]##3(##6)% + \else + \IfValueTF{##4}{% + \iffontchar\gmath@ft"##4 \gmath@do##2[##4]##3(##6)% + \else + \IfValueTF{##5}{% + \iffontchar\gmath@ft"##5 \gmath@do##2[##5]##3(##6)% + \else + \gmath@restore{##1}{##2}{##3}{##4}{##5}{##7}% + \fi}% + {\gmath@restore{##1}{##2}{##3}{##4}{##5}{##7}}% \fi}% - \fi}% - \fi}% - % + {\gmath@restore{##1}{##2}{##3}{##4}{##5}{##7}}% + \fi + }% of |\gmath@doif| + % In the command above we try to define math char or a~\CS in the + % family given as |##6|. If there're no respective chars, we try + % the same with the family given (as a~word) in |##7|. + \def\gmath@restore##1##2##3##4##5##6{% + \IfValueT{##6}% + {\ifcsname ##6\endcsname + \edef\gmu@tempa{% + \unexpanded{\gmath@doif{##1}{##2}{##3}[##4][##5]}% + {\@xa\@nx\csname##6\endcsname}\relax + }\gmu@tempa + \@xa\@gobbletwo % if family |##6| is defined, we gobble the + % other branch + \fi + }% + \firstofone + {\if\relax\@nx##2% + \RestoreMacro##2% + \fi + }% + }% + % \iffalse % doesn't work in a~non-math font. - \DeclareDocumentCommand\gmath@delc{mo}{%\ + \DeclareCommand\gmath@delc{mo}{%\ % \begin{enumargs*} % \mand the char or \CS\ to be declared, % \opt the Unicode (if not the same as the char). @@ -2776,8 +4622,8 @@ pagella, fontspec=quiet]{gmdocc} `##1\relax}% }% \gmu@tempa - \typeout{@@@@ \@nx##1}% - \typeout{@@@@ \meaning\gmu@tempa}% + % ^^A \typeout{@@@@ \@nx##1}% + % ^^A \typeout{@@@@ \meaning\gmu@tempa}% }% of \incs{gmath@delc} % \def\gmath@delcif##1##2{%\ @@ -2803,13 +4649,28 @@ pagella, fontspec=quiet]{gmdocc} \gmath@famnum\space "##1\relax}}% \fi}% of \cs{gmath@delimif}. % - \pdef\gmu@dogmathbase{% + \pdef\rmopname##1##2##3{% + \mathop {##1\kern \z@ \mathrm{##3}}\csname n##2limits@\endcsname + }% + % + \DeclareCommand\gmu@dogmathbase{oC{\NoValue}}{% + %^^A\setbox0=\hbox{$\showthe\textfont0 $}% + \RestoreMacro\mathchar@type% % - \let\gmath@fam\symgmathroman + \IfValueT{##1}{\mathversion{##1}}% + % + \edef\gmath@version{\PutIfValue{##1}}% + % ^^A\show\gmath@version + % + \@xa\let\@xa\gmath@fam\csname symgmathroman% + \endcsname + \edef\gmath@famm{symgmathRoman\gmath@version}% as you see, this is + % not a~font family (number) but a~macro containing the name: of + % the secondary (‘rescue’) family. % \typeout{@@@ gmutils.sty: taking some math chars from the font^^J \gmu@fontstring@}% \gmath@do+\mathbin - \gmath@doif{2212}-\mathbin[2013]% minus sign if present or else en dash + \gmath@doif{2212}-\mathbin[2013](\gmath@famm)% minus sign if present or else en dash \gmath@do=\mathrel \gmath@do0\mathord \gmath@do1\mathord @@ -2822,14 +4683,22 @@ pagella, fontspec=quiet]{gmdocc} \gmath@do8\mathord \gmath@do9\mathord %% - \gmath@doif{2A7D}\xleq\mathrel - \gmath@doif{2A7E}\xgeq\mathrel + \gmath@doif{2264}\le\mathrel(\gmath@famm)% + \let\leq\le + \let\leeng\le + \gmath@doif{2265}\ge\mathrel(\gmath@famm)% + \let\geq\ge + \let\geeng\ge + \gmath@doif{2A7D}\xleq\mathrel(\gmath@famm)% + \gmath@doif{2A7E}\xgeq\mathrel(\gmath@famm)% \@ifpackageloaded{polski}{% \ifdefined\xleq + \gmu@storeifnotyet\leq \let\leq=\xleq \let\le=\leq \fi \ifdefined\xgeq + \gmu@storeifnotyet\geq \let\geq=\xgeq \let\ge=\geq \fi}{}% @@ -2839,7 +4708,7 @@ pagella, fontspec=quiet]{gmdocc} \gmath@do;\mathpunct \gmath@do…\mathpunct \gmath@do(\mathopen -%^^A \gmath@delc(% doeasn't work with a~non-math font (I~dunno if +%^^A \gmath@delc(% doesn't work with a~non-math font (I~dunno if %^^A~it works with a~math font). \gmath@do)\mathclose %^^A \gmath@delc)% @@ -2848,90 +4717,95 @@ pagella, fontspec=quiet]{gmdocc} \gmath@do]\mathclose %^^A \gmath@delc]% % - \gmath@doif{00D7}×\mathbin + \gmath@doif{00D7}×\mathbin (\gmath@famm)% \gmath@do:\mathrel - \gmath@doif{00B7}·\mathbin - \gmath@doif{22C6}*\mathbin - \gmath@doif{2300}\varnothing\mathord - \gmath@doif{221E}\infty\mathord - \gmath@doif{2248}\approx\mathrel - \gmath@doif{2260}\neq\mathrel + \gmath@doif{00B7}·\mathbin(\gmath@famm)% + \gmath@doif{22C6}*\mathbin(\gmath@famm)% % low star + \gmath@doif{2300}\varnothing\mathord(\gmath@famm)% + \gmath@doif{221E}\infty\mathord(\gmath@famm)% + \gmath@doif{2248}\approx\mathrel(\gmath@famm)% + \gmath@doif{2260}\neq\mathrel(\gmath@famm)% \let\ne\neq - \gmath@doif{00AC}\neg\mathbin + \gmath@doif{00AC}\neg\mathbin(\gmath@famm)% + \gmath@doif{00AC}\nego\mathord(\gmath@famm)% \gmath@do/\mathop \gmath@do<\mathrel %^^A \gmath@delcif{2329}<% \gmath@do>\mathrel %^^A \gmath@delcif{232A}>% - \gmath@doif{2329}\langle\mathopen - \gmath@doif{232A}\rangle\mathclose - \gmath@doif{2202}\partial\mathord - \gmath@doif{00B1}\pm\mathbin - \gmath@doif{007E}\sim\mathrel - \gmath@doif{2190}\leftarrow\mathrel - \gmath@doif{2192}\rightarrow\mathrel - \gmath@doif{2194}\leftrightarrow\mathrel% if not present, + \gmath@doif{2329}\langle\mathopen(\gmath@famm)% + \gmath@doif{232A}\rangle\mathclose(\gmath@famm)% + \gmath@doif{2202}\partial\mathord(\gmath@famm)% + \gmath@doif{00B1}\pm\mathbin(\gmath@famm)% + \gmath@doif{007E}\sim\mathrel(\gmath@famm)% + \gmath@doif{2190}\leftarrow\mathrel(\gmath@famm)% + \gmath@doif{2192}\rightarrow\mathrel(\gmath@famm)% + \gmath@doif{2194}\leftrightarrow\mathrel(\gmath@famm)%% if not present, % \incs{gmathfurther} will take care % of it if left and right arrows are present. - \gmath@doif{2191}\uparrow\mathrel% it should be a~delimiter + \gmath@doif{2191}\uparrow\mathrel(\gmath@famm)%% it should be a~delimiter % (declared with \incs{gmath@delimif}) % but in a~non-math % font the delimiters don't work (2008/11/19) and I~don't think % I'll ever need up- and down- arrows as delimiters. - \gmath@doif{2193}\downarrow\mathrel + \gmath@doif{2193}\downarrow\mathrel(\gmath@famm)% % - \gmath@doif{2208}\in\mathrel[03F5][0454]% + \gmath@doif{2208}\in\mathrel[03F5][0454](\gmath@famm)%% % As a~fan of modal logics I~allow redefinition of \incs{lozenge} % and \incs{square} iff both are in the font. I~don't accept % the ‘ballot box’ U+2610. \if\iffontchar\gmath@font"25CA 0\else 1\fi \iffontchar\gmath@font"25FB 0\else\iffontchar\gmath@font"25A1 0\else 2\fi\fi \gmath@do\lozenge[25CA]\mathord - \gmath@doif{25FB}\square\mathord[25A1]% ‘medium white square (modal + \gmath@doif{25FB}\square\mathord[25A1](\gmath@famm)%% ‘medium white square (modal % operator)’ of just ‘white square’. \fi - \gmath@doif{EB08}\bigcircle\mathbin - \gmath@doif{2227}\wedge\mathbin - \gmath@doif{2228}\vee\mathbin + \gmath@doif{EB08}\bigcircle\mathbin(\gmath@famm)% + \gmath@doif{2227}\wedge\mathbin(\gmath@famm)% + \gmath@doif{2228}\vee\mathbin(\gmath@famm)% % - \gmath@doif{0393}\Gamma\mathalpha - \gmath@doif{0394}\Delta\mathalpha - \gmath@doif{0398}\Theta\mathalpha - \gmath@doif{039B}\Lambda\mathalpha - \gmath@doif{039E}\Xi\mathalpha - \gmath@doif{03A3}\Sigma\mathalpha - \gmath@doif{03A5}\Upsilon\mathalpha - \gmath@doif{03А6}\Phi\mathalpha - \gmath@doif{03A8}\Psi\mathalpha - \gmath@doif{03A9}\Omega\mathalpha + \gmath@doif{0393}\Gamma\mathalpha(\gmath@famm)% + \gmath@doif{0394}\Delta\mathalpha(\gmath@famm)% + \gmath@doif{0398}\Theta\mathalpha(\gmath@famm)% + \gmath@doif{039B}\Lambda\mathalpha(\gmath@famm)% + \gmath@doif{039E}\Xi\mathalpha(\gmath@famm)% + %^^A~\gmath@doif{039F}\Xi\mathalpha(\gmath@famm)% + \gmath@doif{03A3}\Sigma\mathalpha(\gmath@famm)% + \gmath@doif{03A5}\Upsilon\mathalpha(\gmath@famm)% + \gmath@doif{03А6}\Phi\mathalpha(\gmath@famm)% + \gmath@doif{03A8}\Psi\mathalpha(\gmath@famm)% + \gmath@doif{03A9}\Omega\mathalpha(\gmath@famm)% % - \let\gmath@fam\symletters + \@xa\let\@xa\gmath@fam\csname symletters\gmath@version% + \endcsname + \edef\gmath@famm{symgmathItalic\gmath@version}% % - \gmath@doif{03B1}\alpha\mathalpha - \gmath@doif{03B2}\beta\mathalpha - \gmath@doif{03B3}\gamma\mathalpha - \gmath@doif{03B4}\delta\mathalpha - \gmath@doif{03F5}\epsilon\mathalpha - \gmath@doif{03B5}\varepsilon\mathalpha - \gmath@doif{03B6}\zeta\mathalpha - \gmath@doif{03B7}\eta\mathalpha - \gmath@doif{03B8}\theta\mathalpha - \gmath@doif{03D1}\vartheta\mathalpha - \gmath@doif{03B9}\iota\mathalpha - \gmath@doif{03BA}\kappa\mathalpha - \gmath@doif{03BB}\lambda\mathalpha - \gmath@doif{03BC}\mu\mathalpha - \gmath@doif{03BD}\nu\mathalpha - \gmath@doif{03BE}\xi\mathalpha - \gmath@doif{03C0}\pi\mathalpha - \gmath@doif{03A0}\Pi\mathalpha - \gmath@doif{03C1}\rho\mathalpha - \gmath@doif{03C3}\sigma\mathalpha - \gmath@doif{03DA}\varsigma\mathalpha% 03C2? - \gmath@doif{03C4}\tau\mathalpha - \gmath@doif{03C5}\upsilon\mathalpha - \gmath@doif{03D5}\phi\mathalpha - \gmath@doif{03C8}\psi\mathalpha - \gmath@doif{03C9}\omega\mathalpha + \gmath@doif{03B1}\alpha\mathalpha(\gmath@famm)% + \gmath@doif{03B2}\beta\mathalpha(\gmath@famm)% + \gmath@doif{03B3}\gamma\mathalpha(\gmath@famm)% + \gmath@doif{03B4}\delta\mathalpha(\gmath@famm)% + \gmath@doif{03F5}\epsilon\mathalpha(\gmath@famm)% + \gmath@doif{03B5}\varepsilon\mathalpha(\gmath@famm)% + \gmath@doif{03B6}\zeta\mathalpha(\gmath@famm)% + \gmath@doif{03B7}\eta\mathalpha(\gmath@famm)% + \gmath@doif{03B8}\theta\mathalpha(\gmath@famm)% + \gmath@doif{03D1}\vartheta\mathalpha(\gmath@famm)% + \gmath@doif{03B9}\iota\mathalpha(\gmath@famm)% + \gmath@doif{03BA}\kappa\mathalpha(\gmath@famm)% + \gmath@doif{03BB}\lambda\mathalpha(\gmath@famm)% + \gmath@doif{03BC}\mu\mathalpha(\gmath@famm)% + \gmath@doif{03BD}\nu\mathalpha(\gmath@famm)% + \gmath@doif{03BE}\xi\mathalpha(\gmath@famm)% + \gmath@doif{03C0}\pi\mathalpha(\gmath@famm)% + \gmath@doif{03A0}\Pi\mathalpha(\gmath@famm)% + \gmath@doif{03C1}\rho\mathalpha(\gmath@famm)% + \gmath@doif{03C3}\sigma\mathalpha(\gmath@famm)% + \gmath@doif{03DA}\varsigma\mathalpha(\gmath@famm)%% 03C2? + \gmath@doif{03C4}\tau\mathalpha(\gmath@famm)% + \gmath@doif{03C5}\upsilon\mathalpha(\gmath@famm)% + \gmath@doif{03D5}\phi\mathalpha(\gmath@famm)% + \gmath@doif{03C7}\chi\mathalpha(\gmath@famm)% + \gmath@doif{03C8}\psi\mathalpha(\gmath@famm)% + \gmath@doif{03C9}\omega\mathalpha(\gmath@famm)% % \if 1 1% \iffontchar\gmath@font"221A @@ -2940,11 +4814,26 @@ pagella, fontspec=quiet]{gmdocc} \XeTeXradical \@xa\gmu@stripchar\meaning\symgmathroman\space "221A\relax}% \fi \fi% of if 1 1. - }% - \AtBeginDocument{\gmu@dogmathbase\let\gmathbase\gmu@dogmathbase}% - \not@onlypreamble\gmathbase + \def\max{\rmopname \relax m{max}}% + \def\min{\rmopname \relax m{min}}% + \def\lim{\rmopname \relax m{lim}}% + \def\sin{\rmopname \relax o{sin}}% + \def\cos{\rmopname \relax o{cos}}% + \def\tg{\rmopname \relax o{tg}}% + \def\ctg{\rmopname \relax o{ctg}}% + \def\tan{\rmopname \relax o{tan}}% + \def\ctan{\rmopname \relax o{ctan}}% + }% of |\gmu@dogmathbase| + \AtBeginDocument{\gmu@dogmathbase[#1](#2)% + \let\gmathbase\gmu@dogmathbase + }% of atbd + \not@onlypreamble\gmathbase }% of \cs{gmathbase} +% The |\gmatbase| declaration defines a~couple of gmath defining +% commands and then launches them for the default font at begin +% document and becomes only that launching. + \@onlypreamble\gmathbase % \nostanza It's a~bit tricky: if \cs{gmathbase} occurs first time in % a~document inside \env{document} then an error error is raised. But @@ -2959,7 +4848,8 @@ pagella, fontspec=quiet]{gmdocc} % \cs{addtotoks} to allow using in any order with \cs{garamath} % and others} % - \def\do##1##2##3{\def##1{% + \def\do##1##2##3{\gmu@storeifnotyet##1% + \def##1{% \mathop{\mathchoice{\hbox{% \rm \edef\gma@tempa{\the\fontdimen8\font}% @@ -2981,7 +4871,8 @@ pagella, fontspec=quiet]{gmdocc} % when the big quantifier is Bauhaus-like. \do\exists{\rotatebox[origin=c]{180}{\gma@quantifierhook E}}\nolimits% % - \def\do##1##2##3{\def##1{##3{% + \def\do##1##2##3{\gmu@storeifnotyet##1% + \def##1{##3{% \mathchoice{\hbox{\rm##2}}{\hbox{\rm##2}}% {\hbox{\rm\scriptsize##2}}{\hbox{\rm\tiny##2}}}}}% % @@ -2999,7 +4890,8 @@ pagella, fontspec=quiet]{gmdocc} %^^A\typeout{@@@ I fake \string\leftrightarrow}% \fi\fi % - \def\do##1##2##3{\def##1####1{##2{\hbox{% + \def\do##1##2##3{\gmu@storeifnotyet##1% + \def##1####1{##2{\hbox{% \rm \setbox0=\hbox{####1}% \edef\gma@tempa{\the\ht0}% @@ -3021,7 +4913,8 @@ pagella, fontspec=quiet]{gmdocc} \addtotoks\everymath{% \changes{v0.96}{2008/11/20}{the % \cs{everymath}'s left brace moved here: % earlier all the stuff was put into \cs{everymath}} - \def\do##1##2{\def##1{\ifmmode##2{\mathchoice + \def\do##1##2{\gmu@storeifnotyet##1% + \def##1{\ifmmode##2{\mathchoice {\hbox{\rm\char`##1}}{\hbox{\rm\char`##1}}% {\hbox{\rm\scriptsize\char`##1}}{\hbox{\rm\tiny\char`##1}}}% \else\char`##1\fi}}% @@ -3032,7 +4925,8 @@ pagella, fontspec=quiet]{gmdocc} \def\={\mathbin{=}}% \def\neqb{\mathbin{\neq}}% \let\neb\neqb - \def\do##1{\edef\gma@tempa{% + \def\do##1{\gmu@storeifnotyet##1% + \edef\gma@tempa{% \def\@xa\@nx\csname \@xa\gobble\string##1r\endcsname{% \@nx\mathrel{\@nx##1}}}% \gma@tempa}% @@ -3049,10 +4943,18 @@ pagella, fontspec=quiet]{gmdocc} % \pk{url} package's \incs{url} typesets the argument inside % a~math which caused digits not to be typewriter but Roman and % lowercase. - \fi% of ifdefined Url. + \fi% of |\ifdefined\Url|. }% of |\def\gmathfurther|. \ResumeDef -\def\gmath{\gmathbase\gmathfurther} +\StoreMacro\mathchar@type + +\DeclareCommand\gmath{oC{\NoValue}}{% + \gmathbase[#1](#2)% + \gmathfurther + \IfValueT{#1}{\csname gmathhook#1\endcsname}% this allows adding + % version-specific stuff (I~first used this for Fell fonts rescued + % with Garamond Premier) +} \pdef\gmathscripts{% \changes{v0.96}{2008/11/11}{added} \addtotoks\everymath{\catcode`\^=7\relax \catcode`\_=8\relax }% @@ -3082,30 +4984,39 @@ pagella, fontspec=quiet]{gmdocc} %^^B trial composition \def\bgcolor{\color{white}} -\def\garamath{% - \addtotoks\everymath{% - \quantifierhook{\addfontfeature{OpticalSize=800}}% - % - \def\gma@arrowdash{{% - \setbox0=\hbox{\char"2192}\copy0\kern-0,6\wd0 - \bgcolor\rule[-\dp0]{0,6\wd0}{\dimexpr\ht0+\dp0}\kern-0,6\wd0}}% - % - \def\gma@gmathhook{% - \def\do####1####2####3{\def####1{####3{% - \mathchoice{\hbox{\rm####2}}{\hbox{\rm####2}}% - {\hbox{\rm\scriptsize####2}}{\hbox{\rm\tiny####2}}}}}% - \do\mapsto{\rule[0,4ex]{0,1ex}{0,4ex}\kern-0,05em% - \gma@arrowdash\kern-0,05em\char"2192}\mathrel - \do\cup{\scshape u}\mathbin - \do\varnothing{\setbox0=\hbox{\gma@quantifierhook\addfontfeature{Scale=1.272727}0}% - \setbox2=\hbox{\char"2044}% - \copy0 \kern-0,5\wd0 \kern-0,5\wd2 \lower0,125\wd0 \copy2 - \kern0,5\wd0\kern-0,5\wd2}{}% - \do\leftarrow{\char"2190\kern-0,05em\gma@arrowdash}\mathrel - \do\rightarrow{\gma@arrowdash\kern-0,05em\char"2192}\mathrel - \do\in{\gma@quantifierhook\char"0454}\mathbin - }}% - \everydisplay\everymath} +\DeclareCommand\garamath{% + O{\rm}% the font command +}{% + % Before 2009/10/19 all the stuff was added to |\everymath| which + % didn't work. + \quantifierhook{\addfontfeature{OpticalSize=800}}% + % + \def\gma@arrowdash{{% + \setbox0=\hbox{\char"2192}\copy0\kern-0,6\wd0 + \bgcolor\rule[-\dp0]{0,6\wd0}{\dimexpr1,07\ht0+\dp0}\kern-0,6\wd0}}% + % + \def\gma@gmathhook{% + \def\do####1####2####3{\gmu@storeifnotyet####1% + \def####1{####3{% + \mathchoice{\hbox{#1####2}}{\hbox{#1####2}}% + {\hbox{#1\scriptsize####2}}{\hbox{#1\tiny####2}}}}}% + \do\mapsto{\rule[0,4ex]{0,1ex}{0,4ex}\kern-0,05em% + \gma@arrowdash\kern-0,05em\char"2192}\mathrel + \do\cup{\scshape u}\mathbin + \do\varnothing{\setbox0=\hbox{\gma@quantifierhook\addfontfeature{Scale=1.272727}0}% + \setbox2=\hbox{\char"2044}% + \copy0 \kern-0,5\wd0 \kern-0,5\wd2 \lower0,125\wd0 \copy2 + \kern0,5\wd0\kern-0,5\wd2}{}% of |\varnothing| + \do\leftarrow{\char"2190\kern-0,05em\gma@arrowdash}\mathrel + \do\shortleftarrow{\char"2190}\mathrel + \do\rightarrow{\gma@arrowdash\kern-0,05em\char"2192}\mathrel + \do\shortrightarrow{\char"2192\relax}\mathrel + \do\in{\gma@quantifierhook\char"0454}\mathbin + \do\prec{\gma@quantifierhook + \rotatebox[origin=c]{-90}{% + \glyphname{u03A5.a}}}\mathrel % added 2009/9/11 + }% of |\gma@gmathhook| +}% of |\garamath|. @@ -3125,27 +5036,363 @@ pagella, fontspec=quiet]{gmdocc} +% \subdivision{A~left-slanted font} Or rather a~left Italic \emph{and} +% left slanted font. In both cases we sample the skewness of the +% itshape font of the current family, we reverse it and apply to +% \cs{itshape} in \cs{litshape} and +% \cs{textlit} and to \cs{sl} in \cs{lsl}. Note +% a~slight asymmetry: \cs{litshape} and \cs{textlit} take the current +% family while \cs{lsl} and \cs{textlsl} the basic Roman family and +% basic (serif) Italic font. Therefore we introduce the \cs{lit} +% declaration for symmetry, that declaration left-slants \cs{it}. +% +% {\leftslanting +% I~introduced them first while typesetting E.~Szarzyński's +% \ty{Letters} to follow his (elaborate) hand-writing and now I copy +% them here when need left Italic for his \ty{Albert Camus' ^^B +% \ty{The Plague}} to avoid using bold font.\par} +% +% Of course it's rather esoteric so I~wrap all that in a~declaration. + +\pdef\leftslanting@{% + \def\litdimen{\strip@pt\fontdimen1\font ex}% + \def\litcorrection{% + \ifhmode\null\nobreak\hskip\litdimen\relax\fi}% + \def\litkern{% note it's to be used inside the left slanted font, + % unlike \incmd\litcorrection, intended to be used \emph{before} + % switching to left slant/italic. + \leavevmode\null + \kern-\litdimen\relax}% + \def\dilitkern{\kern\litdimen\litkern}% + % \stanza + \pdef\litshape{% \changes{v0.93}{2008/08/22}{copied here from + % E.~Szarzyński's \ty{The Letters}} + \litcorrection + \itshape + \@tempdima=-2\fontdimen1\font + \advance\leftskip by\strip@pt\fontdimen1\font ex % to assure at + % least the lowercase letters not to overshoot to the (left) + % margin. Note this has any effect only if there is a~\incs{par} in + % the scope. + \litcorrection + \edef\gmu@tempa{% + \@nx\addfontfeature{FakeSlant=\strip@pt\@tempdima}}%^^B + % \ilrr when not \incs{edef}ed, it caused an error, which is + % perfectly understandable. + \gmu@tempa}% + % + % + \pdef\textlit##1{% \changes{v0.93}{2008/08/22}{added} + {\litshape##1}}% + % + \pdef\lit{\rm\litshape}% + % + % + \pdef\lsl{{% + \litcorrection + \it + % \changes{v0.93}{2008/08/22}{copied here from E.~Szarzyński's \ty{The + % Letters}} + \@tempdima=-\fontdimen1\font + \litcorrection + \xdef\gmu@tempa{% + \@nx\addfontfeature{RawFeature={slant=\strip@pt\@tempdima}}}}% + \rm % Note in this declaration we left-slant the basic Roman font + % not the itshape of the current family. + \gmu@tempa}% + % + % Now we can redefine \cs{em} and \cs{emph} to use left Italic for + % nested emphasis. In Polish typesetting there is bold in nested + % emphasis as I~have heard but we don't like bold since it perturbs + % homogeneous greyness of a~page. So we introduce a~three-cycle + % instead of two-: Italic, left Italic, upright. + % + \pdef\em{%\changes{v0.93}{2008/08/22}{added} + \ifdim\fontdimen1\font=\z@ \itshape + \else + \ifdim\fontdimen1\font>\z@ \litshape + \else \upshape + \fi + \fi}% + % + % + \pdef\emph##1{% \changes{v0.93}{2008/08/22}{added} + {\em##1}}% +}% of \cs{leftslanting@}. + +\pdef\leftslanting{\AtBeginDocument\leftslanting@} + +\AtBeginDocument{\let\leftslanting\leftslanting@} + + +% \subdivision{Fake Old-style Numbers} +% +% While preparing documentation of this package I~faced an \ae ^^A +% sthetic problem of lack of old-style numbers in a~font I~fancy. The +% font is for the sans serif and the digits occur only in the date in +% title so it would be a~pity not too use a~nice font when only one or +% two numbers are needed. + +\def\romorzero#1{% + \ifnum#1=0 zero\else\romannumeral#1 \fi} + +\DeclareCommand\fakeonum{% + o % fake bold for the digit »2« (for which emboldening improves + % look), + >Pm % the text to fake old-style numbers in. + % ^^A Note it's an optional + % ^^A % braced argument so if the next non-space token after + % ^^A % \incs{fakeonum} is not left brace, the \inverb|#2|-less version + % ^^A % will be executed. It allows one to use this command as an + % ^^A % environment. +}{%\ + % I~tried to use this command as a~declaration but active digits are + % very uncomfortable, e.g.\ you can't define macros with arguments. + % \chgs{2008/12/04 v0.98 added} + \gmu@if@onum{#2}{% + \begingroup + \edef\gmu@tempa{#2}% + \makeatletter% + \IfValueT{#1}{% + \prependtomacro\fake@onum@ii{% + \begingroup\addfontfeature{FakeBold=#1}}% + \addtomacro\fake@onum@ii\endgroup + }% + \endlinechar\m@ne % to suppress the line end added by + % |\scantokens|, especially in active |^^M|'s scopes. + \gmu@dofakeonum + \@xa\scantokens\@xa{\gmu@tempa}% + \endgroup + }% of |\gmu@ifonum| ‘else’. +}% of |\fakeonum|. + +\def\gmu@dofakeonum{% + \def\do##1{% + \catcode`##1\active + \scantokens{% + \@xa\let\@xa##1% + \csname fake@onum@\@xa\romorzero\string##1\endcsname\empty}}% + \do0\do1\do2\do3\do4\do5\do6\do7\do8\do9% +} + +\def\do#1#2{% + \@namedef{fake@onum@\romorzero#1}{#2}} + +\def\gmu@tempa#1{% + \do#1{\leavevmode + \gmu@calculateslant{#1}% uses \incs{gmu@tempa} and + % \incs{gmu@tempb}, therefore goes first. And defines \incs{gmu@tempd}. + \gmu@measurewd{#1}% the width of char |#1| is in \incs{gmu@tempa} + % without kerning and in \incs{gmu@tempb} with kerning. + %^^A\typeout{@@@@@@ \gmu@tempa}% + %^^A {\gmu@tempe + % ^^A \typeout{@@@@@@ \the\fontcharwd\font`#1}% + % ^^A }% + \edef\gmu@tempc{\the\fontcharht\font`#1}% + \hbox to \gmu@tempb {% + \hss\resizebox{\gmu@tempa}% + {\dimexpr\fontdimen5\font+\gmu@tempc-\fontdimen8\font}% + {\gmu@tempd#1}\hss}}} + +\def\gmu@measurewd#1{% \label{@measurewd} + \edef\gmu@tempa{\the\fontcharwd\font`#1}% + \settowidth{\@tempdimb}{% to preserve kerning + \char`#1\char`#1\char`#1\char`#1\char`#1\char`#1% + \char`#1\char`#1\char`#1\char`#1\char`#1\char`#1% + \char`#1\char`#1\char`#1\char`#1\char`#1\char`#1% + \char`#1\char`#1\char`#1}% + \edef\gmu@tempb{\the\dimexpr(\@tempdimb-\gmu@tempa)/20}% +} + +\gmu@tempa0 % |\fake@onum@zero| +\gmu@tempa1 % |\fake@onum@i| +\gmu@tempa2 % |\fake@onum@ii| + +\def\gmu@tempa#1{% + \do#1{\leavevmode + \gmu@measurewd{#1}% + \lower + \dimexpr\fontdimen8\font-\fontdimen5\font\relax + \hbox to \gmu@tempb {\hss#1\hss}}% +} + +\gmu@tempa3 % |\fake@onum@iii| +\gmu@tempa4 % |\fake@onum@iv| +\gmu@tempa5 % |\fake@onum@v| +\gmu@tempa7 % |\fake@onum@vii| +\gmu@tempa9 % |\fake@onum@ix| + +\def\gmu@tempa#1{% to preserve pseudo-kerning in digits sequences. + \do#1{\leavevmode + \gmu@measurewd#1% + \hbox to \gmu@tempb {\hss#1\hss}}} + +\gmu@tempa6 % |\fake@onum@vi| +\gmu@tempa8 % |\fake@onum@viii| + + +\protected\def\gmu@if@onum{% + \edef\gmu@tempa{\@xa\meaning\the\font}% + \@xa\@ifinmeaning\detokenize{+onum}\of\gmu@tempa +} +% \nostanza Thus |\gmu@if@onum| becomes a~two-argument command that +% executes its \hash1 if there is |+onum| in current font +% specification or its |#2| if |+onum| is absent. +% +% One could easily generalise |\gmu@if@onum| to |\@if@fontfeature|, +% i.e.\ to a~test for an arbitrary font feature, probably with +% employing that very nice feature specification of \pk{fontspec}, so +% that you could write +% |\IfFontFeature{Numbers=OldStyle}{}{fake old-style digits}|. + +\pdef\gmu@getslant{% we define |\gmu@tempa| to the (fake) slant of current font. + \edef\gmu@tempa{\@xa\meaning\the\font\detokenize{slant=0,}}% + \edef\gmu@tempb{% + \def\@nx\gmu@tempb####1% + \detokenize{slant=}% + ####2,####3}% + \gmu@tempb\@@nil{##2}% + \edef\gmu@tempa{\@xa\gmu@tempb\gmu@tempa\@@nil pt}% + %^^A~\typeout{@@@@ :::\gmu@tempa:::}% +} + +\def\gmu@calculateslant#1{% + \gmu@getslant + %^^A~\typeout{@@@@ \the\fontdimen1\font}% + \edef\gmu@tempa{\the\numexpr\dimexpr\fontdimen1\font + \gmu@tempa}%\ + % \incs{gmu@tempa} bears the number of scaled points of total slant + % (\inverb|\fontdimen1\font|${}+$\inverb|slant=…| if present) per 1pt + % of \inhash1.\ilrr + \edef\gmu@tempa{\the\numexpr \gmu@tempa * + \numexpr\fontdimen5\font\relax/\numexpr\fontcharht\font`#1 + \relax}%\ + % we scale the total slant of \inverb|#1| by the ratio of original + % and scaled height of \inverb|#1|. + \edef\gmu@tempd{% + \the\dimexpr \gmu@tempa sp - \fontdimen1\font}%\ + % and we subtract slant-fontdimen from the scaled total slant. + %^^A\typeout{@@@ \gmu@tempd}% + \ifdim\gmu@tempd=\z@ \emptify\gmu@tempd + \else\edef\gmu@tempd{% + \@nx\addfontfeature{FakeSlant=\strip@pt\dimexpr\gmu@tempd}}% + \fi} + +\DeclareCommand\gmu@cepstnof{O{\gmu@tempa}% a~cs to be |\xdef|ed the + % font specification, + s% not used really, + m% |\fontspec| token or name of feature font (\inverb|Italic|, \inverb|Bold|, + % \inverb|SmallCaps|, \inverb|BoldItalic| ), + O{, Scale=MatchLowercase}% \pk{fontspec} font features (key=val) +} +{% |\gmu@cepstnof|'s body + \def\gmu@reservedc##1:##2:\@@nil{% + \ifx:##2:\else RawFeature={\gmu@maybestripcomma##2,,\@@nil} \fi}% + % \stanza + \def\gmu@reservedd##1/##2/\@@nil{% to check whether font name + % contains |/| (which may not be true!) + \ifx&##2&\@xa\@firstoftwo\else\@xa\@secondoftwo\fi}% + % \stanza + \def\gmu@reservede##1:##2:\@@nil{% to check whether the font name + % contains |:| when it doesn't contain |/|. + \ifx&##2&\@xa\@firstoftwo\else\@xa\@secondoftwo\fi}% + % \stanza + \edef\gmu@reserveda{% + % now, reserved B parses the font name and features. It uses an + % auxiliary reserved C because after |/| may be or may not be + % features specification. + \@xa\@xa\@xa\gmu@reservedd\@xa\meaning\the\font//\@@nil + {% font name doesn't contain a~slash + \@xa\@xa\@xa\gmu@reservede\@xa\meaning\the\font::\@@nil + {% nor does it contain a~colon + \def\@nx\gmu@reservedb\detokenize{select font + "}####1\detokenize{"}####2\@nx\@@nil{% + \ifx\fontspec#3% + \@nx\@nx\@nx\fontspec[\@gobble#4\@empty]{####1}% gobble a~comma + \else + #3Font={####1}, #3Features={\@gobble #4\@empty}% + \fi + }% + }% + {% no slash but there is a~colon + \def\@nx\gmu@reservedb\detokenize{select font + "}####1:####2\detokenize{"}####3\@nx\@@nil{% + \ifx\fontspec#3% + \@nx\@nx\@nx\fontspec[\@nx\gmu@reservedc####2::\@nx\@@nil#4]{####1}% + \else + #3Font={####1}, #3Features={\@nx\gmu@reservedc####2::\@nx\@@nil#4}% + \fi + }% + }% + }% of ‘no slash’ case + {% font name contains a~slash + \def\@nx\gmu@reservedb\detokenize{select font + "}####1/####2\detokenize{"}####3\@nx\@@nil{% + \ifx\fontspec#3% + \@nx\@nx\@nx\fontspec[\@nx\gmu@reservedc####2::\@nx\@@nil#4]{####1}% + \else + #3Font={####1}, #3Features={\@nx\gmu@reservedc####2::\@nx\@@nil#4}% + \fi + }% of |\gmu@reservedb| + }% of ‘slash present’ case + }\gmu@reserveda + % ^^A\typeout{@@@@@ ›\@xa\meaning\the\font‹}% + \xdef#1{\@xa\@xa\@xa\gmu@reservedb\@xa\meaning\the\font\@@nil}% + % ^^A~\typeout{@@@@@ ›\meaning#1‹}% +}% + +\def\gmu@maybestripcomma#1,,#2\@@nil{#1} + +\pdef\gmu@setbasefont{\@xa\let\@xa\gmu@basefont\the\font} + +\let\setbasefont\gmu@setbasefont + +\DeclareCommand\gmu@calc@scale{% + O{1}% a~factor, + m% number of the fontdimen + } +{\begingroup + % ^^A~\setlength\@tempdima{\fontdimen#1\font}% + % ^^A~\setlength\@tempdimb{\fontdimen#1\zf@basefont}% + % ^^A~\setlength\@tempdimc{1pt*\ratio{\@tempdima}{\@tempdimb}}% + % We ‘descale’ the current font:\nostanza + \gmu@cepstnof\fontspec[, Scale=1]\gmu@tempa + \@xa\let\@xa\gmu@currfont@descaled\the\font + \gmu@basefont + % ^^A\typeout{@@@@ \meaning\gmu@basefont}% + \gmu@cepstnof\fontspec[, Scale=1]\gmu@tempa + % \nostanza now also the base font is descaled. + \xdef\gmu@fontscale{% + \strip@pt + % ^^A\@tempdimc + \dimexpr 1pt * + \numexpr\dimexpr#1\fontdimen#2\font\relax\relax / + \numexpr\fontdimen#2\gmu@currfont@descaled\relax + \relax}% + % ^^A \zf@PackageInfo{\zf@fontname\space scale = \zf@scale}% + \endgroup} + + %\division{Varia} % % A~very neat macro provided by \pk{doc}. I~copy it -% \*|verbatim|. +% \texttilde|verbatim|. \def\gmu@tilde{% \leavevmode\lower.8ex\hbox{$\,\widetilde{\mbox{ }}\,$}} % Originally there was just |\ | instead of |\mbox{ }| but some % commands of ours do redefine |\ |. -% \Define\* -\pdef\*{\gmu@tilde} -% \Define\~ -% \changes{v0.83}{2007/08/22}{postponed to -% \cs{begin\{document\}} to avoid overwriting by a~text command and -% made sensible to a~subsequent /} - +%^^A\pdef\*{\gmu@tilde} +% \changes[\*]{v0.97}{2008/11/29}{ removed (it was a~text tilde, +% available as \cmd\texttilde)} \AtBeginDocument{% to bypass redefinition of |\~| as a~text command % with various encodings \pdef\texttilde{% - % \changes{v0.86}{2007/12/11}{renamed from \cmd\~ - % since the latter is one of~\LaTeX\ accents} + % \changes{v0.83}{2007/08/22}{postponed to + % \cs{begin\{document\}} to avoid overwriting by a~text command + % and + % made sensible to a~subsequent + % /} % \changes{v0.86}{2007/12/11}{renamed from \cmd\~ + % since the latter is one of \LaTeX's\ accents} \@ifnextchar/{\gmu@tilde\kern-0,1667em\relax}\gmu@tilde}} % We prepare the proper kerning for ``\texttilde/''. @@ -3170,14 +5417,15 @@ pagella, fontspec=quiet]{gmdocc} {\def\defobeylines{\catcode`\^^M=13 \def^^M{\par}}} % Another thing I~dislike in \LaTeX\ yet is doing special things for -% |\...skip|'s, 'cause I~like the Knuthian simplicity. So I~sort of +% |\…skip|'s, 'cause I~like the Knuthian simplicity. So I~sort of % restore Knuthian meanings: % \changes{v0.63}{06/9/8}{Plain-like skip macros -% defined: \cs{deksmall/med/bigskip} i.e., moved here from +% defined: \cs{dek›(small⁄|med⁄|big›)skip} i.e., moved here from % another file} \def\deksmallskip{\vskip\smallskipamount} \def\undeksmallskip{\vskip-\smallskipamount} +\def\dekmedbigskip{\vskip\glueexpr \medskipamount+\smallskipamount} \def\dekmedskip{\vskip\medskipamount} \def\dekbigskip{\vskip\bigskipamount} @@ -3185,24 +5433,15 @@ pagella, fontspec=quiet]{gmdocc} \def\hfillneg{\hskip 0pt plus -1fill\relax} % \changes{v0.80}{2007/04/28}{added} -% In some |\if(cat?)|\ test I~needed to look only at the first token of -% a~tokens' string (first letter of a~word usually) and to -% drop the rest of it. So I~define a~macro that expands -% to the first token (or \marg{text}) of its argument. -% -\long\def\@firstofmany#1#2\@@nil{#1} -% \changes{v0.63}{06/9/9}{added} -\long\def\@secondofmany#1#2\@@nil{#2} - % A~mark for the \TODO{}s: \newcommand*{\TODO}[1][]{{% - \sffamily\bfseries\huge TODO!\if\relax#1\relax\else\space\fi#1}} + \sffamily\bfseries\huge TO-DO!\if\relax#1\relax\else\space\fi#1}} % \changes{v0.64}{06/9/17}{moved here from \pk{pmlectionis}} % \skiplines -% The code contained in this skiplines I~wrote to make the table of -% contents twocolumn. The first difficulties led me to making the +% The code contained in this |\skiplines| I~wrote to make the table of +% contents two-column. The first difficulties led me to making the % writes immediate at begin and end document but this also worked bad % in a~special situation, namely, when a~contents line was added on % the last page of the document. So for now I~give this way up and @@ -3228,8 +5467,8 @@ pagella, fontspec=quiet]{gmdocc} % }} % \endskiplines -% I~like twocolumn tables of contents. First I~tried to provide them by -% writing |\begin{multicols}{2}| and |\end{multicols}| outto the +% I~like two-column tables of contents. First I~tried to provide them by +% writing |\begin{multicols}{2}| and |\end{multicols}| out to the % \file{.toc} file but it worked wrong in some cases. So I~redefine the % internal \LaTeX\ macro instead. \newcommand*\twocoltoc{% @@ -3246,11 +5485,42 @@ pagella, fontspec=quiet]{gmdocc} % The macro given below is taken from the \pk{multicol} package (where % its name is |\enough@room|). I~put it in this package since I~needed % it in two totally different works. -\newcommand*\enoughpage[1]{% - \par - \dimen0=\pagegoal - \advance\dimen0 by-\pagetotal - \ifdim\dimen0<#1\relax\newpage\fi} +\DeclareCommand\enoughpage{% + Q{+-0123456789}% (optional short version (number of |\baselineskip|s)) + B{2\baselineskip}% (2) optional (formerly mandatory) long version of + % required room on a page + >is + B{} % (3) what if the room is enough + >isB{\newpage} % (4) what if there's to little room on a page +}{% + % \chgs{2009/03/18 v0.98 made \eTeX-ish} + % \chgs{2009/05/25 v0.98 made ifthenelse-like with ‘then’ and ‘else’ + % optional default \ and \cmd\newpage resp.} + % \chgs{2009/10/21 v0.98 \cmd\par\ removed since to let it be used + % for \cmd\pagebreak\ inside a paragraph} + % ^^A \par + \if + \ifdim\dimexpr\pagegoal-\pagetotal<\dimexpr + \IfValueTF{#1}{#1\baselineskip}{#2}\relax + 1\else0\fi + \unless\ifdim\dimexpr\pagegoal-\pagetotal<\z@ + 1\else2\fi + % \nostanza We check both whether space left on page is larger + % than we check \emph{and} whether it's nonnegative (the latter + % happens when we are already on the next page). Therefore this + % test will not work properly for large values of \inhash1 or + % values close to \incmd\textwidth. + % ^^A % \nostanza since 2009/03/18 the test is expandable but + % ^^A % I~leave this macro \inverb|\protected| because user's will to + % ^^A % make the test during the (e-)definition of some macro or while + % ^^A % expanding macros as in inserts seems to me not + % ^^A % very likely. \nostanza + \@xa\@firstoftwo + \else + \@xa\@secondoftwo + \fi + {#4}{#3}% +} %^^A % Two shorthands for debugging: %^^A %\Define\tOnLine\Define\OnAtLine @@ -3318,12 +5588,14 @@ pagella, fontspec=quiet]{gmdocc} \newcommand{\czer}[1]{\leavevmode{\czerwo##1}}% we leave % vmode because if we don't, then \env{verse}'s |\everypar| would be % executed in a~group and thus its effect lost. - \def\*{\czer{$*$}} - \def\+{\czer{$\dag$}} - \newcommand*\nieczer[1]{\textcolor{black}{##1}}} + \StoreMacro\*% + \def\*{\czer{\storedcsname{*}}}% + \def\+{\czer{†}}% + \newcommand*\nieczer[1]{\textcolor{black}{##1}}% +} % After the next definition you can write -% \cs{gmu@RP}\arg[options]\arg{package}\arg{\CS} to get the package |#2| +% \cs{gmu@RP}\arg[options]{package}{\CS} to get the package |#2| % loaded with options |#1| if the \CS |#3| is undefined. \newcommand*\gmu@RPfor[3][]{% \changes{v0.93}{2008/08/30}{renamed from % \cs{gmu@RPif} and \#3 changed from a~csname to \CS} @@ -3350,12 +5622,19 @@ pagella, fontspec=quiet]{gmdocc} \pprovide\continuum{% \gmu@RPfor{eufrak}\mathfrak\ensuremath{\mathfrak{c}}} -% And this macro I~saw in the \pk{ltugproc} document class nad I~liked +% And this macro I~saw in the \pk{ltugproc} document class and I~liked % it. \def\iteracro{% - \pdef\acro##1{\gmu@acrospaces##1 \gmu@acrospaces}% + \pdef\acro##1{% + \begingroup + \acropresetting + \gmu@acrospaces##1 \gmu@acrospaces + \endgroup + }% } +\emptify\acropresetting + \iteracro \def\gmu@acrospaces#1 #2\gmu@acrospaces{% @@ -3383,13 +5662,14 @@ pagella, fontspec=quiet]{gmdocc} % We extract the very thing done to the letters to a~macro because we % need to redefine it in fonts that don't have small caps. -\def\acrocore{\scshape\lowercase} +\pdef\acrocore{\smaller % was: |\scshape\lowercase| +} % Since the fonts I~am currently using do not support required font % feature, I~skip the following definition. -\newcommand*\IMO{\acro{IMO}} -\newcommand*\AKA{\acro{AKA}} +\def\IMHO{\acro{IMHO}} +\def\AKA{\acro{AKA}} \pdef\usc#1{{\addfontfeature{Letters=UppercaseSmallCaps}#1}} @@ -3419,7 +5699,7 @@ pagella, fontspec=quiet]{gmdocc} % the error message. -% Cf.\ \TeXbook\ exc.\ 11.6.\par +% Cf.\ \TeXbook\ ex.\ 11.6.\par % A~line from \LaTeX: % \[|% \check@mathfonts\fontsize\sf@size\z@\math@fontsfalse\selectfont|\] % didn't work as I~would wish: in a~|\footnotesize|'s scope it still @@ -3427,20 +5707,23 @@ pagella, fontspec=quiet]{gmdocc} % \changes{v0.81}{2007/05/13}{moved here from \pk{pmlectionis.cls}} \def\gmu@dekfraccsimple#1/#2{\leavevmode\kern.1em - \raise.5ex\hbox{%^^A \udigits - \smaller[3]#1}\gmu@numeratorkern + \raise.7ex\hbox{%^^A \udigits + \gmu@fracfontsetup#1}\gmu@numeratorkern \dekfraccslash\gmu@denominatorkern %^^A\lower.25ex\hbox {%^^A\udigits - \smaller[3]#2}% + \gmu@fracfontsetup#2}% \if@gmu@mmhbox\egroup\fi} +\def\gmu@fracfontsetup{% + \smaller[3]\addfontfeature{FakeBold=1}} + \def\dekfraccsimple{% \label{2292} \let\dekfracc@args\gmu@dekfraccsimple } -\@ifXeTeX{\def\dekfraccslash{\char"2044 }}{% - \def\dekfraccslash{/}} % You can define it as the fraction slash, +\@ifXeTeX{\def\dekfraccslash{\char"2044 }} +{\def\dekfraccslash{/}} % You can define it as the fraction slash, % %%%%% \nlpercent|\char"2044 |\ilrr \dekfraccsimple @@ -3450,22 +5733,15 @@ pagella, fontspec=quiet]{gmdocc} % A~macro that acts like |\,| (thin and unbreakable space) except it % allows hyphenation afterwards: -\newcommand*\ikern{\,\penalty10000\hskip0sp\relax} +\newcommand*\ikern{\,\penalty\@M\hskip\z@skip\relax} %\changes{v0.82}{2007/07/17}{added} % And a~macro to forbid hyphenation of the next word: -\newcommand*\nohy{\leavevmode\kern0sp\relax} -\newcommand*\yeshy{\leavevmode\penalty10000\hskip0sp\relax} -% In both of the above definitionc `0sp' not |\z@| to allow their +\pdef\nohy{\leavevmode\kern0sp\relax} +\pdef\yeshy{\leavevmode\penalty\@M\hskip\z@skip} +% In both of the above definitions `0sp' not |\z@| to allow their % writing to and reading from files where @ is `other'. -% \subdivision{\cs{@ifempty}} - -\long\pdef\@ifempty#1#2#3{% - \def\gmu@reserveda{#1}% - \ifx\gmu@reserveda\@empty\afterfi{#2}% - \else\afterfi{#3}\fi -} @@ -3532,13 +5808,103 @@ pagella, fontspec=quiet]{gmdocc} % should be closing. \def\inclasthook{\thispagestyle{closing}} +% \subdivision{Switching on and off parts of one file} +% +% The |\include| facility is very nice only it forces you to split +% your source in many files. Therefore I~provide a~tool analogous to +% |\include| and using the same |\includeonly| mechanism/list to +% switch on and off parts of the same source file. +% +\def\filepart#1{\relax + \ifnum\@auxout=\@partaux + \@latex@error{\string\filepart\space cannot be nested}\@eha + \else\afterfi{\@filepart#1 }\fi} + +\def\@filepart#1 {% + \clearpage + \edef\gmu@filepartname{#1}% we'll use it later + \if@filesw + \immediate\write\@mainaux{\string\@input{#1.aux}}% + \fi + \@tempswatrue + \if@partsw + \@tempswafalse + \@for\reserved@a:=\@partlist\do{% + \ifx\reserved@a\gmu@filepartname\@tempswatrue\fi}% + \fi + \if@tempswa + \let\@auxout\@partaux + \if@filesw + \immediate\openout\@partaux #1.aux + \immediate\write\@partaux{\relax}% + \fi + \@xa\@firstoftwo + % \label{spart:iftrue} + \else +% If the file is not included, reset |\@include| |\deadcycles|, so that a +% long list of non-included files +% does not generate an `Output loop' error. + \deadcycles\z@ + \@nameuse{cp@\gmu@filepartname}% + \let\@auxout\@mainaux + \@xa\@secondoftwo + \fi + {\iftrue}% + {\let\endfilepart\fi + \csname gm@skipped@#1\endcsname + \def\next{\RestoreMacro\endfilepart + \@ifnextchar\bgroup{\show\NextBgroup\@gobble}{}}% + \@xa\next\iffalse}% +} + + +\DeclareCommand\endfilepart{b}{% Note the argument is not used really. Maybe later we'll + % use it for checking of proper matching. Or maybe not. + \inclasthook + \clearpage + \@writeckpt{\gmu@filepartname}% + \if@filesw + \immediate\closeout\@partaux + \fi + \fi% this |\fi| closes |\Iftrue| put by line \ref{spart:iftrue}. + \let\@auxout\@mainaux +} + +\StoreMacro\endfilepart + +\def\nofileparts{% + \let\filepart\@gobble + \DeclareCommand\endfilepart{b}{}% +} + +% \subdivision{Fix of including when \pk{fontspec} is used} +% The \pk{fontspec} package creates counters for font families. If +% a~\pk{fontspec} command is used in a~part of a~document and then +% such a~part is skipped, an error occurs ‘No counter zf@fam@… +% defined’. Now we fix that by ensuring all the counters are defined +% before they are set. +% +% Note it's a~draft version which doesn't support resetting of one counter +% within another. + +\def\includecountfix{% + \def\@wckptelt##1{% + \immediate\write\@partaux{% + \providecounter{##1}% to + % provide the font counters defined + % in parts of the document. + \string\setcounter{##1}{\the\@nameuse{c@##1}}}}% +} + +\pdef\providecounter#1{% + \unless\ifcsname c@#1\endcsname\newcounter{#1}\fi} % \subdivision{Faked small caps} \def\gmu@scapLetters#1{% \ifx#1\relax\relax\else% two |\relax|es to cover the case of empty |#1|. - \ifcat a#1\relax + \ifcat a\@nx#1\relax \ifnum\the\lccode`#1=`#1\relax {\fakescapscore\MakeUppercase{#1}}% not Plain |\uppercase| % because that works bad with \pk{inputenc}. @@ -3567,7 +5933,7 @@ pagella, fontspec=quiet]{gmdocc} \let\fakescapscore\gmu@scalematchX % Experimente z~akcentami patrz no3.tex. -\def\tinycae{{\tiny\AE}}% to use in |\fakescaps[\tiny]{...}| +\def\tinycae{{\tiny\AE}}% to use in |\fakescaps[\tiny]{…}| \RequirePackage{calc} @@ -3581,7 +5947,7 @@ pagella, fontspec=quiet]{gmdocc} \ifx\zf@scale\empty\def\gmu@scalar{1.0}% \else\let\gmu@scalar\zf@scale\fi \setlength\@tempdima{\fontdimen5\font}% 5---ex height - \setlength\@tempdimb{\fontdimen8\font}% 8---\XeTeX\ synthesized + \setlength\@tempdimb{\fontdimen8\font}% 8---\XeTeX\ synthesised % uppercase height. \divide\@tempdimb by1000\relax \divide\@tempdima by\@tempdimb @@ -3629,11 +5995,23 @@ pagella, fontspec=quiet]{gmdocc} \def\napapierkicore{\advance\baselineskip% by 0ptplus\napapierkistretch\relax} -\newenvironment*{napapierki}{% - \par\global\napapierkicore}{% - \par\dimen\z@=\baselineskip - \global\baselineskip=\dimen\z@}% so that you can use |\endnapapierki| - % in interlacing environments. + +% ^^A % \catcode`\^^D\active \def^^D{\traceon} +% ^^A % \catcode`\^^E\active \def^^E{\traceoff\gmshowlists} +% ^^A \catcode`\^^D=9 +% ^^A \catcode`\^^E=9 +\DeclareEnvironment{napapierki}{s}{% + % \chgs{2009/01/05 v0.98 added optional star controlling globalness} + \par\IfValueT{#1}{\global + }% + \napapierkicore} +{% + \par + \IfValueT{#1}{\global\baselineskip=1\baselineskip\relax + }% +}% so that you can use \inverb|\napapierki*›…\endnapapierki*| +% in interlacing environments. + \newcount\gmu@luzniej @@ -3649,8 +6027,8 @@ pagella, fontspec=quiet]{gmdocc} \newenvironment*{luzniej}{\par\luzniejcore}{\par} -% The starred version does that |\everypar|, which has its advantages -% and disadvantages. +% The starred version sets |\looseness| in |\everypar|, which has its advantages +% and disadvantages.\nostanza \newenvironment*{luzniej*}[1][1]{% \multiply\tolerance by 2\relax \everypar{\looseness=#1\relax}}{\par} @@ -3659,33 +6037,21 @@ pagella, fontspec=quiet]{gmdocc} % parentheses and letters with descendants such as $j$ or $y$ in % certain fonts. % -% The original |\pauza| of \pk{polski} has the skips rigid (one is even -% a~kern). It begins with |\ifhmode| to be usable also at the -% beginning of a~line as the mark of a~dialogue. -% \Define\pauza\Define\pauzacore\Define\shortpauza -\ifdefined\XeTeXversion +% The original |\pauza| of \pk{polski} has the skips rigid (one is +% even a~kern). We make the skips flexible. Moreover, our |\pauza| +% begins with |\ifhmode| to be usable also at the beginning of a~line +% where it marks a~part of a~dialogue. + \def\pauza@skipcore{\hskip0.2em plus0.1em\relax - \pauzacore\hskip.2em plus0.1em\relax\ignorespaces}% + \pauzacore + \@ifnextchar,{% 2009/11/22 added a special case of a comma following pauza + }{\hskip.2em plus0.1em\relax\ignorespaces}}% % \def\ppauza@skipcore{\unskip\penalty10000\hskip0.2em plus0.1em\relax - –\hskip.2em plus0.1em\ignorespaces} + \ppauza@dash\hskip.2em plus0.1em\ignorespaces} % -\AtBeginDocument{% to be independent of moment of loading of \pk{polski}. - \pdef\—{% - \ifhmode - \unskip\penalty10000 - \afterfi{% - \@ifnextspace{\pauza@skipcore}% - {\@ifnextMac\pauza@skipcore{% - \pauzacore\penalty\hyphenpenalty\hskip\z@}}}% - \else - % According to \tytul{Instrukcja technologiczna.\ Skład ręczny ^^B - % i~maszynowy} the dialogue dash should be followed by a~rigid - % hskip of \dekfracc1/2\,em. - \leavevmode\pauzacore\penalty10000\hskip0,5em\ignorespaces - \fi}% - % The next command's name consists of letters and therefore it eats - % any spaces following it, so |\@ifnextspace| would always be false. + +\AtBeginDocument{% \pdef\pauza{% \ifhmode \unskip\penalty10000 @@ -3696,14 +6062,15 @@ pagella, fontspec=quiet]{gmdocc} \fi}% % % According to \tytul{Instrukcja technologiczna.\ Skład ręczny ^^B - % i~maszynowy} the dialogue dash should be followed by a~rigid - % hskip of \dekfracc1/2\,em. + % i~maszynowy} the dialogue dash (in Polish) should be followed by + % a~rigid hskip of \dekfracc1/2\,em. \pdef\pauzadial{% \leavevmode\pauzacore\penalty10000\hskip0,5em\ignorespaces} % - % And a~version with no space at the left, to begin a~|\noindent| - % paragraph or a~dialogue in quotation marks: + % And a~version with no space at the left, to begin a~|\noindent|ed + % paragraph explaining e.g.\ a~quotation: \pdef\lpauza{% + \leavevmode \pauzacore\hskip.2em plus0.1em\ignorespaces}% % % We define |\ppauza| as an en dash surrounded with thin stretchable @@ -3712,6 +6079,38 @@ pagella, fontspec=quiet]{gmdocc} % never get such a~space after a~literal \CS so an explicit |\ppauza| % will always result with a~bare discretionary en dash, but if we % |\let–\ppauza|… + % \stanza + \pdef\ppauza{% + \ifvmode \PackageError{gmutils}{% + command \bslash ppauza (en dash) not intended for vmode.}{% + Use \bslash ppauza (en dash) only in number and numeral ranges.}% + \else + \unskip\discretionary + {\ppauza@dash}{\ppauza@dash}{\ppauza@dash}% + \fi}% +}% of at begin document + +\ifdefined\XeTeXversion +% +\AtBeginDocument{% to be independent of moment of loading of \pk{polski}. + \pdef\—{% + \ifhmode + \unskip\penalty10000 + \afterfi{% + \@ifnextspace{\pauza@skipcore}% + {\@ifnextchar,{\pauza@skipcore}% a special case of comma added 2009/11/22 + {\@ifnextMac{\pauza@skipcore}% + {\pauzacore\penalty\hyphenpenalty\hskip\z@skip}}}% + }% of |\afterfi|'s argument + \else + % \nostanza According to \tytul{Instrukcja technologiczna.\ Skład ręczny ^^B + % i~maszynowy} the dialogue dash should be followed by a~rigid + % hskip of \dekfracc1/2\,em.\nostanza + \leavevmode\pauzacore\penalty10000\hskip0,5em\ignorespaces + \fi}% + % The next command's name consists of letters and therefore it eats + % any spaces following it, so |\@ifnextspace| would always be + % false, therefore we don't use it.\nostanza \pdef\–{% \ifvmode \PackageError{gmutils}{% command \bslash ppauza (en dash) not intended for vmode.}{% @@ -3719,18 +6118,12 @@ pagella, fontspec=quiet]{gmdocc} \else \afterfi{% \@ifnextspace{\ppauza@skipcore}{% - \@ifnextMac\ppauza@skipcore{\unskip\discretionary{–}{–}{–}}}% + \@ifnextMac\ppauza@skipcore + {\unskip\discretionary + {\ppauza@dash}{\ppauza@dash}{\ppauza@dash}}}% }% \fi }% - % - \pdef\ppauza{% - \ifvmode \PackageError{gmutils}{% - command \bslash ppauza (en dash) not intended for vmode.}{% - Use \bslash ppauza (en dash) only in number and numeral ranges.}% - \else - \unskip\discretionary{–}{–}{–}% - \fi}% % \def\emdash{\char`\—} }% of at begin document @@ -3738,9 +6131,22 @@ pagella, fontspec=quiet]{gmdocc} \def\longpauza{\def\pauzacore{—}} \longpauza \def\shortpauza{% - \def\pauzacore{–\kern,23em\relax\llap{–}}} + \def\pauzacore{\hbox{–\kern,23em\relax\llap{–}}}}% +\def\ppauza@dash{–}% + + +\else % not \XeTeX +\def\longpauza{\def\pauzacore{---}} +\longpauza +\def\shortpauza{% + \def\pauzacore{--\kern,23em\relax\llap{--}}}% +\def\ppauza@dash{--}% + + \fi% of if \XeTeX. + + % If you have all the three dashes on your keyboard (as I~do), you may want to use % them for short instead of |\pauza|, |\ppauza| and |\dywiz|. The % shortest dash is defined to be smart in math mode and result with @@ -3750,8 +6156,8 @@ pagella, fontspec=quiet]{gmdocc} \def\adashes{\AtBeginDocument\adashes}% because |\pauza| % is defined at begin document. \AtBeginDocument{\def\adashes{% - \catcode`—\active \let—\—% - \catcode`–\active \let–\–% + \catcode`—\active \def—{\—}% + \catcode`–\active \def–{\–}% % ^^A \catcode`-\active \let-\gmu@dywiz \addtomacro\dospecials{\do\–\do\—}% \addtomacro\@sanitize{\@makeother\–\@makeother\—}% @@ -3762,20 +6168,20 @@ pagella, fontspec=quiet]{gmdocc} \fi -% The hyphen shouldn't be active \acro{IMO} because it's used in \TeX\ +% The hyphen shouldn't be active \IMHO\ because it's used in \TeX\ % control such as |\hskip-2pt|. Therefore we provide the |\ahyphen| -% declaration reluctanly, because sometimes we need it and always use +% declaration reluctantly, because sometimes we need it and always use % it with caution. Note that my active hyphen in vertical and math % modes expands to |-|\catother. \def\gmu@dywiz{\ifmmode-\else \ifvmode-\else\afterfifi\dywiz\fi\fi}% -\foone{\catcode`-\active}{% - \def\ahyphen{\let-\gmu@dywiz\catcode`\-\active}} +\foone{\catcode`-\active}{% aktivnyj diefis aktywny dywiz active hyphen + \def\ahyphen{\let-\gmu@dywiz\catcode`\-\active}} -% To get current time. Works in \eTeX s, icluding \XeTeX. |\czas| +% To get current time. Works in \eTeX s, including \XeTeX. |\czas| % typesets \czas\ and |\czas[:]| typesets \czas[:]. \newcommand*\czas[1][.]{% \the\numexpr(\time-30)/60\relax#1% @@ -3808,183 +6214,97 @@ pagella, fontspec=quiet]{gmdocc} % A~date in the |YYYY-MM-DD| format we'll transform into % `\acro{DD mmmm YYYY}' -% format or we'll just typeset next two tokens/|{...}| if the +% format or we'll just typeset next two tokens/|{…}| if the % arguments' string begins with |--|. The latter option is provided to % preserve compatibility with already used macros and to avoid % a~starred version of |\thedate| and the same time to be able to turn % |\datef| off in some cases (for \file{SevSev04.tex}). -\newcommand*\polskadata{% - \def\gmu@datef##1-##2-##3##4,##5\gmu@datef{% - \ifx\relax##2\relax##3##4% - \else - \ifnum##3\@firstofmany##40\@@nil=0\relax - \else - \ifnum0##3=0\relax - \else##3% - \fi##4% - \fi - \ifcase##2\relax\or\ stycznia\or\ lutego% - \or\ marca\or\ kwietnia\or\ maja\or\ czerwca\or\ lipca\or\ sierpnia% - \or\ września\or\ października\or\ listopada\or\ grudnia\else - {}% - \fi - \if\relax##1\relax\else\ \fi ##1% - \fi - \gmu@datecomma{##5}}% of \incs{gmu@datef}. - % - \def\gmu@datefsl##1/##2/##3##4,##5\gmu@datefsl{% - \if\relax##2\relax##3##4% - \else - \ifnum##3\@firstofmany##40\@@nil=0\relax - \else - \ifnum0##3=0\relax - \else##3% - \fi##4% - \fi - \ifcase##2\relax\or\ stycznia\or\ lutego% - \or\ marca\or\ kwietnia\or\ maja\or\ czerwca\or\ lipca\or\ sierpnia% - \or\ września\or\ października\or\ listopada\or\ grudnia\else - {}% - \fi - \if\relax##1\relax\else\ \fi ##1% - \fi - \gmu@datecomma{##5}}% -}% of |\polskadata| - -%^^A \def\datef#1-#2-#3#4{\gmu@datef#1-#2-#3#4\gmu@datef}% -%^^A \def\datefsl#1/#2/#3#4{\gmu@datefsl#1/#2/#3#4\gmu@datefsl} +\pdef\polskadata{% + \DeclareCommand\gmu@datefsl{% + Q{0123456789\bgroup}>iT{/-} % (1) year + Q{0123456789\bgroup}>iT{/-} % (2) month + Q{0123456789\bgroup} % (3) day + T{,} K{##1\gmu@datefsl} % (4, 5) additional stuff after comma + }{% + \IfValueF{##2}{\PutIfValue{##3}}% + \IfValueT{##2}{% + \@tempcnta=0##3\relax\the\@tempcnta + \ifcase##2\relax\or\ stycznia\or\ lutego% + \or\ marca\or\ kwietnia\or\ maja\or\ czerwca\or\ lipca\or\ sierpnia% + \or\ września\or\ października\or\ listopada\or\ grudnia\else + {}% + \fi}% + \IfValueT{##1}{\space ##1}% + \PutIfValue{##4}\IfValueT{##5}{ ##5}% + }% of \incs{gmu@datefsl}. + }% of |\polskadata| \polskadata % For documentation in English: -\newcommand*\englishdate{% - \def\gmu@datef##1-##2-##3##4,##5\gmu@datef{% - \if\relax##2\relax##3##4% - \else - \ifcase##2\relax\or January\or February% - \or March\or April\or May\or June\or July\or August% - \or September\or October\or November\or December\else - {}% - \fi - \ifnum##3\@firstofmany##40\@@nil=0\relax - \else - \ % - \ifnum0##3=0\relax - \else##3% - \fi##4% - \ifcase##3\@firstofmany##4\relax\@@nil\relax\or st\or nd\or rd\else th\fi - \fi - \ifx\relax##1\relax\else,\ \fi ##1% - \fi - \gmu@datecomma{##5}}% -% - \def\gmu@datefsl##1/##2/##3##4,##5\gmu@datefsl{% - \if\relax##2\relax##3##4% - \else +\pdef\englishdate{% + \DeclareCommand\gmu@datefsl{% + Q{0123456789\bgroup}>iT{/-} % (1) year + Q{0123456789\bgroup}>iT{/-} % (2) month + Q{0123456789\bgroup} % (3) day + T{,} K{##1\gmu@datefsl} % (4, 5) additional stuff after comma + }{% + \IfValueF{##2}{\PutIfValue{##3}}% + \IfValueT{##2}{% \ifcase##2\relax\or January\or February% \or March\or April\or May\or June\or July\or August% \or September\or October\or November\or December\else {}% - \fi - \ifnum##3\@firstofmany##40\@@nil=0\relax - \else - \ % - \ifnum0##3=0\relax - \else##3% - \fi##4% - \ifcase##3\@firstofmany##4\relax\@@nil\relax\or st\or nd\or rd\else th\fi - \fi - \if\relax##1\relax\else,\ \fi ##1% - \fi - \gmu@datecomma{##5}}% -} - - -\def\gmu@datecomma#1{% sometimes we want to typeset something like `11 - % września, czwartek' so we add handling for comma in the - % \incs{ldate}'s argument. - \ifx\gmu@datecomma#1\gmu@datecomma\else - ,\gmu@stripcomma#1% - \fi -}% of |\gmu@datecomma| - -\def\gmu@stripcomma#1,{#1} - - -\newif\ifgmu@dash - -\def\gmu@ifnodash#1-#2\@@nil{% - \def\gmu@tempa{#2}% - \ifx\gmu@tempa\@empty} - -\pdef\gmu@testdash#1\ifgmu@dash{% - \gmu@ifnodash#1-\@@nil - \gmu@dashfalse - \else - \gmu@dashtrue - \fi - \ifgmu@dash} -% A~word of explanation to the pair of macros above. |\gmu@testdash| -% sets |\iftrue| the |\ifgmu@dash| switch if the argument contains an -% explicit |-|. To learn it, an auxiliary |\gmu@ifdash| macro is used -% that expands to an open (un|\fi|ed) |\ifx| that tests whether the -% dash put by us is the only one in the argument string. This is done -% by matching the parameter string that contains a~dash: if the -% investigated sequence contains (another) dash, |#2| of |\gmu@ifdash| -% becomes the rest of it and the `guardian' dash put by us so then -% it's nonempty. Then |#2| is took as the definiens of |\@tempa| so if -% it was empty, |\@tempa| becomesx equal |\@empty|, otherwise it isx -% not. -% -% Why don't we use just |\gmu@ifdash|? Because we want to put this -% test into another |\if...|. A~macro that doesn't \emph{mean} -% |\if...| wouldn't match its |\else| nor its |\fi| while \TeX\ would -% skip the falsified branch of the external |\if...| and that would -% result in the `extra |\else|' or 'extra |\fi|' error. -% -% Therefore we wrap the very test in a~macro that according to its -% result sets an explicit Boolean switch and write this switch right -% after the testing macro. (Delimiting |\gmu@testdash|'es parameter -% with this switch is intended to bind the two which are not one -% because of \TeX nical reasons only. -% -% Warning: this pair of macros may result in `extra |\else|/extra -% |\fi|' errors however, if |\gmu@testdash| was |\expandafter|ed. + \fi}% + \space + \@tempcnta=##3\relax\the\@tempcnta, + \IfValueT{##1}{ ##1}% + \PutIfValue{##4}\IfValueT{##5}{ ##5}% + }% of \incs{gmu@datefsl}. +}% % Dates for memoirs to be able to typeset them also as diaries. \newif\ifdate -%^^A|%\newcounter{dateinsection}[section]| +% ^^A|%\newcounter{dateinsection}[section]| \pdef\bidate#1{% - \ifdate\gmu@testdash#1% - \ifgmu@dash - \gmu@datef#1,\gmu@datef - \else - \gmu@datefsl#1,\gmu@datefsl - \fi\fi} + \gmu@datefsl#1\gmu@datefsl +} -\pdef\linedate{\@ifstar\linedate@@\linedate@} +\pdef\linedate{\gm@ifstar\linedate@@\linedate@} \pdef\linedate@@#1{\linedate@{--{}{}#1}} -\pdef\linedate@#1{\par\ifdate\addvspace{\dateskip}% +\pdef\linedate@#1{\par + \linedate@hook{#1}% + \ifdate\addvspace{\dateskipamount}% + \possvfil% if we put it before |\addvspace|, the v-space is always added. \date@line{\footnotesize\itshape \bidate{#1}}% - \nopagebreak\else%|%\ifnum\arabic{dateinsection}>0\dekbigskip\fi| - \addvspace{\bigskipamount}% + \nopagebreak + \else%|%\ifnum\arabic{dateinsection}>0\dekbigskip\fi| + \addvspace{\bigskipamount}\possvfil \fi}% end of |\linedate|. + +\let\linedate@hook\@gobble -\let\dateskip\medskipamount - -%^^A \pdef\date@biway#1{% -%^^A \gmu@testdash#1% -%^^A \ifgmu@dash\gmu@datef#1\gmu@datef -%^^A \else\gmu@datefsl#1\gmu@datefsl -%^^A \fi} - +\let\dateskipamount\medskipamount + \pdef\rdate{\let\date@line\rightline \linedate} + + +\def\date@left#1{\par{% + \raggedright#1% + \leftskip\z@skip + % ^^A \hangindent\z@skip + % ^^A \hangafter\z@ + % ^^A \parshape\z@ + % ^^A~wycinam, bo gryzło się z~floatingfigure. + \@@par}}% + \pdef\ldate{%\changes{v0.94}{2008/09/06}{\cs{leftline} % replaced with \cs{par}…\cs{par} to work well with \pk{floatflt}} - \def\date@line##1{\par{\raggedright##1\par}}% + \let\date@line\date@left \linedate} + \newcommand*\runindate[1]{% \paragraph{\footnotesize\itshape \gmu@datef#1\gmu@datef}% \stepcounter{dateinsection}} @@ -4020,140 +6340,173 @@ pagella, fontspec=quiet]{gmdocc} -\newcommand*\justified{% +\pdef\justified{% \leftskip=1\leftskip% to preserve the natural length and discard % stretch and shrink. \rightskip=1\rightskip \parfillskip=1\parfillskip \advance\parfillskip by 0sp plus 1fil\relax + % ^^A~\lastlinefit=700 \let\\\@normalcr} % To conform Polish recommendation for typesetting saying that % a~paragraph's last line leaving less than |\parindent| should be % stretched to fill the text width:\nostanza -\newcommand*\fullpar{% +\DeclareCommand\fullpar{% + T{+-}% + Q{+-0123456789} % optional looseness (most probably negative) +}{% + \begingroup + \IfValueT{#1}{\looseness=#1\IfValueTF{#2}{#2}{1}\relax + \multiply\tolerance by \tw@ + }% + \fullparcore + \par + \endgroup} + +\pdef\fullparcore{% \hunskip - \bgroup\parfillskip\z@skip\par\egroup} + \parfillskip\z@skip} -% To conform Polish recommendation for typesetting saying that the + +% To conform Polish recommendation for typesetting that says that the % last line of a~paragraph has to be 2|\parindent| long at least. The % idea is to set \cs{parfillskip} naturally rigid and long as % |\textwidth-2\parindent|, but that causes non-negligible shrinking % of the -% interword spaces so we provide a~declaration to catch the proper +% inter-word spaces so we provide a~declaration to catch the proper % glue where the parindent is set (e.g.\ in footnotes parindent is 0\,pt) \newcommand*\twoparinit{% the name stands for `\emph{last} paragraph % line's length \emph{min}imum \emph{two} \incs{parindent}. - \edef\twopar{% - \hunskip% it's \incs{protected}, remember? - \bgroup - \parfillskip=\the\glueexpr - \dimexpr\textwidth-2\parindent\relax - minus\dimexpr\textwidth-2\parindent\relax - \relax% to delimit |\glueexpr|. - \relax% to delimit the assignment. - \par\egroup - }% of \incs{gmu@twoparfill} - % ^^A \gmu@lastmintwo - % ^^A \ampulexdef\@arrayparboxrestore\parfillskip\lineskip{% - % ^^A \gmu@lastmintwo\lineskip}% we replace original setting of - % ^^A % \incs{parfillskip} by ours in \inenv{minipage} and \incs{footnote(text)}. + \def\twopar@defts{% + \hsize-\leftskip-\rightskip-\fontcharwd\font`…}% + \def\twopar@atleast{2\@parindent}% + \DeclareCommand\twopar{% + T{+-}% (1) you can specify loosening the paragraph by one only by + % typing single |+| and tightening by one by typing single |-|. + Q{+-0123456789}% (2) + A{\twopar@atleast}% (3) + >iT{\cipolagwa}}{% + \begingroup + \IfValueT{##1}{% + \looseness=##1\IfValueTF{##2}{##2}{1}\relax + \multiply\tolerance by2 + }% + \twoparcore<##3>% + \par + \endgroup + }% of \incmd\twopar. + % \stanza + \ifdefined\XeTeXversion + \DeclareCommand\twoparcore{% + A{\twopar@atleast}>iT{\cipolągwa}}{% + \hunskip % it's \ac{O.K.} it's in a~group, it'll work anyway. + \edef\gmu@tempa{\the\dimexpr\twopar@defts-##1\relax}% + \parfillskip=\glueexpr\gmu@tempa minus \gmu@tempa + \relax% to delimit |\glueexpr|. + \relax% to delimit the assignment. + }% + \else % not \XeTeX---doesn't use |\fontcharwd|. + \DeclareCommand\twoparcore{% + A{\twopar@default}>iT{\cipolagwa}}{% + \hunskip % it's \ac{O.K.} it's in a~group, it'll work anyway. + {\setbox0=\hbox{\dots}% + \xdef\gmu@tempa{\the\wd0}}% + \edef\gmu@tempa{% + \the\dimexpr\hsize-\leftskip-\rightskip + -\gmu@tempa-2\@parindent\relax}% + \parfillskip=\glueexpr\gmu@tempa minus \gmu@tempa + \relax% to delimit |\glueexpr|. + \relax% to delimit the assignment. + }% + \fi + % \stanza + \AtBeginDocument{% + \unless\ifdefined\@parindent + \newskip\@parindent + \@parindent=\parindent + \fi + \def\restoreparindent{\parindent\@parindent}% + }% of \cmd\AtBeginDocument. }% of \cs{twoparinit}. -% For dati under poems. - -\newcommand\wherncore[1]{% - \rightline{% - \parbox{0,7666\textwidth}{ - \leftskip0sp plus \textwidth - \parfillskip0sp\relax - \let\\\linebreak - \footnotesize #1}}} +% \subdivision{For dati under poems} +% Or explanations under results of \pk{time}. +\DeclareCommand\wherncore{om}{%\ + % \begin{enumargs} + % \dc optional value of \incs{hskip} of (left) indent of the parbox. If + % absent, parbox is aligned right; + % \dc text for the datum parbox. + % \end{enumargs} + \IfValueTF{#1}{\leftline{% + \whernfont + \hskip#1\relax\parbox + {\dimexpr\textwidth-\leftskip-\rightskip-#1}% + {#2}% of |\parbox|, + }% of |\leftline|, + }% of |ValueT{#1}|. + {% |ValueF{#1}|: + \rightline + {\whernfont + \whern@parbox{#2}% + }% of |\rightline|, + \setprevdepth + }% of |ValueF{#1}|, +}% of |\wherncore|. + + +\DeclareCommand\whern@parbox{% + S{\leftskip\rightskip}% horizontal alignment of resulting box (the + % side to be ragged) + O{t} % vertical alignment of parbox + >is % separator + O{0,7666\textwidth} % (3) width of parbox + m % (4) parbox contents +}{% + % \begin{enumargs} + % \dc S the skip of the ragged side, + % \dc the |\parbox|'s contents. + % \end{enumargs} + \parbox[#2]{#3}{% + \IfValueTF{#1}{#1}{\leftskip}=0sp plus \textwidth + \parfillskip0sp\relax + \let\\\linebreak + \disobeylines + \whernfont #4\unskip\strut\endgraf + \getprevdepth + }% of |\parbox|, +}% of |\whern@parbox|. + \def\whern{% - \@ifstar\wherncore{\vskip\whernskip\wherncore}} + \endgraf\nopagebreak + \gm@ifstar{\wherncore}% + {\vskip\whernskip\wherncore}} +\let\whernfont\footnotesize \newskip\whernskip \whernskip2\baselineskip minus 2\baselineskip\relax -\newcommand\whernup[1]{\par\wherncore{#1}} - - - - -% \subdivision{A~left-slanted font} Or rather a~left Italic \emph{and} -% left slanted font. In both cases we sample the skewness of the -% itshape font of the current family, we reverse it and apply to -% \cs{itshape} in \cs{litshape} and -% \cs{textlit} and to \cs{sl} in \cs{lsl}. Note -% a~slight asymmetry: \cs{litshape} and \cs{textlit} take the current -% family while \cs{lsl} and \cs{textlsl} the basic Roman family and -% basic (serif) Italic font. Therefore we introduce the \cs{lit} -% declaration for symmetry, that declaration left-slants \cs{it}. -% -% {\leftslanting -% I~introduced them first while typesetting E.~Szarzyński's -% \ty{Letters} to follow his (elaborate) hand-writing and now I copy -% them here when need left Italic for his \ty{Albert Camus' ^^B -% \ty{The Plague}} to avoid using bold font.\par} -% -% Of course it's rather esoteric so I~wrap all that in a~declaration. +\DeclareCommand\whernup{% + o % a~vskip before + >is % separating star (ignored) + o % (2) custom width of parbox + >Pm}{\par + \IfValueT{#1}{\vskip#1\relax}% + \leftline{% + \IfValueTF{#2}{\whern@parbox\rightskip[b][#2]}% + {\whern@parbox\rightskip[b]}% + {#3}% + }% + \setprevdepth + \nopagebreak\relax + \@ifenvir{quote}{\noindent\ignorespaces}{}} -\def\leftslanting{% - \pdef\litshape{% \changes{v0.93}{2008/08/22}{copied here from - % E.~Szarzyński's \ty{The Letters}} - \itshape - \@tempdima=-2\fontdimen1\font - \advance\leftskip by\strip@pt\fontdimen1\font ex % to assure al - % least the lowercase letters not to overshoot to the (left) - % margin. Note this has any effect only if there is a~\incs{par} in - % the scope. - \edef\gmu@tempa{% - \@nx\addfontfeature{FakeSlant=\strip@pt\@tempdima}}%^^B - % \ilrr when not \incs{edef}ed, it caused an error, which is - % perfectly understandable. - \gmu@tempa}% - % - % - \pdef\textlit##1{% \changes{v0.93}{2008/08/22}{added} - {\litshape##1}}% - % - \pdef\lit{\rm\litshape}% - % - % - \pdef\lsl{{\it - % \changes{v0.93}{2008/08/22}{copied here from E.~Szarzyński's \ty{The - % Letters}} - \@tempdima=-\fontdimen1\font - \xdef\gmu@tempa{% - \@nx\addfontfeature{RawFeature={slant=\strip@pt\@tempdima}}}}% - \rm % Note in this declaration we left-slant the basic Roman font - % not the itshape of the current family. - \gmu@tempa}% - % - % Now we can redefine \cs{em} and \cs{emph} to use left Italic for - % nested emphasis. In Polish typesetting there is bold in nested - % emphasis as I~have heard but we don't like bold since it perturbs - % homogeneous greyness of a~page. So we introduce a~three-cycle - % instead of two-: Italic, left Italic, upright. - % - \pdef\em{%\changes{v0.93}{2008/08/22}{added} - \ifdim\fontdimen1\font=\z@ \itshape - \else - \ifdim\fontdimen1\font>\z@ \litshape - \else \upshape - \fi - \fi}% - % - % - \pdef\emph##1{% \changes{v0.93}{2008/08/22}{added} - {\em##1}}% -}% of \cs{leftslanting}. %\subdivision{Thousand separator} @@ -4172,16 +6525,19 @@ pagella, fontspec=quiet]{gmdocc} \gmu@thou@put }} -\def\gmu@thou@fiver#1#2#3#4#5\gmu@thou@fiver#6#7{% - \ifx\relax#5\relax\afterfi{#6}\else\afterfi{#7}\fi} +\def\gmu@thou@fiver#1#2#3#4#5\gmu@thou@fiver#6#7{% this macro only + % checks if the text delimited with itself consists of at least five tokens/braces + \ifx\relax#5\relax\@xa\@firstoftwo + \else\@xa\@secondoftwo + \fi{#6}{#7}} \def\gmu@thou@putter#1#2{% we are sure to have at least five tokens - % before the guardian \incs{gmu@thou@putter}. + % before the sentinel \incs{gmu@thou@putter}. \advance\@tempcnta\@ne \@tempcntb\@tempcnta \divide\@tempcntb3\relax \@tempcnta=\numexpr\@tempcnta-\@tempcntb*3 - \edef\gmu@thou@put{\gmu@thou@put#1% + \edef\gmu@thou@put{\@xau{\gmu@thou@put}\unexpanded{#1}% \ifx\gmu@thou@putter#2\else \ifcase\@tempcnta \gmu@thou@o\or\gmu@thou@i\or\gmu@thou@ii% all three @@ -4214,19 +6570,24 @@ pagella, fontspec=quiet]{gmdocc} % \xathousep{\numexpr 90*8*7*6*120}. \def\shortthousep{% - \pdef\thous{% + \DeclareCommand\thous{Q{+-0123456789}}{% + % we declare it as a command with Q-type argument to allow spaces + % between digits. \ifmmode\hbox\bgroup\@gmu@mmhboxtrue\fi - \afterassignment\thous@inner - \@tempcnta=}%^^A} - % - \def\thous@inner{% - \ifnum\@tempcnta<0 $-$% - \@tempcnta=-\@tempcnta - \fi - \xathousep\@tempcnta - \if@gmu@mmhbox\egroup - \else\afterfi{\@ifnextcat a\space{}}% - \fi}% + \IfValueTF{##1}{% we are given a sequence of digits + \@tempcnta=##1\relax + \ifnum\@tempcnta<0 $-$% + \@tempcnta=-\@tempcnta + \fi + \xathousep\@tempcnta + \if@gmu@mmhbox\egroup + \else\@xa\spifletter + \fi + }% + {% no bare digits given, then we assume the argument is braced. + \thousep + }% + }% of |\thous|. }% of |\shortthousep|. % % And now write \shortthousep |\thous 3628800| to get \thous 3628800 even with @@ -4239,12 +6600,466 @@ pagella, fontspec=quiet]{gmdocc} \AtBeginDocument{% \@ifpackageloaded{hyperref}{% \StoreMacro\url - \def\url{\@ifstar{\nolinkurl}{\storedcsname{url}}}% + \pdef\url{\gm@ifstar{\nolinkurl}{\storedcsname{url}}}% }{}}} \@onlypreamble\urladdstar +% \subdivision{Footnotes suggested by Andrzej Tomaszewski} + +\DeclareCommand\ATfootnotes{s}{% \chgs{2008/11/29 v0.98 moved here + % from my own private macro package to allow the beauty of these + % footnotes for the general audience} + % \stanza + % We make the footnote mark in the footnote |\scriptsize| not + % |\scriptscriptsize|.\nostanza + \IfValueT{#1}% the following setting is suitable for old style + % numbers in footnote marks, therefore I~place it in the starred + % version of the command. + {\prependtomacro\gmu@ATfootnotes{% + \pdef\@makefnmark{% + \mbox {\normalfont \textsuperscript {\smaller[3]\@thefnmark }}}% + }% of prepend, + }% of |\IfValueT|. + % + \gmu@ATfootnotes + \gmu@AT@ampulex\maketitle% without \pk{hyperref} + \ifdefined\HyOrg@maketitle + \afterfi{\gmu@AT@ampulex\HyOrg@maketitle}% with \pk{hyperref} + \fi +} + +\pdef\gmu@AT@ampulex#1{% + \ampulexdef#1{\def\@makefnmark}% + \if@twocolumn + {\gmu@ATfootnotes\if@twocolumn}% Ampulex redefinition of + % \incs{maketitle} for the standard classes. + \ampulexdef#1{\long\def\@makefntext}% + \if@twocolumn{\gmu@ATfootnotes\if@twocolumn}% Ampulex redefinition + % of \incs{maketitle} for \pk{mwcls}. +} + +\pdef\gmu@ATfootnotes{% + % And we make the footnote number not be in superscript but on the + % base line, according to Andrzej Tomaszewski's suggestion on + % Bacho\TeX\ 2008, and the same size as in the footnote mark.\nostanza + \long\pdef\@makefntext##1{% + \ifdefined\@parindent \parindent\@parindent + \else \parindent 1em\relax + \fi + \indent{\ATf@font\scriptsize% ^^A \hphantom{19}\llap + {\@thefnmark}}% + \gmu@fnhook + \enspace\ignorespaces##1}% +} + +\let\ATf@font\normalfont + +\emptify\gmu@fnhook + +\pdef\rrthis{% ‘rag right this’: make only the current paragraph + % ragged right (e.g.\ if the paragraph consists of a~long \ac{URL}). + % \chgs{2008/12/01 v0.98 added} + \begingroup\rightskip=0sp plus \hsize \endgraf\endgroup} + +\pdef\centerthis{% 2009/12/15 + \begingroup + \rightskip=1\rightskip plus \hsize + \leftskip=1\leftskip plus\hsize + \parfillskip=\z@skip + \endgraf\endgroup} + + +\def\balsmiley#1 {}% to balance parentheses and brackets in + % smileys. \balsmiley( ;-) \inverb|\balsmiley( ;-)| +% \chgs{2008/12/9 v0.98 moved here from my personal macro package +% since I~needed it in the documentation of \pk{gmutils}}. +%^^A The \pk{wasysym} package defines \incs{smiley} as it should be, a~smiley +%^^A that is. + +\long\pdef\scantnoline#1{% ‘rescan tokens without adding line end’ + {\endlinechar\m@ne\scantokens{#1}}} +% \chgs{2008/12/14 v0.98 added} + +% \subdivision{A~fix to the \pk{url} package} +% +% It happened that a~\ac{URL}s typeset with the |\url| command of the +% \pk{url} package came out sort of spaced because kerning was off +% because of the math mode. So I~provide a~redefinition of the +% internal macros of the \pk{url} package which in my version uses not math mode but +% |\scantokens| and not |\relpenalty| and |\binoppenalty| but +% |\hyphenpenalty| (as it is in the paragraph) and +% |\discretionary|. I~tried putting explicit penalties after the +% symbols but that spoiled kerning. +% +% The rules of line breaking are somewhat different, too: in the original \pk{url} +% package line breaks are forbidden between any two symbols listed in +% |\UrlBigBreaks|. In my version line breaks are +% forbidden between any two \emph{identical} ‘\ac{URL} Breaks’ and +% ‘\ac{URL} Big Breaks’. +% +% There are some more differences in formatting some chars, i.a.\ |~|, +% |%| and angle brackets which I~don't treat specially and just take from font +% assuming the font provides \ac{ASCII} chars and checking whether it +% provides the angle brackets. +% +\@ifXeTeX{% + \pdef\UrlFix{\AtBeginDocument{% + \@ifpackageloaded{url}{\gm@UrlFix}{}}% + \relaxen\UrlFix}% + % + \AtBeginDocument{% + \pdef\UrlFix{% + \@ifpackageloaded{url}{\gm@UrlFix}{}% + \relaxen\UrlFix}}% +} +{% + \pdef\UrlFix{\PackageWarning{gmutils}{!!! The \string\UrlFix\space + declaration works only with XeTeX}}% +} + + +\@ifXeTeX{}{% + \edef\gmu@restoreUpUpUp{\catcode`\@nx\^^^=\the\catcode`\^^^}% + \AtEndOfPackage\gmu@restoreUpUpUp + \catcode`\^^^=9 } + +\def\gm@UrlFix{% + % \stanza + % default style assignments + \def\UrlBreaks{\do\.\do\@\do\\\do\/\do\!\do\_\do\|\do\;\do\]% + \do\)\do\,\do\?\do\'\do\"\do\+\do\=\do\#\do\%\do\~\do\_\do\|% + \do\{\do\}\do\$}% + \def\UrlBigBreaks{\do\:}% + \def\UrlNoBreaks{\do\(\do\[\do\{}% + \def\UrlSpecials{% + \do\ {\hbox{\visiblespace}}\do\^^M{\hbox{\visiblespace}}}% + % \stanza + % + % \stanza + \def\Url@Format##1{% + \UrlFont + \ifdefined\verbatim@specials + \catcode`\>\active + \verbatim@specials + \verbatim@mathhack + \fi % setting of + % the escape char, begin and end group and optionally math shift, + % defined in \pk{gmverb}. + \gm@UrlSetup + \UrlLeft + \edef\gmu@theendlinechar{\the\endlinechar}% + \endlinechar\m@ne + \kern\z@% to forbid hyphenating the first word if the \ac{URL} + % begins with a~word + \hyphenchar\font=\UrlHyphenchar\relax + \let\-\gmu@discretionaryhyphen + \scantokens{##1}% + \endlinechar\gmu@theendlinechar\relax + \UrlRight + }% of |\Url@Format|. + % \stanza + \edef\UrlHyphenchar{% + \ifdefined\gmv@hyphenchar\gmv@hyphenchar + \else"A6 \fi}% \label{UrlHyphenchar} broken bar, |¦| or the same as + % provided in \pk{gmverb} for verbatims. You + % can redefine it as you please. This char is used as the + % hyphenation char in \ac{URL}s and therefore should be different + % from |-| (hyphen), which is often a part of an \ac{URL}. The + % broken bar seems to be quite unlikely in \ac{URL}s and/or file + % names. + % \stanza + \def\verbatim@mathhack{% + \ifdefined\verbatim@specials@list + \@xa\verbatim@mathhack@\verbatim@specials@list + \fi + }% + % \stanza + \def\verbatim@mathhack@##1##2##3##4##5##6{% + \IfValueT{##4}{% + \edef\gmu@thinmuskip{\the\thinmuskip}% + \edef\gmu@medmuskip{\the\medmuskip}% + \edef\gmu@thickmuskip{\the\thickmuskip}% + \begingroup + \lccode`\~=`##4\lowercase{% + \endgroup\def~####1~}% + {$\thinmuskip\gmu@thinmuskip\relax + \medmuskip\gmu@medmuskip\relax + \thickmuskip\gmu@thickmuskip\relax + ####1% + $}% + \catcode`##4\active + }% + }% + %\stanza + \def\gm@UrlSetup{% + \medmuskip\Urlmuskip \thickmuskip\medmuskip \thinmuskip0mu% + \relpenalty\UrlBigBreakPenalty \binoppenalty\UrlBreakPenalty + % ^^A \exhyphenpenalty\@M % seems not to work. + % ^^A \hyphenpenalty\@M + \def\do{\gmu@doUrlMath\UrlBreakPenalty}\UrlBreaks % bin + % (\incs{hyphenpenalty} anyway) + \def\do{\gmu@doUrlMath\UrlBigBreakPenalty}\UrlBigBreaks % rel + % (\incs{hyphenpenalty} anyway) + \def\do{\gmu@doUrlMath\@M}\UrlNoBreaks % open (no break) + \def\do{\gmu@doUrlMathAc\UrlBreakPenalty}% (\incs{hyphenpenalty}) + \UrlSpecials + \if \iffontchar\font"2329 1\else0\fi\iffontchar\font"232A 1\else2\fi + % \nostanza we check whether the font provides both left and right + % angle brackets. \nostanza + \gmu@measurewd{^^^^2329}% + \edef\gmu@tempa{% + \@nx\gmu@doUrlMathAc\@M\@nx\<{% + \hbox to\gmu@tempb{\unexpanded{\hss\char"2329 \hss}}}% + }\gmu@tempa + \gmu@measurewd{^^^^232a}% + \edef\gmu@tempa{% + \@nx\do\@nx\>{% + \hbox to\gmu@tempb{\unexpanded{\hss\char"232A \hss}}}% + }\gmu@tempa + \else + \gmu@doUrlMathAc\@M\<{\langle}\do\>{\rangle}% + \fi + \iffontchar\font"22C6 % low star + \do\*{\hbox{\char"22C6 }}% + \else \do\**% + \fi + \ifx\do@url@hyp\@empty + \gmu@measurewd{-}% this macro is defined in line \ref{@measurewd}. + \edef\gmu@tempa{% + \unexpanded{\gmu@doUrlMathAc\@M\-}% + {\hbox to \gmu@tempb{\unexpanded{\hss-\hss}}% + \@nx\-}% hyphen is a + % good point for hyphenation, but the hyphenation char should + % be sth. else, and it is indeed: |¦| (broken bar, + % |\char"A6|). See also line \ref{UrlHyphenchar} + }\gmu@tempa + \fi + \addfontfeature{Ligatures=NoCommon, Mapping=none}% instead of + % ‘doing’ \incs{ver\+bat\+im\+@\+no\+lig\+@\+list}. + % ^^A \let\do\set@mathnolig \verbatim@nolig@list % prevent ligatures + }% of |\gm@UrlSetup|. + % \stanza + % ^^A \def\gmu@UrlBreakPenalty{\gobble{\penalty\UrlBreakPenalty\relax}}% + % ^^A \def\gmu@UrlBigBreakPenalty{\gobble{\penalty\UrlBigBreakPenalty\relax}}% + % ^^A \def\gmu@Url@M{\gobble{\penalty\@M\relax}}% + % + % \stanza + \def\gmu@doUrlMath##1##2{%\ + % \begin{enumargs} + % \item value of the penalty (used as a~Boolean: if $<$ + % \thous 10000, \nlperc\cs{hyphenpenalty} will be used anyway, if $\ge$ + % \thous10000, there will be no \incs{discretionary}), + % \item the char, given as |\⁄|. + % \end{enumargs} + % ^^A % \begin{enumargs} + % ^^A % \item a~type information macro that expands to |\gobble{⁄«penalty»}|, + % ^^A % \item the char, given as |\⁄|. + % ^^A % \end{enumargs} + % ^^A\gmu@measurewd{##3}% + \begingroup + \lccode`\~=`##2\lowercase{% + \endgroup\def~{\@ifnextchar~}% + \@xa\addtomacro\@xa~}% of |\lowercase|. + \ifnum##1<\@M + {% + {\char`##2\csname gmu@dbl\string##2kern\endcsname}% if next is the same char + {\ifmmode\char`##2% else + \else\gmu@urlbreakable{##1}{##2}% + \fi}% + }% of |\addtomacro|'s argument |\ifnum| true. + \else + {% + {\char`##2\csname gmu@dbl\string##2kern\endcsname}{\char`##2}% + }% of |\addtomacro|'s argument |\ifnum| false. + \fi + \catcode`##2=\active + }% of |\gmu@doUrlMath|. + % \stanza + \def\gmu@doUrlMathAc##1##2##3{%\ + % \begin{enumargs} + % \item (value of) a~penalty (see the remark to \inverb|##1| of + % the previous macro), + % \item the char (as |\⁄|), + % \item the definition. + % \end{enumargs} + \begingroup + \lccode`\~=`##2\lowercase{% + \endgroup\def~{\@ifnextchar~}% + \@xa\addtomacro\@xa~}% of |\lowercase|. + \ifnum ##1<\@M + {% + {\ifmmode\char`##2\else$##3\m@th$\fi}% + {\ifmmode\char`##2% + \else\discretionary{\hbox{$##3\m@th$}}{}{\hbox{$##3\m@th$}}% + \fi}% + }% of |\addtomacro|'s argument if num true. + \else + {% + {\ifmmode\char`##2\else$##3\m@th$\fi}{\ifmmode\char`##2\else$##3\m@th$\fi}% + }% of |\addtomacro|'s argument if num false. + \fi + \catcode`##2=\active + }% of |\gmu@doUrlMathAc|. + % \stanza + \pdef\gmu@url@rigidbreak##1##2{\discretionary{\char`##2}{}{\char`##2}}% + % \stanza + \pdef\gmu@url@flexbreak##1##2{\penalty\@M \hskip\z@ plus0,03em + \char`##2\penalty##1\hskip\z@ plus0,03em\relax}% + % \stanza + \let\gmu@urlbreakable\gmu@url@flexbreak + % \stanza + \def\Url@z##1{% + % Do any hyper referencing due to hyperref (or perform a url-def) + \Url@HyperHook + % Now do the formatting in a group (can also have \incs{Url@HyperHook} take + % this as an argument). \nostanza + {\Url@Format{##1}}% + \endgroup}% + % \stanza + \DeclareUrlCommand\file{\urlstyle{sf}}% + % \stanza + \emptify\Url@moving% with our settings |\url| is pretty allowed in + % moving arguments, I~hope. +}% of |\gmu@UrlFix|. + +\DeclareCommand\UrlSlashKern{O{tt}m}% +{\AtBeginDocument{% + \@nameedef{url@#1style}{\def\@nx\UrlFont{% + \@xa\@nx\csname#1family\endcsname + \def\@xa\@nx\csname gmu@dbl\string\/kern\endcsname + {\kern#2\relax}% + % ^^A \hyphenchar\font=124 + }% of |\UrlFont| + }% of |\url#1style| + \urlstyle{#1}% + }% of |\AtBeginDocument| +}% of |\UrlSlashKern| + + + + +% \division{Conditional tilde} +% +% Polish typesetting standards say that for 12 dd and 10 dd \ +% if leading is narrower that 3\dekfracc1/2 \, $ 3\dekfracc1/2 × 48$dd, +% then hanging letters are allowed, which also applies to 8 and 6 dd +% \ in less than 3 \ leading. I~treat this +% recommendation not strictly but as an inspiration, that is +% I~translate »dd« to »pt«. + +\def\TrzaskaTilde{% + \@xa\DeclareCommand\@xa\gm@smarttilde + \@xa{\@xa S\@xa{\all@stars~}}{% + \IfValueTF{##1}{\nobreakspace{}}% + {\ifdim\dimexpr\hsize-\leftskip-\rightskip + -\ifdim\hangindent<\z@-\fi\hangindent % the last + % parameter is used with respect to the \pk{floatflt} package. + >% + \ifdim\f@size pt>\dimexpr10pt-1sp\relax + 168dd + \else + 144dd + \fi + \nobreakspace {}% + \else + \ % + \fi + }% of |\gm@ifstar|'s else, + }% of |\gm@smarttilde|, + \let~\gm@smarttilde +}% of |\TrzaskaTilde|. + + +\pdef\getprevdepth{% + \endgraf + \xdef\setprevdepth{\prevdepth=\the\prevdepth\relax}% +} + +% \division{Storing the catcode of line end} +\def\StoreCatM{% + \protected\edef\RestoreCatM{% + \catcode`\@nx\^^M=\the\catcode`\^^M\relax}% +} + +\pdef\RestoreCatM{\PackageE{gmutils}{first store the catcode of + ^\empty^\empty M with \string\StoreCatM.}% +} + +% \division{A~really empty page} +% Copied from Marcin Woliński's macros. +% + +\newcommand{\clearemptydoublepage}{% + \newpage{\pagestyle{empty}\cleardoublepage}} + + +\DeclareCommand\setspaceskip{% + A{}% optional factor for all three components + O{\fontdimen2\font}% + >is + O{\fontdimen3\font}% + >is + O{\fontdimen4\font}} +{\spaceskip=#1#2plus#1#3minus#1#4\relax} + +\foone\obeylines{% + \def\disobeylines{% for arguments in which line end is active to + % simulate normal behaviour + \ifnum\catcode`\^^M=\active% + \pdef^^M{\@ifnextgroup{\ifhmode\unskip\space\fi}{\gmu@disMinner}}% + \def\gmu@disMinner##1{% + \ifx^^M##1\endgraf% + \else\afterfi{\ifhmode\unskip\space\fi}\fi##1}% + \fi}% +} + + +%^^A\def\gmu@lowstarfake{*} + + +\def\makestarlow{% + \begingroup\lccode`\~=`\*\lowercase{%% \Define** + \endgroup\def~{\gmu@lowstar}}% 2009/10/19 |\let| changed to + % \inverb|\def| to allow redefinitions of \incmd\gmu@lowstar. + \catcode`\*=\active + \defLowStarFake +} + +\DeclareCommand\defLowStarFake{% + Q{+-0123456789,.}{0,5}% fraction of fontchar depth of the star glyph +}% +{% + \def\gmu@lowstarfake{% + \leavevmode\vbox{\hbox{*}\kern#1\fontchardp\font`*}% + }% +} + + +\def\gmu@lowstarfake{*} % useful for next command where normal star is +% low. + + +% The |\*| \CS and active |*| should be defined different to make them +% distinguishable by tests, especially with |\gm@ifstar| in +% mind. + +\DeclareCommand\*{Q{0123456789}{1}} +% \label{def:gmu@star} +{\gmu@star@loop0{#1}} + +\def\gmu@star@loop#1#2{% this is an expandable loop as in The + % \eTeX\ Manual p.~9. + \ifnum#1<\numexpr#2\relax% + \gmu@lowstar + \@xa\gmu@star@loop + \@xa{\number\numexpr#1+1\@xa}% + \@xa{\number#2\@xa}% + \fi} + + + \endinput % % \ChangesGeneral @@ -4252,7 +7067,7 @@ pagella, fontspec=quiet]{gmdocc} % \changes{v0.70}{06/10/20}{Package renamed to \pk{gmutils} from % \pk{gmlpatch}. As my \protect\TeX\ Guru remarked rightly, the % previous name might suggest there was sth.\ wrong with \LaTeX\ which -% was not my intension} +% was not my intention} % % \changes{v0.74}{2006/11/28}{Added macros to make sectioning commands % of \pk{mwcls} and standard classes compatible. Now my sectionings @@ -4305,7 +7120,7 @@ pagella, fontspec=quiet]{gmdocc} % \cs{unex@nameuse}, probably never really used since they were % incomplete: \cs{edef@other} undefined} % -% \toCTAN{v0.96}{2008/11/21} +% \toCTAN{2008/11/21 v0.96} % % % \PrintChanges\PrintIndex @@ -4315,4 +7130,19 @@ pagella, fontspec=quiet]{gmdocc} %%% Local Variables: %%% mode: doctex %%% coding: utf-8 +%%% mode: flyspell +%%% ispell-local-dictionary: "british" %%% End: + +% LocalWords: xedekfraccplain dekfraccsimple doif ifnif sptoken xifnif lowstar +% LocalWords: dc oC soC oarg parg Ps LocalWords ifnextgroup xifncat ifncat xaS +% LocalWords: ifnextsingle seQuence activespace dofakeonum smarttilde prevdp +% LocalWords: reserveda fileext filepart tempswatrue partsw tempswafalse gmu +% LocalWords: tempswa filename filepartname partlist mainaux writeckpt nameuse +% LocalWords: prependtomacro xefraccdef xefracc mmhbox selectfont cepstnof +% LocalWords: reservedb tempd SMglobal smtempa SMglobalfalse MacroSt fontscale +% LocalWords: quotedstring getfontdata getfontscale getfontstring fontstring +% LocalWords: numeratorkern denominatorkern fracfontsetup maxnum minnum +% LocalWords: extremnum firstofmany normalcr tempcnta currfont reservedc +% LocalWords: maybestripcomma twocolumn thefnmark makefnmark ATfootnotes +% LocalWords: reservedd reservede -- cgit v1.2.3