summaryrefslogtreecommitdiff
path: root/macros/generic/etoolbox-generic/etoolbox-generic.tex
blob: c1fcd869acb7281875e18ed89c69c7685c558e34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
% etoolbox-generic.tex 2023/10/10 v2.5k
%
% This is a loader for etoolbox.sty 2020/10/05 v2.5k in non-LaTeX formats.
%
% Copyright (c) 2023- Saso Zivanovic <saso.zivanovic@guest.arnes.si>
%
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3c of this license or (at
% your option) any later version.  The latest version of this license is in
% https://www.latex-project.org/lppl.txt and version 1.3c or later is part of
% all distributions of LaTeX version 2008 or later.
%
% This work has the LPPL maintenance status `maintained`.
% The Current Maintainer of this work is Saso Zivanovic.
%
% This work consist of this file and README.md.
% 
% Prevent double-loading.
\ifcsname ver@etoolbox.sty\endcsname
  \expandafter\endinput
\fi
% We need miniltx and a couple of auxiliary macros.
\input miniltx
\def\newif#1{%
  \count@\escapechar \escapechar\m@ne
    \let#1\iffalse
    \@if#1\iftrue
    \@if#1\iffalse
  \escapechar\count@}
\def\@if#1#2{%
  \expandafter\def\csname\expandafter\@gobbletwo\string#1%
  \expandafter\@gobbletwo\string#2\endcsname
  {\let#1#2}}
% We need to define \AtEndOfPackage; etoolbox uses it to undefine its
% catcodes. We're careful and restore the old (probably empty) definition at
% the end.
\let\etb@AtEndOfPackage\AtEndOfPackage
\def\AtEndOfPackage#1{\def\AtEndOfPackageDo{#1}}
% Kindly, all the LaTeX-specific code in etoolbox.sty occurs after
% the call to \IfFormatAtLeastTF. Redefining this macro to \endinput will
% therefore remove the LaTeX-specific part of the package:
\def\IfFormatAtLeastTF#1#2#3{\endinput}
\let\etb@extrafloats\extrafloats
\let\extrafloats\relax
\input etoolbox.sty
% Restore what we changed, and execute the end-of-package code.
\let\extrafloats\etb@extrafloats
\AtEndOfPackageDo
\let\AtEndOfPackage\etb@AtEndOfPackage
\let\AtEndOfPackageDo\relax
\cslet{ver@etoolbox.sty}\relax
% To have this package work in ConTeXt, we must patch the macros by replacing
% \unexpanded with \normalunexpanded.
\ifcsname normalunexpanded\endcsname
  \def\etb@patchunexpanded#1{%
    \patchcmd#1\unexpanded\normalunexpanded{}{%
      \PackageError{etoolbox}{Cannot adapt command \string#1 to ConTeXt}{}%
    }%
  }
  % \patchcmd itself uses \etb@patchcmd@scantoks which uses \unexpanded; so we
  % temporarily redefine \unexpanded to patch \etb@patchcmd@scantoks.
  \let\unexpanded\normalunexpanded
  \etb@patchunexpanded\etb@patchcmd@scantoks
  \let\unexpanded\protected
  % Now we can patch the rest.
  \etb@patchunexpanded\expandonce
  \etb@patchunexpanded\etb@unexpandable
  \etb@patchunexpanded\appto\etb@patchunexpanded\appto
  \etb@patchunexpanded\gappto\etb@patchunexpanded\gappto
  \etb@patchunexpanded\preto\etb@patchunexpanded\preto
  \etb@patchunexpanded\gpreto\etb@patchunexpanded\gpreto
  \etb@patchunexpanded\etb@hooktocmd
  % Patching \protecting is a bit involved, as its parameters text is #.
  \expandafter\def\expandafter\protecting\expandafter{\protecting{}}
  \etb@patchunexpanded\protecting
  \patchcmd\protecting{{}}{}{}{}%
  \expandafter\def\expandafter\protecting\expandafter#\expandafter{\protecting}
\fi
\resetatcatcode
\endinput