%
% \GetFileInfo{gmutils.sty}
% \title{The \pk{gmutils} Package\thfileinfo}
% \author{Grzegorz Murzynowski}
% \maketitle
%
% \begin{copyrnote}
%
%%Written by Grzegorz Murzynowski,
%% natror at o2 dot pl
%%
%% \copyright\,2005, 2006, 2007 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.
%%
%% LPPL status: "author-maintained".\par
%%
%% Many thanks to my \TeX\ Guru Marcin Woli\'nski for his \TeX nical ^^A
%% support.
%
%\end{copyrnote}
%% 
%%
% \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}
% \chschange{v0.65}{06/9/28}{700}
% \chschange{v0.66}{06/10/5}{698}
% \chschange{v0.67}{06/10/11}{739}
% \chschange{v0.68}{06/10/12}{812}
% \chschange{v0.69}{06/10/17}{844}
% \chschange{v0.70}{06/10/20}{852}
% \chschange{v0.71}{06/10/27}{876}
% \chschange{v0.72}{06/11/14}{906}
% \chschange{v0.74}{06/12/1}{1185}
% \chschange{v0.76}{07/4/9}{1538}
% \chschange{v0.77}{07/4/14}{1547}
% \chschange{v0.78}{07/4/26}{1685}
% \chschange{v0.80}{2007/4/29}{1689}
% \chschange{v0.84}{2007/11/13}{2684}
% \chschange{v0.85}{2007/11/16}{2795}
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{gmutils}
     [2007/11/16 v0.85 some rather TeXnical macros, some of them tricky (GM)]

%
% \tableofcontents
%
% \division{Intro} 
% 
% The \pk{gmutils.sty} package provides some macros that are
% analogous to the standard \LaTeX\ ones but extend their
% functionality, such as |\@ifnextcat|, |\addtomacro| or |\begin(*)|.
%   The others are just conveniences I~like to use in all my TeX
%   works, such as |\afterfi|, |\pk| or |\cs|.
%
% I wouldn't say they are only for the package writers but I~assume
% some nonzero \LaTeXpar-awareness of the user.
%
% For details just read the code part.
%
% \begin{gmlonely}
%   \subdivision{Installation} Unpack the \file{gmutils-tds.zip}
%   archive (this is an archive that conforms the \acro{TDS} standard,
%   see \file{CTAN/tds/tds.pdf}) in some texmf directory or just put
%   the \pk{gmutils.sty} somewhere in the \file{texmf/\:tex/\:latex}
%   branch. Creating a~\file{texmf/\:tex/\:latex/\:gm} directory may
%   be advisable if you consider using other packages written by me.
%
%   Then you should refresh your \TeX\ distribution's files' database
%   most probably.
% \end{gmlonely}
%
% \subdivision{Contents of the \pk{gmutils.zip} Archive}
%
% The distribution of the \pk{gmutils} package consists of the
% following four files and a~\acro{TDS}-compliant archive.
% \begin{verse}
%   \pk{gmutils.sty}\\
%   \pk{README}\\
%   \pk{gmutilsDoc.tex}\\
%   \pk{gmutilsDoc.pdf}\\
%   \pk{gmutils.tds.zip}
% \end{verse}
% 
% \begin{gmlonely}
%   \subdivision{Compiling of the Documentation}
%
%   The last of the above files (the \pk{.pdf}, i.e., \emph{this
%     file}) is a~documentation compiled from the \pk{.sty} file by
%   running \LaTeX\ on the \pk{gmutilsDoc.tex} file twice,
%   then MakeIndex on the \file{gmutils.idx} file, and then \LaTeX\
%   on \file{gmutilsDoc.tex} once more.
%
%   MakeIndex shell command:
%   \[\hbox{|makeindex -r gmutilsDoc|}\]
%   The |-r| switch is to forbid MakeIndex to make implicit ranges since
%   the (code line) numbers will be hyperlinks.
%
%   Compiling the documentation requires the packages:
%   \pk{gmdoc} (\pk{gmdoc.sty} and \pk{gmdocc.cls}), \pk{gmverb.sty},
%   \pk{gmutils.sty}, \pk{gmiflink.sty}  and also some standard packages:
%   \pk{hyperref.sty}, \pk{color.sty}, \pk{geometry.sty},
%   \pk{multicol.sty}, \pk{lmodern.sty}, \pk{fontenc.sty} that should
%   be installed on your computer by default.
%
%   If you had not installed the \pk{mwcls} classes (available on
%   CTAN and present in \TeX\ Live e.g.), the result of your
%   compilation might differ a~bit from the \pk{.pdf} provided in this
%   \pk{.zip} archive in formatting: If you had not installed
%   \pk{mwcls}, the standard \pk{article.cls} class would be used.
% \end{gmlonely}
%
% 
% \division{A~couple of abbreviations}
% \Define\@xa \Define\@nx
\let\@xa\expandafter
\let\@nx\noexpand

%
% The |\newgif| declaration's effect is used even in the \LaTeXe\
% source by redefining some particular user defined ifs (UD-ifs
% henceforth) step by step.  The goal is to make the UD-if's
% assignment global. I~needed it at least twice during \pk{gmdoc}
% writing so I~make it a~macro. It's an almost verbatim copy of
% \LaTeX's |\newif| modulo the letter $g$ and the |\global| prefix.
% (File d: \file{ltdefns.dtx} Date: 2004/02/20 Version v1.3g, lines
% 139--150) \Define\newgif
\def\newgif#1{%
  {\escapechar\m@ne
    \global\let#1\iffalse
    \@gif#1\iftrue
    \@gif#1\iffalse
  }}
% `Almost' is also in the detail that in this case, which deals with
% |\global| assignments, we don't have to bother with storing and
% restoring the value of |\escapechar|: we can do all the work inside
% a~group.
% \DefIndex\@gif
\def\@gif#1#2{%
  \@xa\gdef\csname\@xa\@gobbletwo\string#1%
  g% the letter $g$ for `|\global|'.
  \@xa\@gobbletwo\string#2\endcsname
  {\global\let#1#2}}

% After |\newgif\iffoo| you may type |{\foogtrue}| and the |\iffoo|
% switch becomes globally equal |\iftrue|. Simili modo |\foogfalse|.
% 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
% it both with |\newif| and |\newgif|.
%
% Note that it's just a~shorthand. |\global\if|\<switch>|true/false|
% \emph{does} work as expected.

% \Define\grefstepcounter
% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}.}
% There's a~trouble with |\refstepcounter|: defining |\@currentlabel|
% is local. So let's |\def| a~|\global| version of |\refstepcounter|.
%
% Warning. I~use it because of very special reasons in \pk{gmdoc} and
% in general it is probably not a~good idea to make |\refstepcounter|
% global since it is contrary to the original \LaTeX\ approach.
\newcommand*\grefstepcounter[1]{%
  {\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|.
% 
% Thanks to using the true |\refstepcounter| inside, it observes the
% change made to |\refstepcounter| by \pk{hyperref}.
% \dekmedskip
%
% Another shorthand. It may decrease a~number of |\expandafter|s e.g.
% \Define\glet
\def\glet{\global\let}


% \LaTeX\ provides a~very useful |\g@addto@macro| macro that adds its
% second argument to the current definition of its first argument
% (works iff the first argument is a~no argument macro). But I~needed
% it some times in a~document, where |@| is not a~letter. So:
% \Define\gaddtomacro
\let\gaddtomacro=\g@addto@macro

% 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|.)

% And for use in the very document,
% \Define\addtomacro
\let\addtomacro=\addto@macro

% \Define\addtotoks
\long\def\addtotoks#1#2{%
  #1=\@xa{\the#1#2}}

%\Define\@emptify \Define\emptify
\newcommand*\@emptify[1]{\let#1=\@empty}
\@ifdefinable\emptify{\let\emptify\@emptify}

% Note the two following commands are in fact one-argument.
%\Define\g@emptify \Define\gemptify
\newcommand*\g@emptify{\global\@emptify}
\@ifdefinable\gemptify{\let\gemptify\g@emptify}

% \Define\@relaxen \Define\relaxen
\newcommand*\@relaxen[1]{\let#1=\relax}
\@ifdefinable\relaxen{\let\relaxen\@relaxen}

% Note the two following commands are in fact one-argument.
% \Define\g@relaxen \Define\grelaxen
\newcommand*\g@relaxen{\global\@relaxen}
\@ifdefinable\grelaxen{\let\grelaxen\g@relaxen}


% 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,
%
% \Define\gmshowlists 
% \changes{v0.59}{06/09/04}{moved here from \pk{gmdoc}}
\def\gmshowlists{\showboxdepth=1000 \showboxbreadth=1000 \showlists}

% \Define\nameshow
\newcommand*\nameshow[1]{\@xa\show\csname#1\endcsname}


% 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}


% \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\@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
  \fi
  \reserved@c}

{\def\:{\let\@sptoken= } \: % 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\@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
  \else
    \if\reserved@d\@nx\@let@token
      \let\reserved@c\reserved@a
    \else
      \let\reserved@c\reserved@b
    \fi
  \fi
  \reserved@c}

% \UnDef
{\def\:{\let\@sptoken= } \: % this makes |\@sptoken| a space token.
% \UnDef
\def\:{\@xifnif} \@xa\gdef\: {\futurelet\@let@token\@ifnif}}

% \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.
% \Define\@ifnextac
% \changes{v0.75}{2007/01/11}{added}
%
\long\def\@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}

% 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= }%
\* %

