summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bxorigcapt/bxorigcapt.sty
blob: 6de4b9386ef2c2a2cb32a51944796b82dcb739ef (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
%%
%% This is file 'bxorigcapt.sty'.
%% 
%% Copyright (c) 2017 Takayuki YATO (aka. "ZR")
%%   GitHub:   https://github.com/zr-tex8r
%%   Twitter:  @zr_tex8r
%%
%% This package is distributed under the MIT License.
%%

%% package declaration
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxorigcapt}[2017/05/03 v0.2a]
\def\bxoc@pkgname{bxorigcapt}
\providecommand*\bxDebug[1]{}

%% code guard
\edef\bxoc@restore@codes{%
\catcode39=\the\catcode39%
\catcode46=\the\catcode46%
\catcode47=\the\catcode47%
\catcode58=\the\catcode58%
\relax}
\catcode39=12 % <'>
\catcode46=12 % <.>
\catcode47=12 % </>
\catcode58=12 % <:>
\AtEndOfPackage{%
\bxoc@restore@codes
\let\bxoc@restore@codes\relax}

%--------------------------------------- options

%% \bxoc@target@lang
\let\bxoc@target@lang\relax

%% language options
\DeclareOption*{%
  \edef\bxoc@target@lang{\CurrentOption}%
}
% dispatch
\ProcessOptions*

%--------------------------------------- general

%% \bxoc@name@list
% The list of caption names.
\@onlypreamble\bxoc@name@list
\def\bxoc@name@list{%
  abstract,also,appendix,author,bib,cc,chapter,contents,%
  encl,figure,glossary,headto,index,listfigure,listtable,%
  page,part,preface,proof,ps,ref,seealso,see,subject,table,%
  prepart,postpart,prechapter,postchapter,presection,postsection%
}

%% \bxoc@deprecated@ldf@list
% The list of the names of deprecated commands.
\@onlypreamble\bxoc@deprecated@ldf@list
\def\bxoc@deprecated@ldf@list{}

%--------------------------------------- public commands

%%<+> \bxorigcaptDeprecateCommand{<csname>,...}
\@onlypreamble\bxorigcaptDeprecateCommand
\newcommand*\bxorigcaptDeprecateCommand[1]{%
  \edef\bxoc@deprecated@ldf@list{\bxoc@deprecated@ldf@list,#1}}

%--------------------------------------- hook

%% \bxoc@babel@hook
% Note that \bxoc@babel@hook must be invoked between the loading
% of babel and the dispatch of babel's begin-document hook.
\@onlypreamble\bxoc@babel@hook
\let\bxoc@babel@hook\@empty
\@ifpackageloaded{babel}{%
  \AtEndOfPackage{\bxoc@babel@hook}%
}{%else
  \AtBeginDocument{%
    \@ifpackageloaded{babel}{%
      \bxoc@babel@hook
    }{%else
      \PackageWarning\bxoc@pkgname
       {Babel is not loaded,}%
    }%
  }%
}

%--------------------------------------- deprecated ldf stuffs

%% \bxoc@clear@deprecated@ldf
\@onlypreamble\bxoc@clear@deprecated@ldf
\def\bxoc@clear@deprecated@ldf{%
  \begingroup
    \@for\bxoc@tmpa:=\bxoc@deprecated@ldf@list\do{%
      \ifx\@bxoc@tmpa\@empty\else
        \expandafter\ifx\csname \bxoc@tmpa\endcsname\relax\else
          \bxDebug{Smashed \@backslashchar\bxoc@tmpa}%
          \global\expandafter\let\csname\bxoc@tmpa\endcsname\@empty
        \fi
      \fi
    }%
  \endgroup
  \bxoc@clear@deprecated@ldf@a
}
\@onlypreamble\bxoc@clear@deprecated@ldf@a
\def\bxoc@clear@deprecated@ldf@a{%
  \global\let\bxoc@clear@deprecated@ldf@a\relax
  \gdef\bxorigcaptDeprecateCommand##1{%
    \edef\bxoc@deprecated@ldf@list{##1}%
    \bxoc@clear@deprecated@ldf}}
\g@addto@macro\bxoc@babel@hook{\bxoc@clear@deprecated@ldf}

%--------------------------------------- save and restore

%% variables
\let\bxoc@@today\relax
% \[bxoc@@<caption>name]

%% \bxoc@save@captions
%% \bxoc@restore@captions
\@onlypreamble\bxoc@save@captions
\let\bxoc@save@captions\@empty
\let\bxoc@restore@captions\@empty
\begingroup
  \@for\bxoc@tmpa:=\bxoc@name@list\do{%
    \edef\bxoc@next{%
      \noexpand\g@addto@macro\noexpand\bxoc@save@captions{%
        \let\expandafter\noexpand\csname bxoc@@\bxoc@tmpa name\endcsname
            \expandafter\noexpand\csname\bxoc@tmpa name\endcsname}%
    }\bxoc@next
    \edef\bxoc@next{%
      \noexpand\g@addto@macro\noexpand\bxoc@restore@captions{%
        \let\expandafter\noexpand\csname \bxoc@tmpa name\endcsname
            \expandafter\noexpand\csname bxoc@@\bxoc@tmpa name\endcsname}%
    }\bxoc@next
  }
\endgroup

%% \bxoc@restore@date
\def\bxoc@restore@date{%
  \let\today\bxoc@@today
}

%% \bxoc@enable@restore
\@onlypreamble\bxoc@enable@restore
\def\bxoc@enable@restore{%
  \ifx\bxoc@target@lang\relax
    \let\bxoc@target@lang\bbl@main@language
  \fi
  \bxDebug{target=\bxoc@target@lang}%
  \expandafter\ifx\csname date\bxoc@target@lang\endcsname\relax
    \PackageError\bxoc@pkgname
     {Language '\bxoc@target@lang' not defined}%
      \@ehc
    \@namedef{date\bxoc@target@lang}{}%
  \fi
  \expandafter\ifx\csname captions\bxoc@target@lang\endcsname\relax
    \@namedef{captions\bxoc@target@lang}{}%
  \fi
  \expandafter\g@addto@macro\csname date\bxoc@target@lang\endcsname{%
    \bxoc@restore@date}%
  \expandafter\g@addto@macro\csname captions\bxoc@target@lang\endcsname{%
    \bxoc@restore@captions}%
}

%% Saves the current captions
\bxoc@save@captions
\let\bxoc@@today\today
\g@addto@macro\bxoc@babel@hook{\bxoc@enable@restore}

%--------------------------------------- done
\endinput
%% EOF