% \Define\@ifnextspace
\def\@ifnextspace#1#2{%
  \let\@reserveda\*%
  \def\*{%
    \let\*\@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.

% \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 in general it's only a~matter of taste which one to
% use.
%
% One warning: those macros peel the braces off, i.e., 
% \[|\if..\afterfi{\@makeother\^^M}\fi|\] 
% causes a~leakage of
% |^^M|\catother. To avoid pollution write 
% \[|\if..\afterfi{\bgroup\@makeother\^^M\egroup}\fi|\,.\] 
%
% \Define\afterfi \Define\afterfifi 
% \Define\afteriffifi

\long\def\afterfi#1#2\fi{\fi#1}
% And two more of that family:
\long\def\afterfifi#1#2\fi#3\fi{\fi\fi#1}
\long\def\afteriffifi#1#2\if#3\fi#4\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{Almost an Environment or Redefinition of \cs{begin}}
%
% We'll extend the functionality of |\begin|: the non-starred
% instances shall act as usual and we'll add the starred version. The
% difference of the latter will be that it won't check whether the
% `environment' has been defined so any name will be allowed. 
%
% This is intended to structure the source with named groups that
% don't have to be especially defined and probably don't take any
% particular action except the scoping.
%
%  (If the |\begin*|'s argument is a~(defined) environment's name,
%  |\begin*| will act just like |\begin|.)
% \dekmedskip
%
% Original \LaTeX's |\begin|:
% \begin{verbatim}
%\def\begin#1{%
%  \@ifundefined{#1}%
%    {\def\reserved@a{\@latex@error{Environment #1 undefined}\@eha}}%
%    {\def\reserved@a{\def\@currenvir{#1}%
%        \edef\@currenvline{\on@line}%
%        \csname #1\endcsname}}%
%    \@ignorefalse
%    \begingroup\@endpefalse\reserved@a}
%\end{verbatim}
% 
%   \Define\@begnamedgroup
\@ifdefinable\@begnamedgroup{\relax}
\def\@begnamedgroup#1{%
  \@ignorefalse% not to ignore blanks after group
  \begingroup\@endpefalse
  \def\@currenvir{#1}%
  \edef\@currenvline{\on@line}%
  \csname #1\endcsname}% if the argument is a~command's name (an
% environment's e.g.), this command will now be executed. (If the
% corresponding control sequence hasn't been known to \TeX, this line
% will act as |\relax|.)

% For back compatibility with my earlier works
% \Define\bnamegroup
% \Define\enamegroup
\let\bnamegroup\@begnamedgroup
% And for the ending
\def\enamegroup#1{\end{#1}}

% And we make it the starred version of |\begin|.
%   \begin{DoIndex}{\begin}
%   \Define\old@begin \Define\begin
\let\old@begin\begin
  % \Define*\begin*
\def\begin{\@ifstar{\@begnamedgroup}{\old@begin}}
% \end{DoIndex}

% \division{Improvement of \cs{end}}
%
% \changes{v0.74}{2006/11/27}{The catcodes of \cs{begin} and \cs{end}
% argument(s) don't have to agree strictly anymore: an environment is properly
% closed if the \cs{begin}'s and \cs{end}'s arguments result in the
% same \cs{csname}}
%
% It's very clever and useful that |\end| checks whether its argument
% is |ifx|-equivalent |@currenvir|. However, 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 the char catcodes are
% equivalent. Thus should be also in the |\end|'s test and therefore
% we ensure the compared texts are both expanded and made all `other'.

\def\@checkend#1{%
  \edef\reserved@a{\@xa\string\csname#1\endcsname}%
  \edef\exii@currenvir{\@xa\string\csname\@currenvir\endcsname}%
  \ifx\reserved@a\exii@currenvir\else\@badend{#1}\fi}

% Thanks to it you may write |\begin{macrocode*}| with |*|\catother
% and end it with |\end{macrocode*}| with |*|\catletter\ (that was the
% problem that led me to this solution). The error messages looked
% really funny:
% $$\hbox{|! LaTeX Error: \begin{macrocode*} on input line 1844 ended by \end{macrocode*}.|}$$
% Of course, you might write
% also |\end{macrocode\star}| where |\star| is defined as `other' star
% or letter star.


%\division{From \pk{relsize}}
%
%\changes{v0.58}{06/09/02}{Relative fontsize 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
% \url{asnd@triumf.ca} and Matt Swift \url{swift@bu.edu} after the
% \LaTeX\,2.09 \pk{smaller.sty} style file written by Bernie Cosell
% \url{cosell@WILMA.BBN.COM}\,.
%
% 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
% \<n> 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.
% \TextUsage\smaller${}=={}$|\relsize{-1}|;
% \TextUsage\larger${}=={}$|\relsize{1}|. \TextUsage\smallerr (my
% addition)${}=={}$|\relsize{-2}|; \TextUsage\largerr\ guess yourself.
% 
% (Since |\DeclareRobustCommand|
% doesn't issue an error if its argument has been defined and it only
% informs about redefining, loading \pk{relsize} remains allowed.)
% \Define\relsize
\DeclareRobustCommand*\relsize[1]{%
  \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\footnotesize 2\else
          \ifx\@currsize\large 5\else
           \ifx\@currsize\Large 6\else
            \ifx\@currsize\LARGE 7\else
             \ifx\@currsize\scriptsize 1\else
              \ifx\@currsize\tiny 0\else
               \ifx\@currsize\huge 8\else
                \ifx\@currsize\Huge 9\else
                4\rs@unknown@warning % unknown state: |\normalsize| as starting point
     \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
%  Change the number by the given increment:
     \advance\@tempcnta#1\relax
%  watch out for size underflow:
      \ifnum\@tempcnta<\z@ \rs@size@warning{small}{\string\tiny}\@tempcnta\z@ \fi
      \@xa\endgroup
      \ifcase\@tempcnta  % set new size based on altered number
         \tiny \or \scriptsize \or \footnotesize \or \small \or \normalsize \or 
         \large \or \Large \or \LARGE \or \huge \or \Huge \else 
          \rs@size@warning{large}{\string\Huge}\Huge
\fi\fi}% end of |\relsize|.

% \Define\rs@size@warning
\providecommand*\rs@size@warning[2]{\PackageWarning{gmutils (relsize)}{%
 Size requested is too #1.\MessageBreak Using #2 instead}}

% \Define\rs@unknown@warning
\providecommand*\rs@unknown@warning{\PackageWarning{gmutils (relsize)}{Current font size 
 is unknown! (Why?!?)\MessageBreak Assuming \string\normalsize}}

% And a~handful of shorthands: 
%
% \Define\larger \Define\smaller \Define\textlarger
% \Define\textsmaller \Define\largerr \Define\smallerr
\DeclareRobustCommand*\larger[1][\@ne]{\relsize{+#1}}
\DeclareRobustCommand*\smaller[1][\@ne]{\relsize{-#1}}
\DeclareRobustCommand*\textlarger[2][\@ne]{{\relsize{+#1}#2}}
\DeclareRobustCommand*\textsmaller[2][\@ne]{{\relsize{-#1}#2}}
\DeclareRobustCommand*\largerr{\relsize{+2}}
\DeclareRobustCommand*\smallerr{\relsize{-2}}

% \division{\cs{firstofone} and the Queer \cs{catcode}s}
%
% Remember that once a~macro's argument has been read, its
% |\catcode|s are assigned forever and ever. That's what is
% |\firstofone| for. It allows you to change the |\catcode|s locally
% for a~definition \emph{outside} the changed |\catcode|s' group.
% Just see the below usage of this macro `with \TeX's eyes', as my
% \TeX\ Guru taught me.
%
\long\def\firstofone#1{#1}

% The next command, |\foone|, is intended as two-argument for
% shortening of the |\bgroup...\firstofone{\egroup...}| hack.
% 
\long\def\foone#1{\bgroup#1\egroupfirstofone}
% \UnDef
\long\def\egroupfirstofone#1{\egroup#1}

\long\def\fooatletter{\foone\makeatletter}



% And this one is defined, I~know, but it's not |\long| with the
% standard definition.
% \Define\gobbletwo
\long\def\gobble#1{}
\let\gobbletwo\@gobbletwo


% \Define\subs
\foone{\catcode`\_=8 }%
{\let\subs=_}

\foone{\@makeother\_}%
{\def\xiiunder{_}}

\@ifundefined{XeTeXversion}{}{%
  \def\xiiunder{\char"005F }%
  \let\_\xiiunder}


% 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\\

\@ifundefined{bslash}{\let\bslash=\xiibackslash}{}


%    \begin{oldmc}
\foone{\@makeother\%}
{\def\xiipercent{%}}
%    \end{oldmc}

\foone{\@makeother\&}%
{\def\xiiand{&}}

\foone{\@makeother\ }%
{\def\xiispace{ }}

%\division{Metasymbols}
% I~fancy also another Knuthian trick for typesetting \<metasymbols>
% 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
% make it |\long|.
% \dekmedskip
%
% \begin{quotation}
% The new implementation fixes this problem by defining
% |\meta| in a radically different way: we prevent hypenation by defining a |\language|
% which has no patterns associated with it and use this to typeset the words within
% the angle brackets.
% \end{quotation}
% \Define\meta \DefIndex\l@nohyphenation
\ifx\l@nohyphenation\undefined
  \newlanguage\l@nohyphenation
\fi
\DeclareRobustCommand*\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
  {%
    \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.
% \DefIndex\meta@hyphen@restore
    \edef\meta@hyphen@restore{%
      \hyphenchar\the\font\the\hyphenchar\font}%
    \hyphenchar\font\m@ne
    \language\l@nohyphenation
    #1\/%
    \meta@hyphen@restore
  }\ensuremath\rangle
}

% \DefIndex\meta@font@select
% \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*{\<...>}
\def\<#1>{\meta{#1}}

% \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
% |\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{\kern0sp\discretionary{#1}{#2}{#3}\penalty10000\hskip0sp\relax}
\def\discret#1{\kern0sp\discretionary{#1}{#1}{#1}\penalty10000\hskip0sp\relax}

% 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}

% \Define\vs
\newcommand*{\vs}{\discre{\textvisiblespace}{}{\textvisiblespace}}

% 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
% effect).
%
% \Define\printspaces
%^^A\def\printspaces#1{\gm@printspaces#1\@@nil}
%^^A CodeDefIndex\gm@printspaces
% ^^A~originally it has a~version with the argument delimited with /
% ^^A but recently I~don't like this delimiter.
% ^^A A~test: \printspaces{Ala ma kota }\par
% ^^A \printspaces{Ala ma aligatora}
\def\printspaces#1{{\let~=\vs \let\ =\vs \gm@pswords#1 \@@nil}}
% \DefIndex\gm@pswords
\def\gm@pswords#1 #2\@@nil{%
  \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 |\gm@pswords| the argument string is
% not extended with a~guardian space: it has been already by
% |\printspaces|.

% \Define\sfname \Define\file
\DeclareRobustCommand*\sfname[1]{\textsf{\printspaces{#1}}}
\let\file\sfname% it allows the spaces in the filenames (and prints
% them  as \vs).

% The below macro I~use to format the packages' names.
% \Define\pk \Define\file
\DeclareRobustCommand*{\pk}[1]{\textsf{\textup{#1}}}

% Some (if not all) of the below macros are copied from \pk{doc}
% and/or \pk{ltxdoc}.
% 
% A~macro for printing control sequences in arguments of
% a~macro. Robust to avoid writing an explicit |\| into a~file. It
% 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}}

% \Define\env
% \changes{v0.66}{06/09/29}{the braces removed}
\DeclareRobustCommand*{\env}[1]{\cs[]{#1}}

% And for the special sequences like |^^A|:
\foone{\@makeother\^}
  {\DeclareRobustCommand*\hathat[1]{\cs[^^]{#1}}}


% And one for encouraging linebreaks e.g., before long verbatim words.
% \Define\possfil
\newcommand*\possfil{\hfil\penalty1000\hfilneg}

% The five macros below are taken from the \pk{ltxdoc.dtx}.
%
% \begin{quotation}|\cmd{\foo}| Prints |\foo| verbatim. It may be used inside moving
% arguments. |\cs{foo}| also prints |\foo|, for those who prefer that
% 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
\def\cmd@to@cs#1#2{\char\number`#2\relax}

% |\marg{text}| prints \marg{text}, `mandatory argument'.
% \Define\marg
\def\marg#1{{\ttfamily\char`\{}\meta{#1}{\ttfamily\char`\}}}

% |\oarg{text}| prints \oarg{text}, `optional argument'.
% Also |\oarg[text]| does that.
% \Define\oarg
\def\oarg{\@ifnextchar[\@oargsq\@oarg}
%^^A]
\def\@oarg#1{{\ttfamily[}\meta{#1}{\ttfamily]}}
\def\@oargsq[#1]{\@oarg{#1}}

% |\parg{te,xt}| prints \parg{te,xt}, `picture mode argument'.
% \Define\parg
\def\parg{\@ifnextchar(\@pargp\@parg}
%^^A)
\def\@parg#1{{\ttfamily(}\meta{#1}{\ttfamily)}}
\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}%
}

% \division{Storing and Restoring the Meanings of CSs}
%
% First a~Boolean switch af globalness of assignments and 
% its verifier.
\newif\ifgmu@SMglobal

\def\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}}
\def\StoreMacro{%
  \bgroup\makeatletter\@ifstar\egStore@MacroSt\egStore@Macro}

\long\def\egStore@Macro#1{\egroup\Store@Macro{#1}}
\long\def\egStore@MacroSt#1{\egroup\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
    % \cs{(Re)StoreMacro} and \cs{(Re)StoreMacro*}, that is. to allow
    % writing e.g.  |\StoreMacro\kitten| and then
    % |\RestoreMacro*{kitten}| to restore the meaning of |\kitten|.
    \@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

\long\def\StoreMacros{\bgroup\makeatletter\Store@Macros}
\long\def\Store@Macros#1{\egroup
  \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}}
\def\RestoreMacro{%
  \bgroup\makeatletter\@ifstar\egRestore@MacroSt\egRestore@Macro}

\long\def\egRestore@Macro#1{\egroup\Restore@Macro{#1}}
\long\def\egRestore@MacroSt#1{\egroup\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\def\RestoreMacros{\bgroup\makeatletter\Restore@Macros}

\long\def\Restore@Macros#1{\egroup
  \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{\bgroup\makeatletter\Stored@Macro}
\long\def\Stored@Macro#1{\egroup\Restore@Macro#1#1}

% 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'.


% 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}



% \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.


% \Define\not@onlypreamble
% \changes{v0.79}{2007/04/28}{All the actions are done in a~group and
% therefore \cs{xdef} used instead of \cs{edef} because this command
% has to use \cs{do} (which is contained in the \cs{@preamblecmds}
% list) and \cs{not@onlypreamble} itself should be able to be let to
% \cs{do}} 
\newcommand\not@onlypreamble[1]{{%
  \def\do##1{\ifx#1##1\else\@nx\do\@nx##1\fi}%
  \xdef\@preamblecmds{\@preamblecmds}}}



\not@onlypreamble\@preamblecmds
\not@onlypreamble\@ifpackageloaded
\not@onlypreamble\@ifclassloaded
\not@onlypreamble\@ifl@aded
\not@onlypreamble\@pkgextension

% And let's make the message of only preamble command's forbidden use
% informative a~bit:

\def\gm@notprerr{ can be used only in preamble (\on@line)}

\AtBeginDocument{%
  \def\do#1{\@nx\do\@nx#1}%
  \edef\@preamblecmds{%
    \def\@nx\do##1{%
      \def##1{! \@nx\string##1 \@nx\gm@notprerr}}%
    \@preamblecmds}}






% \division{Third Person Pronouns}
%
% 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}}

% \division[To Save Precious Count Registers]{\gmhypertarget{To Save Precious Count Registers}}
%
% It's a~contribution to \TeX's ecology \gobble(;-). You can use as
% many CSs as you wish and you may use only 256 count registers
% (although in \eTeX\ there are $2^{16}$ count registers, which makes
% the following a~bit obsolete).

\newcommand*\nummacro[1]{\gdef#1{0}}

\newcommand*\stepnummacro[1]{%
  \@tempcnta=#1\relax
  \advance\@tempcnta by1\relax
  \xdef#1{\the\@tempcnta}}% Because of some mysterious reasons
% explicit |\count0| interferred with page
% numbering when used in |\gmd@evpaddonce| in \pk{gmdoc}.



\newcommand*\addtonummacro[2]{%
  \count0=#1\relax
  \advance\count0by#2\relax
  \xdef#1{\the\count\z@}}
% Need an explanation? The |\nummacro| declaration defines its
% argument (that should be a~CS) as |{0}| which is analogous to
% |\newcount| declaration but doesn't use up any count register.
%
% Then you may use this numeric macro as something between \TeX's
% count CS and \LaTeX's counter. The macros |\stepnummacro| and
% |\addtonummacro| are analogous to \LaTeX's |\stepcounter| and
% |\addtocounter| respectively: |\stepnummacro| advances the number
% stored in its argument by 1 and |\addtonummacro| advances it by the
% second argument. As the \LaTeX's analogoi, they have the global effect
% (the effect of global warming \gobble(;-)\,).
%
% So far I've used only |\nummacro| and |\stepnummacro|. Notify me if
% you use them and whether you need sth.\ more, |\multiplynummacro|
% e.g. 
%


% \division{Improvements to \pk{mwcls} Sectioning Commands}
%
% That is, `Expe-ri-mente'\footnote{A.\ Berg, \textit{Wozzeck}.} mit MW
% sectioning \& \cs{refstepcounter} to improve \pk{mwcls}'s cooperation
% with \pk{hyperref}. They shouldn't make any harm if another class
% (non-\pk{mwcls}) is loaded.
%
% We |\refstep| sectioning counters even if the sectionings are not
% numbered, because otherwise
% \begin{enumerate}
% \item \pdfTeX\ cried of multiply defined |\label|s,
% \item e.g.\ in a~table of contents the hyperlink
% |<rozdzia\l\ Kwiaty polskie>| linked not to the chapter's heading but
% to the last-before-it change of |\ref|.
% \end{enumerate}

\AtBeginDocument{% because we don't know when exactly \pk{hyperref} is
  % loaded and maybe after this package.
  \@ifpackageloaded{hyperref}{\newcounter{NoNumSecs}%
    \setcounter{NoNumSecs}{617}% to make |\ref|ing to an unnumbered section
    % visible (and funny?).
    \def\gm@hyperrefstepcounter{\refstepcounter{NoNumSecs}}%
    \DeclareRobustCommand*\gm@targetheading[1]{%
      \hypertarget{#1}{#1}}}% end of then
  {\def\gm@hyperrefstepcounter{}%
    \def\gm@targetheading#1{#1}}% end of else
}% of |\AtBeginDocument|

% Auxiliary macros for the kernel sectioning macro:
\def\gm@dontnumbersectionsoutofmainmatter{%
  \if@mainmatter\else \HeadingNumberedfalse \fi}
\def\gm@clearpagesduetoopenright{%
  \if@openright\cleardoublepage\else \clearpage\fi}

% To avoid |\def|ing of |\mw@sectionxx| if it's undefined, we redefine
% |\def| to gobble the definition and restore the original meaning of
% itself.
%
% Why shouldn't we change the ontological status of |\mw@sectionxx|
% (not define if undefined)? Because some macros (in \pk{gmdocc} e.g.)
% check it to learn whether they are in an \pk{mwcls} or not.
%
% But let's make a~shorthand for this test since we'll use it three
% times in this package and maybe also somewhere else.
% \Define\@ifnotmw
\long\def\@ifnotmw#1#2{\@ifundefined{mw@sectionxx}{#1}{#2}}

\let\gmu@def\def
\@ifnotmw{%
  \StoreMacro\gmu@def \def\gmu@def#14#2{\RestoreMacro\gmu@def}}{}
% I~know it may be of bad taste (to write such a~way \emph{here}) but
% I~feel so lonely and am in an alien state of mind after 3 hour sleep
% last night and, worst of all, listening to sir Edward Elgar's flamboyant
% Symphonies d'Art Nouveau. 
%
% A~\emph{decent} person would just wrap the following
% definition in |\@ifundefined|'s Else. But look, the definition is so
% long and I~feel so lonely etc. So,
% I~define |\def| (for some people there's nothing sacred) to be
% a~macro with two parameters, first of which is 
% delimited by digit 4 (the last token of |\mw@sectionxx|'s parameter
% string) and the latter is undelimited which means it'll be the body
% of the definition. Such defined |\def| does nothing else but
% restores its primitive meaning by the way sending its arguments to
% the Gobbled Tokens' Paradise. Luckily, |\RestoreMacro| contains
% |\let| not |\def|.

% The kernel of MW's sectioning commands:
\gmu@def\mw@sectionxx#1#2[#3]#4{%
  \edef\mw@HeadingLevel{\csname #1@level\endcsname
        \space}% space delimits level number!
  \ifHeadingNumbered
      \ifnum \mw@HeadingLevel>\c@secnumdepth \HeadingNumberedfalse \fi
      % line below is in \@ifundefined to make it work in classes
      % other than mwbk
      \@ifundefined{if@mainmatter}{}{\gm@dontnumbersectionsoutofmainmatter}
  \fi
%\begin{verbatim}
%%   \ifHeadingNumbered
%%     \refstepcounter{#1}%
%%     \protected@edef\HeadingNumber{\csname the#1\endcsname\relax}%
%%   \else
%%     \let\HeadingNumber\@empty
%%   \fi
%\end{verbatim}
  \def\HeadingRHeadText{#2}%
  \def\HeadingTOCText{#3}%
  \def\HeadingText{#4}%
  \def\mw@HeadingType{#1}%
  \if\mw@HeadingBreakBefore
    \if@specialpage\else\thispagestyle{closing}\fi
    \@ifundefined{if@openright}{}{\gm@clearpagesduetoopenright}%
    \if\mw@HeadingBreakAfter
      \thispagestyle{blank}\else
      \thispagestyle{opening}\fi
       \global\@topnum\z@
  \fi% of |\if\mw@HeadingBreakBefore|
%%
% placement of |\refstep| suggested by me (GM)
  \ifHeadingNumbered
    \refstepcounter{#1}%
    \protected@edef\HeadingNumber{\csname the#1\endcsname\relax}%
  \else
    \let\HeadingNumber\@empty
    \gm@hyperrefstepcounter
  \fi% of |\ifHeadingNumbered|
%%
  \if\mw@HeadingRunIn
    \mw@runinheading
  \else
    \if\mw@HeadingWholeWidth
      \if@twocolumn
        \if\mw@HeadingBreakAfter
        \onecolumn
        \mw@normalheading
        \pagebreak\relax
              \if@twoside
                \null
                \thispagestyle{blank}%
                \newpage
              \fi% of |\if@twoside|
        \twocolumn
        \else
          \@topnewpage[\mw@normalheading]%
        \fi% of |\if\mw@HeadingBreakAfter|
      \else
        \mw@normalheading
        \if\mw@HeadingBreakAfter\pagebreak\relax\fi
      \fi% of |\if@twocolumn|
    \else
      \mw@normalheading
      \if\mw@HeadingBreakAfter\pagebreak\relax\fi
    \fi% of |\if\mw@HeadingWholeWidth|
  \fi% of |\if\mw@HeadingRunIn|
  }
%^^A%%% (End of Experimente with MW sectioning.)

%
% \subdivision{An improvement of MW's \cs{SetSectionFormatting}}
%
% A~version of MW's |\SetSectionFormatting| that lets to leave some
% settings unchanged by leaving the respective argument empty (|{}| or
% |[]|).
%
% Notice: If we adjust this command for new version of \acro{MWCLS},
% we should name it |\SetSectionFormatting| and add issuing errors if
% the inner macros are undefined.
\relaxen\SetSectionFormatting
\newcommand*\SetSectionFormatting[5][\empty]{%
  \ifx\empty#1\relax\else% empty (not |\empty|!) |#1| also launches |\else|.
    \def\mw@HeadingRunIn{10}\def\mw@HeadingBreakBefore{10}%
    \def\mw@HeadingBreakAfter{10}\def\mw@HeadingWholeWidth{10}%
    \@ifempty{#1}{}{\mw@processflags#1,\relax}% If |#1| is omitted,
    % the flags are left unchanged. If |#1| is given, even as [], the
    % flags are first cleared and then processed again.
  \fi
  \@ifundefined{#2}{\@namedef{#2}{\mw@section{#2}}}{}%
  \mw@secdef{#2}{@preskip} {#3}{2 oblig.}%
  \mw@secdef{#2}{@head}    {#4}{3 oblig.}%
  \mw@secdef{#2}{@postskip}{#5}{4 oblig.}%
  \ifx\empty#1\relax
    \mw@secundef{#2@flags}{1 (optional)}%
  \else\mw@setflags{#2}%
  \fi}

\def\mw@secdef#1#2#3#4{% |#1| the heading name,\\
% |%| |#2| the command distinctor, \\
% |%| |#3| the meaning, \\
% |%| |#4| the number of argument to error message.
  \@ifempty{#3}
    {\mw@secundef{#1#2}{#4}}
    {\@namedef{#1#2}{#3}}}

\def\mw@secundef#1#2{%
  \@ifundefined{#1}{%
    \ClassError{mwcls/gm}{%
      command \bslash#1  undefined \MessageBreak
      after \bslash SetSectionFormatting!!!\MessageBreak}{%
      Provide the #2 argument of \bslash SetSectionFormatting.}}{}}


% First argument is a~sectioning command (wo. |\|) and second the
% stuff to be added at the beginning of the heading declarations.
\def\addtoheading#1#2{%
    \n@melet{gmu@reserveda}{#1@head}%
    \toks\z@=\@xa{\gmu@reserveda}%
    \toks\tw@={#2}%
    \edef\gmu@reserveda{\the\toks\tw@\the\toks\z@}%
    \n@melet{#1@head}{gmu@reserveda}%
%^^A    \@xa\show\csname#1@head\endcsname
}

% \subdivision{Negative \cs{addvspace}} When two sectioning commands
% appear one after another (we may assume that this occurs only when
% a~lower section appears immediately after higher), we prefer to put
% the \emph{smaller} vertical space not the larger, that is, the
% preskip of the lower sectioning not the postskip of the higher.
%
% For that purpose we modify the very inner macros of \acro{MWCLS}
% to introduce a~check whether the previous vertical space equals the
% postskip of the section one level higher.

\@ifnotmw{}{% We proceed only in \acro{MWCLS}
  
% The information that we are just after a~heading will be stored in
% the |\gmu@prevsec| macro: any heading will define it as the section
% name and |\everypar| (any normal text) will clear it.
  \def\@afterheading{%
    \@nobreaktrue
    \xdef\gmu@prevsec{\mw@HeadingType}% added now
    \everypar{%
      \grelaxen\gmu@prevsec% added now. All the rest is original \LaTeX.
      \if@nobreak
        \@nobreakfalse
        \clubpenalty \@M
        \if@afterindent \else
          {\setbox\z@\lastbox}%
        \fi
      \else
        \clubpenalty \@clubpenalty
        \everypar{}%
      \fi}}
  
% If we are (with the current heading) just after another heading (one
% level lower I~suppose), then we add the less of the higher header's
% post-skip and the lower header pre-skip or, if defined, the
% two-header-skip. (We put the macro defined below just before
% |\addvspace| in MWCLS inner macros.
  \def\gmu@checkaftersec{%
    \@ifundefined{gmu@prevsec}{}{%
      \ifgmu@postsec% an additional switch that is true by default but
                    % may be turned into an \cs{ifdim} in special
                    % cases, see line \ref{gmu@postsec}.
        {\@xa\mw@getflags\@xa{\gmu@prevsec}%
          \glet\gmu@reserveda\mw@HeadingBreakAfter}%
        \if\mw@HeadingBreakBefore\def\gmu@reserveda{11}\fi% if the 
        % current heading inserts page break before itself, all the play
        % with vskips is irrelevant.
        \if\gmu@reserveda\else
          \penalty10000\relax
          \skip\z@=\csname\gmu@prevsec @postskip\endcsname\relax
          \skip\tw@=\csname\mw@HeadingType @preskip\endcsname\relax
          \@ifundefined{\mw@HeadingType @twoheadskip}{
            \ifdim\skip\z@>\skip\tw@
              \vskip-\skip\z@% we strip off the post-skip of previous
              % header if it's bigger than current pre-skip
            \else
              \vskip-\skip\tw@% we strip off the current pre-skip otherwise
            \fi}{% But if the two-header-skip is defined, we put
            % \emph{it}
            \penalty10000
            \vskip-\skip\z@
            \penalty10000
            \vskip-\skip\tw@
            \penalty10000
            \vskip\csname\mw@HeadingType @twoheadskip\endcsname
            \relax}%
          \penalty10000
          \hrule height\z@\relax% to hide the last (un)skip before subsequent
          % |\addvspace|s. 
          \penalty10000
        \fi
      \fi
    }% of |\@ifundefined{gmu@prevsec}| `else'
  }% of |\def\gmu@checkaftersec|

  \def\ParanoidPostsec{% \label{gmu@postsec} this version of
    % \inverb|\ifgmu@postsec| is intended for the special case of
    % sections may contain no normal text, as while \pk{gmdoc}ing.
    \def\ifgmu@postsec{% note this macro expands to an open \cs{if}.
      \skip\z@=\csname\gmu@prevsec @postskip\endcsname\relax
      \ifdim\lastskip=\skip\z@\relax% we play
      % with the vskips only if the last skip is the previous
      % heading's postskip (a~counter-example I~met while
      % \pk{gmdoc}ing).
    }}
  
  \let\ifgmu@postsec\iftrue
  
  \def\gmu@getaddvs#1\addvspace#2\gmu@getaddvs{%
    \toks\z@={#1}
    \toks\tw@={#2}}

  % And the modification of the inner macros at last:
  \def\gmu@setheading#1{%
    \@xa\gmu@getaddvs#1\gmu@getaddvs
    \edef#1{%
      \the\toks\z@\@nx\gmu@checkaftersec
      \@nx\addvspace\the\toks\tw@}}
  
  \gmu@setheading\mw@normalheading
  \gmu@setheading\mw@runinheading

  \def\SetTwoheadSkip#1#2{\@namedef{#1@twoheadskip}{#2}}

}% of |\@ifnotmw|

%^^A% % \subdivision{Feature fix for \pk{gmdoc}}
%^^A% %
%^^A% % I'm not sure whether call it `bug' but it happens while
%^^A% % \pk{gmodc}ing that between two headers only code appears no `normal'
%^^A% % text, the commentary that is. And the code layer redefines
%^^A% % |\everypar| so the next heading `thinks' it is next to the previous
%^^A% % heading and does those special things with the skips when in
%^^A% % \pk{mwcls}. Therefore we provide two-heading skips for all the
%^^A% % headings in \pk{gmdoc} equal to the respective preskips whatever
%^^A% % those preskips may be.
%^^A% 
%^^A% \@ifnotmw{}{%
%^^A%   \AtBeginDocument{%
%^^A%     \@ifpackageloaded{gmdoc}{%
%^^A%       \def\do#1{%
%^^A%         \@namedef{#1@twoheadskip}{\csname#1@preskip\endcsname}}%
%^^A%       \do{part}%
%^^A%       \do{section}\do{subsection}\do{subsubsection}%
%^^A%       \do{paragraph}\do{subparagraph}%
%^^A%       \@ifundefined{chapter}{}{\do{chapter}}%
%^^A%     }{}}}
%^^A% \fi
%^^A% commented out since the additional \ifdim in line 1358 does.

% \subdivision{My heading setup for \pk{mwcls}}
%
% The setup of heading skips was tested in `real' typesetting, for
% money that is. The skips are designed for 11/13\,pt leading and
% together with my version of \pk{mw11.clo} option file for \pk{mwcls}
% make the headings (except paragraph and subparagraph) consist of
% an integer number of lines. The name of the declaration comes from
% my employer, ``Wiedza Powszechna'' Editions.

\@ifnotmw{}{% We define this declaration only when in \pk{mwcls}.
\def\WPheadings{%
  \SetSectionFormatting[breakbefore,wholewidth]
      {part}{\z@\@plus1fill}{}{\z@\@plus3fill}%
  % 
  \@ifundefined{chapter}{}{%
    \SetSectionFormatting[breakbefore,wholewidth]
      {chapter}
      {66\p@}% |{67\p@}|% for Adventor/Schola 0,95.
      {\FormatHangHeading{\LARGE}}
      {27\p@\@plus0,2\p@\@minus1\p@}%
  }%
      %
  \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
      % we understand her, wants the skip between a~heading and text
      % to be rigid.
  %
  \SetTwoheadSkip{subsection}{11\p@\@plus0,5\p@\@minus1\p@}%
  \SetSectionFormatting{subsection}
      {19\p@\@plus0,4\p@\@minus6\p@}
      {\FormatHangHeading {\large}}% 12/14 pt
      {6\p@\@plus0,3\p@}% after-skip 6\,pt due to p.12, not to squeeze
      % the before-skip too much.
  %
  \SetTwoheadSkip{subsubsection}{10\p@\@plus1,75\p@\@minus1\p@}%
  \SetSectionFormatting{subsubsection}
      {10\p@\@plus0,2\p@\@minus1\p@}
      {\FormatHangHeading {\normalsize}}
      {3\p@\@plus0,1\p@}% those little skips should be smaller than
      % you calculate out of a~geometric progression, because the
      % interline skip enlarges them.
  %
  \SetSectionFormatting[runin]{paragraph}
      {7\p@\@plus0,15\p@\@minus1\p@}
      {\FormatRunInHeading{\normalsize}}
      {2\p@}%
  %
  \SetSectionFormatting[runin]{subparagraph}
      {4\p@\@plus1\p@\@minus0,5\p@}
      {\FormatRunInHeading{\normalsize}}
      {\z@}%
}% of |\WPheadings|
}% of |\@ifnotmw|


% \division{Compatibilising Standard and \pk{mwcls} Sectionings}
%
% If you use Marcin Woli\nacute ski's document classes (\pk{mwcls}), you
% might have met their little queerness: the sectioning commands take
% two optional arguments instead of standard one. It's reasonable
% since one may wish one text to be put into the running head,
% another to the toc and yet else to the page. But the order of
% optionalities causes an incompatibility with the standard classes:
% MW section's first optional argument goes to the running head not to
% toc and if you've got a~source file written with the standard
% classes in mind and use the first (and only) optional argument, the
% effect with \pk{mwcls} would be different if not error.
%
% Therefore I~counter-assign the commands and arguments to reverse the
% order of optional arguments for sectioning commands when \pk{mwcls}
% are in use and reverse, to make \pk{mwcls}-like sectioning optionals usable
% in the standard classes.
%
% \stanza
% With the following in force, you may both in the standard classes
% and in \pk{mwcls} give a~sectioning command one or two optional
% arguments (and mandatory the last, of course). If you give just one
% optional, it goes to the running head and to toc as in scls (which
% is unlike in \pk{mwcls}). 
% If you give two optionals, the first goes to the running head and
% the other to toc (like in \pk{mwcls} and unlike in scls). 
%
% (In both cases the mandatory last argument goes only to the page.)
%
% What more is unlike in scls, it's that even with them the starred
% versions of sectioning commands allow optionals (but they still send
% them to the Gobbled Tokens' Paradise).
%
% (In \pk{mwcls}, the only difference between starred and non-starred
% sec commands is (not) numbering the titles, both versions make a~contents
% line and a~mark and that's not changed with my redefinitions.)
%
%
\@ifnotmw{% we are not in \pk{mwcls} and want to
  % handle \pk{mwcls}-like sectionings i.e., those written with two
  % optionals.
  \def\gm@secini{gm@la}%
  % \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
      % a~special version of the heading just to the running head.
      \@namedef{#1mark}##1{% we redefine \cs{\<sec>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
        % wanted we restore original |\#1mark|.
      }%
      \def\gm@secstar{[#3]}% if |\gm@secstar|
    % is empty, which means the sectioning command was written
    % starless, we pass the `true' sectioning command |#3| as the
    % optional argument. Otherwise the sectioning command was written
    % with star so the `true' s.c.\ takes no optional.
    \fi
    \@xa\@xa\csname\gm@secini#1\endcsname
    \gm@secstar{#4}}%
% \stanza
}{% we are in \pk{mwcls} and want to reverse MW's optionals order
  % i.e., if there's just one optional, it should go both to toc and to
  % running head.
  \def\gm@secini{gm@mw}%
  % 
  \let\gm@secmarkh\@gobble% in \pk{mwcls} there's no need to make
  % tricks for special version to running headings.
  % \Define\gm@secxx
  \def\gm@secxx#1#2[#3]#4{%
    \@xa\@xa\csname\gm@secini#1\endcsname
    \gm@secstar[#2][#3]{#4}}%
}

\def\gm@sec#1{\@dblarg{\gm@secx{#1}}}
\def\gm@secx#1[#2]{%
  \@ifnextchar[{\gm@secxx{#1}{#2}}{\gm@secxx{#1}{#2}[#2]}}% if
% there's only one optional, we double \emph{it} not the mandatory
% argument.  ^^A}

\def\gm@straightensec#1{% the parameter is for the command's name.
  \@ifundefined{#1}{}{% we don't change the ontological status of the
    % command because someone may test it.
    \n@melet{\gm@secini#1}{#1}%
    \@namedef{#1}{%
      \@ifstar{\def\gm@secstar{*}\gm@sec{#1}}{%
        \def\gm@secstar{}\gm@sec{#1}}}}%
}%

\let\do\gm@straightensec
\do{part}\do{chapter}\do{section}\do{subsection}\do{subsubsection}
\@ifnotmw{}{\do{paragraph}}% this `straightening' of
% |\paragraph| with the standard \pk{article} caused the `\TeX\
% capacity exceeded' error. Anyway, who on Earth wants paragraph
% titles in toc or running head?
%
%
% \division{\env{enumerate*} and \env{itemize*}}
% We wish the starred version of \env{enumerate} to be just numbered
% paragraphs. But \pk{hyperref} redefines |\item| so we should do it
% a~smart way, to set the \LaTeX's \env{list} parameters that is.
%
% (Marcin Woli\nacute ski in \pk{mwcls} defines those environments slightly
% different: his item labels are indented, mine are not; his
% subsequent paragraphs of an item are not indented, mine are.)
%
% \Define*{enumerate*}
\@namedef{enumerate*}{%
  \ifnum\@enumdepth>\thr@@
    \@toodeep
  \else
    \advance\@enumdepth\@ne
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
    \@xa\list\csname label\@enumctr\endcsname{%
      \partopsep\topsep \topsep\z@ \leftmargin\z@ 
      \itemindent\@parindent %|%\advance\itemindent\labelsep|
      \labelwidth\@parindent
      \advance\labelwidth-\labelsep
      \listparindent\@parindent
      \usecounter \@enumctr 
      \def\makelabel##1{##1\hfil}}%
  \fi}
\@namedef{endenumerate*}{\endlist}

% \Define*{itemize*}
\@namedef{itemize*}{%
  \ifnum\@itemdepth>\thr@@
    \@toodeep
  \else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \@xa\list\csname\@itemitem\endcsname{%
      \partopsep\topsep \topsep\z@ \leftmargin\z@ 
      \itemindent\@parindent 
      \labelwidth\@parindent 
      \advance\labelwidth-\labelsep
      \listparindent\@parindent
      \def\makelabel##1{##1\hfil }}%
  \fi}
\@namedef{enditemize*}{\endlist}



% \division{The Logos}
%
% We'll modify The \LaTeX\ logo now to make it fit better to various
% fonts. 

\let\oldLaTeX\LaTeX
\let\oldLaTeXe\LaTeXe

\def\TeX{T\kern-.1667em\lower.5ex\hbox{E}\kern-.125emX\@}

\newcommand*\DeclareLogo[3][\relax]{%
  % |#1| is for non-\LaTeX\ spelling and will be used in the PD1
  % encoding (to make pdf bookmarks);\\
  % |#2| is the command, its name will be the PD1 spelling by
  % default,\\ 
  % |#3| is the definition for all the font encodings except PD1.
  \ifx\relax#1\def\gmu@reserveda{\@xa\@gobble\string#2}%
  \else
    \def\gmu@reserveda{#1}%
  \fi
  \edef\gmu@reserveda{%
    \@nx\DeclareTextCommand\@nx#2{PD1}{\gmu@reserveda}}
  \gmu@reserveda
  \DeclareTextCommandDefault#2{#3}%
  \DeclareRobustCommand*#2{#3}}% added for \XeTeX

% \DeclareDefining\DeclareLogo
\DeclareLogo\LaTeX{%
  {%
%^^A\typeout{***** LaTeX logo of GM ^^J}\show\relax
    L%
    \setbox\z@\hbox{\check@mathfonts
      \fontsize\sf@size\z@
      \math@fontsfalse\selectfont
      A}%
    \kern-.57\wd\z@
    \sbox\tw@ T%
    \vbox to\ht\tw@{\copy\z@ \vss}%
    \kern-.2\wd\z@}% originally $-,15$\,em for T.
  {% 
    \ifdim\fontdimen1\font=\z@
    \else
      \count\z@=\fontdimen5\font
      \multiply\count\z@ by 64\relax
      \divide\count\z@ by\p@
      \count\tw@=\fontdimen1\font
      \multiply\count\tw@ by\count\z@
      \divide\count\tw@ by 64\relax
      \divide\count\tw@ by\tw@
      \kern-\the\count\tw@ sp\relax
    \fi}%
  \TeX}

\DeclareLogo\LaTeXe{\mbox{\m@th \if
    b\expandafter\@car\f@series\@nil\boldmath\fi
    \LaTeX\kern.15em2$_{\textstyle\varepsilon}$}}

\StoreMacro\LaTeX
\StoreMacro*{LaTeX }
% \label{SMLaTeX}

% `\LaTeXpar' in my opinion better describes what I~work with/in than
% just `\LaTeX'.
% \Define\LaTeXpar
\DeclareLogo[(La)TeX]{\LaTeXpar}{%
  {%
    \setbox\z@\hbox{(}%)
    \copy\z@
    \kern-.2\wd\z@ L%
    \setbox\z@\hbox{\check@mathfonts
      \fontsize\sf@size\z@
      \math@fontsfalse\selectfont
      A}%
    \kern-.57\wd\z@
    \sbox\tw@ T%
    \vbox to\ht\tw@{\box\z@%
      \vss}%
  }%
  \kern-.07em% originally $-,15$\,em for T.
  {%(
    \sbox\z@)%
    \kern-.2\wd\z@\copy\z@  
    \kern-.2\wd\z@}\TeX
}

% \begin{quotation} Here are a few definitions which can usefully be
% employed when documenting 
% package files: now we can readily refer to \AmSTeX, \BibTeX\ and \SliTeX, as well
% as the usual \TeX\ and \LaTeX. There's even a \PlainTeX\ and
% a~\Web.\end{quotation}
\@ifundefined{AmSTeX}
  {\def\AmSTeX{\leavevmode\hbox{$\mathcal A\kern-.2em\lower.376ex%
        \hbox{$\mathcal M$}\kern-.2em\mathcal S$-\TeX}}}{}

\DeclareLogo\BibTeX{{\rmfamily B\kern-.05em%
    \textsc{i{\kern-.025em}b}\kern-.08em% the kern is wrapped in
                                % braces for my |\fakescaps|' sake.
    \TeX}}


\DeclareLogo\SliTeX{{\rmfamily S\kern-.06emL\kern-.18em\raise.32ex\hbox
        {\scshape i}\kern -.03em\TeX}}

\DeclareLogo\PlainTeX{\textsc{Plain}\kern2pt\TeX}

\DeclareLogo\Web{\textsc{Web}}
% There's also the \LaTeXpar\ logo got with the |\LaTeXpar| macro
% provided by \pk{gmutils}. And here \TeXbook's logo:
\DeclareLogo[The TeX book]\TeXbook{\textsl{The \TeX book}}
\let\TB\TeXbook% \textit{TUG Boat} uses this.

\DeclareLogo[e-TeX]\eTeX{%
  \ensuremath{\varepsilon}-\kern-.125em\TeX}% definition sent by Karl
% Berry from \textit{TUG Boat} itself.

\DeclareLogo[pdfe-TeX]\pdfeTeX{pdf\eTeX}

\DeclareLogo\pdfTeX{pdf\TeX}

%^^A\@ifXeTeX{}{}
\@ifundefined{XeTeX}{%
  \DeclareLogo\XeTeX{X\kern-.125em\relax
    \@ifundefined{reflectbox}{%
      \lower.5ex\hbox{E}\kern-.1667em\relax}{%
      \lower.5ex\hbox{\reflectbox{E}}\kern-.1667em\relax}%
    \TeX}}{}

\@ifundefined{XeLaTeX}{%
  \DeclareLogo\XeLaTeX{X\kern-.125em\relax
    \@ifundefined{reflectbox}{%
      \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}
% (\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
% \pk{gmutils} |\XeTeXthree| declaration) and then the reversed |E|
% you get as the Unicode Latin Letter Reversed E.


% \division{Expanding turning stuff all into `other'}

% 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 turns its |#2| all into `other' chars and assigns
% them to |#1| which has to be a~CS or an active char.
% 

% \Define\def@other

\long\def\def@other#1#2{%
  \long\def\gm@def@other@tempa{#2}%
  \all@other#1{#2}}

% 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
\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.
%
% \Define\gm@gobmacro
\edef\gmu@reserveda{%
  \def\@nx\gm@gobmacro##1\@xa\@gobble\string\macro:->{}}
\gmu@reserveda

% In the next two macros' names, `unex' stands both for not expanding
% the argument(s) and for disastrously partial unexpandability of the
% macros themselves.

\long\def\unex@namedef#1#2{%
  \edef@other\gmu@reserveda{#1}%
  \@xa\long\@xa\def\csname\gmu@reserveda\endcsname{#2}}


\long\def\unex@nameuse#1{%
  \edef@other\gmu@reserveda{#1}%
  \csname\gmu@reserveda\endcsname}


% \division{Brave New World of  \XeTeX}

\newcommand\@ifXeTeX[2]{%
  \@xa\ifx\csname XeTeXversion\endcsname\relax
  \afterfi{#2}\else\afterfi{#1}\fi}

%^^A \Define\withXeTeX
%^^A~\let\withXeTeX\@ifXeTeX

\def\XeTeXthree{%
  \@ifXeTeX{%
%^^A    \SMglobal\StoreMacro\LaTeX
%^^A    \SMglobal\StoreMacro*{LaTeX }% we want \emph{our} version
%^^A of |\LaTeX|.
    \RequirePackage{fontspec}%
    \RequirePackage{xunicode}%
    \RequirePackage{xltxtra}%
    \AtBeginDocument{%
      \RestoreMacro\LaTeX\RestoreMacro*{LaTeX }}% my version of the
                                % \LaTeX\ logo has been stored just
                                % after defining, in line \ref{SMLaTeX}.
    % ^^A \def\dekfracc##1/##2{\vfrac{##1}{##2}}
}{}}


% The |\udigits| declaration causes the digits to be typeset
% uppercase. I~provide it since by default I~prefer the lowercase
% (nautical) digits.
\AtBeginDocument{%
  \@ifpackageloaded{fontspec}{%
    \DeclareRobustCommand*\udigits{%
      \addfontfeature{Numbers=Uppercase}}%
  }{%
    \emptify\udigits}}


% \subdivision{Fractions}

\def\Xedekfracc{\@ifstar{%
% Minion GM 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|).
    \def\gmu@dekfracc########1/########2{%
      {\addfontfeature{VerticalPosition=Numerator}########1}\kern-0.05em
      \char"2044\kern-.05em
      {\addfontfeature{VerticalPosition=Denominator}########2}}%
%
% We define the fractional macros. Since Adobe Minion Pro doesn't
% contain $\frac n5$ nor $\frac n6$, we don't provide them here.
    \@namedef{gmu@xefracc1/4}{\char"BC\relax}%
    \@namedef{gmu@xefracc1/2}{\char"BD\relax}%
    \@namedef{gmu@xefracc3/4}{\char"BE\relax}%
    \@namedef{gmu@xefracc1/3}{\char"2153\relax}%
    \@namedef{gmu@xefracc2/3}{\char"2154\relax}%
    \@namedef{gmu@xefracc1/8}{\char"215B\relax}%
    \@namedef{gmu@xefracc3/8}{\char"215C\relax}%
    \@namedef{gmu@xefracc5/8}{\char"215D\relax}%
    \@namedef{gmu@xefracc7/8}{\char"215E\relax}%
    \def\dekfracc########1/########2{%
      \@ifundefined{gmu@xefracc########1/########2}{%
        \gmu@dekfracc{########1}/{########2}}{%
        \csname gmu@xefracc########1/########2\endcsname}}%
  }{%
    \def\dekfracc####1/####2{{%
        \addfontfeature{Fractions=On}%
        ####1/####2}}%
    \let\fnfracc\dekfracc
    }}
% What have we just done? We defined two versions of the
% |\Xefractions| declaration. The starred version is intended to make
% use only of the built-in fractions such as \dekfracc1/2 or
% \dekfracc7/8. To achieve that, a~handful of macros is defined that
% expand to the Unicodes of built-in fractions and |\dekfracc| command
% is defined to use them.
%
% 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)
% |#|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.)


% \subdivision{\cs{resizegraphics}}
%

\@ifXeTeX{%
  \def\resizegraphics#1#2#3{{%
      \setbox0=\hbox{\XeTeXpicfile #3 }%
      \ifx!#1\else
        \dimen0=#1\relax
        \count2=\wd0
        \divide\count2 by1000\relax
        \count0=\dimen0\relax
        \divide\count0\count2 
      \fi
      \ifx!#2\else
        \dimen0=#1\relax
        \count6=\ht0
        \divide\count6 by1000\relax
        \count4=\dimen0\relax
        \divide\count4\count6
      \fi
      \ifx!#1\count0=\count4\fi
      \ifx!#2\count4=\count0\fi
      \XeTeXpicfile #3 xscaled \count0 yscaled \count4
    }}}{%
    \def\resizegraphics#1#2#3{%
      \resizebox{#1}{#2}{%
        \includegraphics{#3}}}}%

% The [options] in the |\XeTeXpicfile| command use the following keywords:\\
% |width| \<dimen>\\
% |height| \<dimen>\\
% |scaled| \<scalefactor>\\
% |xscaled| \<scalefactor>\\
% |yscaled| \<scalefactor>\\
% |rotated| \<degrees>
%

\def\GMtextsuperscript{%
  \@ifXeTeX{%
    \def\textsuperscript##1{{%
        \addfontfeature{VerticalPosition=Numerator}##1}}%
  }{\truetextsuperscript}}

\def\truetextsuperscript{%
  \DeclareRobustCommand*\textsuperscript[1]{%
    \@textsuperscript{\selectfont##1}}
  \def\@textsuperscript##1{%
    {\m@th\ensuremath{^{\mbox{\fontsize\sf@size\z@##1}}}}}}

%\division{Varia}
%

% A~very neat macro provided by \pk{doc}. I~copy it
% \*|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\*
\DeclareRobustCommand*\*{\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 /}

\AtBeginDocument{% to bypass redefinition of |\~| as a~text command
  % with various encodings
  \DeclareRobustCommand*\~{%
    \@ifnextchar/{\gmu@tilde\kern-0,1667em\relax}\gmu@tilde}}
% We prepare the proper kerning for ``\~/''.

% The standard |\obeyspaces| declaration just changes the space's
% |\catcode| to \catactive\ (`active'). Usually it is fairly enough
% because no one `normal' redefines the active space. But we are
% \emph{not} normal and we do \emph{not} do usual things and therefore
% we want a~declaration that not only will |\active|ate the space but
% also will (re)define it as the |\ | primitive. So define
% |\gmobeyspaces| that obeys this requirement.
% 
% (This definition is repeated in \pk{gmverb}.)
\foone{\catcode`\ \active}%
{\def\gmobeyspaces{\catcode`\ \active\let \ }}

% While typesetting poetry, I~was surprised that sth.\ didn't work. The
% reason was that original |\obeylines| does |\let| not |\def|, so I~give
% the latter possibility.
% \Define\defobeylines
% \changes{v0.62}{06/09/07}{moved from \pk{pmlectionis.cls}}
\foone{\catcode`\^^M\active}% the comment signs here are crucial.
{\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
% restore Knuthian meanings:
% \changes{v0.63}{06/9/8}{Plain-like skip macros
% defined: \cs{deksmall/med/bigskip} i.e., moved here from
% another file}

\def\deksmallskip{\vskip\smallskipamount}
\def\undeksmallskip{\vskip-\smallskipamount}
\def\dekmedskip{\vskip\medskipamount}
\def\dekbigskip{\vskip\bigskipamount}


\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}

% A~mark for the \TODO{}s:
\newcommand*{\TODO}[1][]{{%
    \sffamily\bfseries\huge TODO!\if\relax#1\relax\else\space\fi#1}}
% \changes{v0.64}{06/9/17}{moved here from \pk{pmlectionis}}

% \iffalse 
% The code contained in this iffalse I~wrote to make the table of
% contents twocolumn. 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
% brutally redefine the internal \LaTeX\ macro.
%
% % A~trick for making |\protected@write| immediate. What's a~use of it?
% % See the next macro.
% % CodeDefine\MakeWriteImmediate
% % CodeDefIndex\@@write
% % changes{v0.65}{06/9/26}{added}
% \newcommand*\MakeWriteImmediate{%
%   \let\@@write\write
%   \def\write{\immediate\@@write}}
%
% % First I~used it for closing of \env{multicols} in the \file{.toc}
% % file. Second time to make \emph{two} tables of contents containing
% % two different parts of the document
% % CodeDefine\ImmediateAddtoConts
% % changes{v0.65}{06/9/26}{added}
% \newcommand\ImmediateAddtoConts[2]{{%
%     \MakeWriteImmediate
%     \addtocontents{#1}{#2}%
% }}
% \fi

% I~like twocolumn tables of contents. First I~tried to provide them by
% writing |\begin{multicols}{2}| and |\end{multicols}| outto the
% \file{.toc} file but it worked wrong in some cases. So I~redefine the
% internal \LaTeX\ macro instead.
\newcommand*\twocoltoc{%
  \RequirePackage{multicol}%
  \def\@starttoc##1{%
    \begin{multicols}{2}\makeatletter\@input {\jobname .##1}%
      \if@filesw \@xa \newwrite \csname tf@##1\endcsname 
        \immediate \openout \csname tf@##1\endcsname \jobname .##1\relax
      \fi 
      \@nobreakfalse\end{multicols}}}

\@onlypreamble\twocoltoc

% 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.
%\Define\enoughpage
\newcommand\enoughpage[1]{%
  \par
  \dimen0=\pagegoal
  \advance\dimen0 by-\pagetotal
  \ifdim\dimen0<#1\relax\newpage\fi}

% Two shorthands for debugging:
%\Define\tOnLine\Define\OnAtLine
\newcommand*\tOnLine{\typeout{\on@line}}

\let\OnAtLine\on@line

% An equality sign properly spaced:
% \Define\equals\Define\eequals
\newcommand*\equals{${}={}$}
% And for the \LaTeX's pseudo-code statements:
\newcommand*\eequals{${}=={}$}

% The job name without extension.
% \Define\jobnamewoe
\def\gm@jobn#1.#2\@@nil{#1}

\def\jobnamewoe{\@xa\gm@jobn\jobname.\@@nil}% We add the dot
% to be sure there is one although I'm not sure whether you can \TeX\
% a~file that has no extrension.



% While typesetting a~UTF-8 ls-R result I~found a~difficulty that
% follows: UTF-8 encoding is handled by the \pk{inputenc}
% package. It's O.K. so far. The UTF-8 sequences are managed using
% active chars. That's O.K. so far. While writing such sequences to
% a~file, the active chars expand. You feel the blues? When the result of
% expansion is read again, it sometimes is again an active char, but
% now it doesn't star a~correct UTF-8 sequence. 
%
% Because of that I~wanted to `freeze' the active chars so that they
% would be |\write|n to a~file unexpanded. A~very brutal operation is
% done: we look at all 256 chars' catcodes and if we find an active
% one, we |\let| it |\relax|.  As the macro does lots and lots of
% assignments, it shouldn't be used in |\edef|s.
%
% \Define\freeze@actives
% \changes{v0.76}{2007/02/07}{added}

\def\freeze@actives{%
  \count\z@\z@
  % 
  \@whilenum\count\z@<\@cclvi\do{%
    \ifnum\catcode\count\z@=\active
      \uccode`\~=\count\z@
      \uppercase{\let~\relax}%
    \fi
    \advance\count\z@\@ne}}


% A~macro that typesets all 256 chars of given font. It makes use of
% |\@whilenum|. \Define\ShowFont

\newcommand*\ShowFont[1][6]{%
  \begin{multicols}{#1}[The current font (the \f@encoding\ encoding):]
    \parindent\z@
    \count\z@\m@ne
    \@whilenum\count\z@<\@cclv\do{
      \advance\count\z@\@ne
      \ \the\count\z@:~\char\count\z@\par}
  \end{multicols}}


% A~couple of macros for typesetting liturgic texts such as psalmody
% of Liturgia Horarum. I~wrap them into a~declaration since they'll be
% needed not every time.
% \Define\liturgiques
% \changes{v0.76}{07/3/30}{added, or rather moved from \file{Akatyst.tex}}
\newcommand*\liturgiques[1][red]{% Requires the \pk{color} package.
  \gmu@RPif{color}{color}%
  \newcommand*\czerwo{\small\color{#1}}% environment
  \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}}}

% After the next definition you can write
% \cs{gmu@RP}\arg[options]\arg{package}\arg{csname} to get the package |#2|
% loaded with options |#1| if the csname |#3| is undefined.
\newcommand*\gmu@RPif[3][]{%
  \ifx\relax#1\relax
  \else \def\gmu@resa{[#1]}%
  \fi
  \@xa\RequirePackage\gmu@resa{#2}}

% Since inside \env{document} we cannot load a~package, we'll redefine
% |\gmu@RPif| to issue a~request before the error issued by undefined
% CS. 
% \Define\gmu@RPif
\AtBeginDocument{%
  \renewcommand*\gmu@RPif[3][]{%
    \@ifundefined{#3}{%
      \@ifpackageloaded{#2}{}{%
        \typeout{^^J! Package `#2' not loaded!!! (\on@line)^^J}}}{}}}


% It's very strange to me but it seems that $\continuum$ is not
% defined in the basic math packages. It is missing at least in the
% \textit{Symbols} book.\Define\continuum
\providecommand*\continuum{\gmu@RPif{eufrak}{mathfrak}\mathfrak{c}}

% And this macro I~saw in the \pk{ltugproc} document class nad I~liked
% it.
\def\acro#1{\gmu@acroinner#1\gmu@acroinner}

\def\gmu@acroinner#1{%
  \ifx\gmu@acroinner#1\else
    \ifcat a\@nx#1%
      \ifnum`#1=\uccode`#1%
        {\scshape\lowercase{#1}}%
      \else{\smallerr#1}%
      \fi
    \else#1%
    \fi
    \afterfi\gmu@acroinner
  \fi}

% Since the fonts I~am currently using do not support required font
% feature, I~skip the following definition. 
\iffalse
\newcommand*\acroff{%
  \def\acro##1{{\addfontfeature{Letters=UppercaseSmallCaps}##1}}}
\fi

\newcommand*\IMO{\acro{IMO}}
\newcommand*\AKA{\acro{AKA}}

\newcommand*\qxenc{\fontencoding{QX}\selectfont}
% The |\copyright| command is unavailable in T1 and U~(unknown)
% encodings so provide
\newcommand*\qxcopyright{{\qxenc\copyright}}
\newcommand*\qxcopyrights{%
  \let\gmu@copyright\copyright
  \def\copyright{{\qxenc\gmu@copyright}}}

\newcommand*\fixcopyright{%
  \@ifXeTeX{\def\copyright{\char"00A9 }}{\qxcopyrights}}


% Probably the only use of it is loading \pk{gmdocc.cls} `as second
% class'. This command takes first argument optional, options of the
% class, and second mandatory, the class name. I~use it in an article
% about \pk{gmdoc}.
\def\secondclass{%
  \newif\ifSecondClass
  \SecondClasstrue
  \@fileswithoptions\@clsextension}%|[outeroff,gmeometric]{gmdocc}|%
% it's loading \pk{gmdocc.cls} with all the bells and whistles except
% the error message.


% Cf.\ \TeXbook exc. 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
% was |\scriptsize|, so too large.
% \changes{v0.81}{2007/05/13}{moved here from \pk{pmlectionis.cls}}

%^^A% From my first love with infinite stretchabilities
%^^A~ \def\myvfil#1/{\vskip0pt plus#1fil\relax}
%^^A~ \def\myvfill#1/{\vskip0pt plus#1fill\relax}
%^^A~ \def\myhfil#1/{\hskip0pt plus#1fil\relax}
%^^A~ \def\myhfill#1/{\hskip0pt plus#1fill\relax}

\def\dekfracc#1/#2{\leavevmode\kern.1em
  \raise.5ex\hbox{\udigits\scriptsize#1}\kern-.1em
  /\kern-.15em\lower.25ex\hbox{\udigits\scriptsize#2}}


\def\fnfracc#1/#2{\leavevmode\kern.1em
  \raise.6ex\hbox{\udigits\tiny#1}\kern-.1em
  /\kern-.1em\lower.25ex\hbox{\udigits\tiny#2}}
% \changes{v0.81}{2007/05/13}{moved here from \pk{pmlectionis.cls}}


% A~macro that  acts like |\,| (thin and unbreakable space) except it
% allows hyphenation afterwards:

\newcommand*\ikern{\,\penalty10000\hskip0sp\relax}
%\changes{v0.82}{2007/07/17}{added}

% And a~macro to forbid hyphenation of the next word:
\newcommand*\nohy{\kern\z@}


% \subdivision{\cs{@ifempty}}

\long\def\@ifempty#1#2#3{%
  \def\gmu@reserveda{#1}%
  \ifx\gmu@reserveda\@empty\afterfi{#2}%
  \else\afterfi{#3}\fi
}



% \subdivision{\cs{include} not only \file{.tex}'s}
% |\include| modified by me below lets you to include files of any
% extension provided that extension in the argument. 
% 
% If you want to |\include| a~non-\file{.tex} file and deal with it
% with |\includeonly|, give the latter command full file name, with
% the extension that is.
%
\def\gmu@getext#1.#2\@@nil{%
  \def\gmu@filename{#1}%
  \def\gmu@fileext{#2}}

\def\include#1{\relax
  \ifnum\@auxout=\@partaux
  \@latex@error{\string\include\space cannot be nested}\@eha
  \else \@include#1 \fi}

\def\@include#1 {%
  \gmu@getext#1.\@@nil
  \ifx\gmu@fileext\empty\def\gmu@fileext{tex}\fi
  \clearpage
  \if@filesw
    \immediate\write\@mainaux{\string\@input{\gmu@filename.aux}}%
  \fi
  \@tempswatrue
  \if@partsw
    \@tempswafalse
    \edef\reserved@b{#1}%
    \@for\reserved@a:=\@partlist\do{%
      \ifx\reserved@a\reserved@b\@tempswatrue\fi}%
  \fi
  \if@tempswa
    \let\@auxout\@partaux
    \if@filesw
      \immediate\openout\@partaux \gmu@filename.aux
      \immediate\write\@partaux{\relax}%
    \fi
    \@input@{\gmu@filename.\gmu@fileext}%
    \inclasthook
    \clearpage
    \@writeckpt{\gmu@filename}%
    \if@filesw
      \immediate\closeout\@partaux
    \fi
  \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@filename}%
  \fi
  \let\@auxout\@mainaux}


\newcommand\whenonly[3]{%
  \def\gmu@whonly{#1,}%
  \ifx\gmu@whonly\@partlist\afterfi{#2}\else\afterfi{#3}\fi}

% I~assume one usually includes chapters or so so the last page style
% should be closing.
\def\inclasthook{\thispagestyle{closing}}



% \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
      \ifnum\the\lccode`#1=`#1\relax
        {\gmu@scsetup\MakeUppercase{#1}}% not Plain |\uppercase|
                                % because that works bad with \pk{inputenc}.
      \else#1%
      \fi
    \else#1%
    \fi%
    \@xa\gmu@scapLetters
  \fi}%
%
\def\gmu@scapSpaces#1 #2\@@nil{%
  \ifx#1\relax\relax
  \else\gmu@scapLetters#1\relax
  \fi
  \ifx#2\relax\relax
  \else\afterfi{\ \gmu@scapSpaces#2\@@nil}%
  \fi}
%
\def\gmu@scapss#1\@@nil{{\def~{{\nobreakspace}}%
    \gmu@scapSpaces#1 \@@nil}}%|% \def\\{{\newline}}\relax|
                                % adding redefinition of |\\| caused
                                % stack overflow
% Note it disallows hyphenation except at |\-|.
\DeclareRobustCommand\fakescaps[2][\gmu@scalematchX]{{%
    \let\gmu@scsetup=#1\gmu@scapss#2\@@nil}}

% Experimente z~akcentami patrz no3.tex.
\def\tinycae{{\tiny\AE}}% to use in |\fakescaps[\tiny]{...}|

\RequirePackage{calc}

% wg |\zf@calc@scale| pakietu \pk{fontspec}.

\@ifXeTeX{%
  \def\gmu@scalematchX{%
    \begingroup
      \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
      % uppercase height.
      \divide\@tempdimb by1000\relax
      \divide\@tempdima by\@tempdimb
      \setlength{\@tempdima}{\@tempdima*\real{\gmu@scalar}}%
      \@ifundefined{fakesc@extrascale}{}{%
        \setlength{\@tempdima}{\@tempdima*\real{\fakesc@extrascale}}}%
      \@tempcnta=\@tempdima
      \divide\@tempcnta by 1000\relax
      \@tempcntb=-1000\relax
      \multiply\@tempcntb by\@tempcnta
      \advance\@tempcntb by\@tempdima
      \xdef\gmu@scscale{\the\@tempcnta.%
        \ifnum\@tempcntb<100 0\fi
        \ifnum\@tempcntb<10 0\fi
        \the\@tempcntb}%^^A{\strip@pt\@tempdimc}%
%^^A      \typeout{**** \gmu@scscale}%
    \endgroup
    \addfontfeature{Scale=\gmu@scscale}%
  }}{\let\gmu@scalematchX\smallerr}

\def\fakescextrascale#1{\def\fakesc@extrascale{#1}}
 

% \subdivision{See above/see below}
% To generate a~phrase as in the header depending of whether the
% respective label is before of after.
\newcommand*\wyzejnizej[1]{%
  \edef\gmu@tempa{\@ifundefined{r@#1}{\arabic{page}}{%
      \@xa\@xa\@xa\@secondoftwo\csname r@#1\endcsname}}%
  \ifnum\gmu@tempa<\arabic{page}\relax wy\.zej\fi
  \ifnum\gmu@tempa>\arabic{page}\relax ni\.zej\fi
  \ifnum\gmu@tempa=\arabic{page}\relax \@xa\ignorespaces\fi
}


%\subdivision{\env{luzniej} and \env{napapierki}---environments ^^B
%  used in page breaking for money}
%
% The name of first of them comes from Polish typesetters' phrase
% ``rozbija\cacute\ [sk\l ad] na papierki''---`to broaden [leading] with
% paper scratches'.

\def\napapierkistretch{0,3pt}% It's quite much for 11/13pt typesetting

\newenvironment*{napapierki}{%
  \par\global\advance\baselineskip%
  by 0ptplus\napapierkistretch\relax}{%
  \par\dimen\z@=\baselineskip
  \global\baselineskip=\dimen\z@}% so that you can use  |\endnapapierki|
                              % in interlacing environments


\newenvironment*{luzniej}[1][1]{%
  \multiply\tolerance by 2\relax
  \looseness=#1\relax}{\par}


% 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
\AtBeginDocument{% to be independent of moment of loading of \pk{polski}.
  \DeclareRobustCommand*\pauza{%
    \ifhmode\unskip\penalty10000\hskip0.2em plus0.1em\relax\fi
    \pauzacore\hskip.2em plus0.1em\ignorespaces}}

\def\pauzacore{---}
\def\shortpauza{% 
  \def\pauzacore{--\kern,23em\relax\llap{--}}}


\endinput
%
% \ChangesGeneral
%
% \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}
%
% \changes{v0.74}{2006/11/28}{Added macros to make sectioning commands
% of \pk{mwcls} and standard classes compatible. Now my sectionings
% allow two optionals in both worlds and with \pk{mwcls} if there's
% only one optional, it's the title to toc and running head not just
% to the latter}
%
% \changes{v0.76}{2007/03/10}{A~`fixing' of \cs{dots} was rolled back
% since it came out they were O.K. and that was the QX encoding that
% prints them very tight}
%
% \changes{v0.77}{2007/04/13}{\cs{afterfi} \& pals made two-argument
% as the Marcin Woli\nacute ski's analogoi are. At this occasion some
% redundant macros of that family are deleted}
% 
% \changes{v0.78}{2007/04/26}{\cs{@namelet} renamed to \cs{n@melet}
% to solve a~conflict with the \pk{beamer} class. The package contents
% regrouped}
%
% \changes{v0.85}{2007/11/16}{fixed behaviour of too clever headings
% with \pk{gmdoc} by adding an \cs{ifdim} test}
%
%
% \PrintChanges\PrintIndex
%\NoEOF

% (For my GNU Emacs:)
%%% Local Variables: 
%%% mode: doctex
%%% TeX-master: "../../../../LaTeX/TeXGuru/gmutils/gmutilsDoc.tex"
%%% End: 
