summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/currfile/currfile.dtx
blob: 03a66bedbd9822de23671d0347bd383fdd90645a (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
% \iffalse meta-comment
%% Copyright (c) 2010 by Martin Scharrer <martin@scharrer-online.de>
%% -----------------------------------------------------------------
%%
%% 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
%%
%%   http://www.latex-project.org/lppl.txt
%%
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008/05/04 or later.
%%
%% This work has the LPPL maintenance status `maintained'.
%%
%% The Current Maintainer of this work is Martin Scharrer.
%%
%% This work consists of the files currfile.dtx, currfile.ins
%% and the derived file currfile.sty.
%%
%% $Id: currfile.dtx 1911 2010-12-08 19:29:13Z martin $
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{currfile.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%<package>\ProvidesPackage{currfile}
%<*package>
    [2010/12/08 v0.2 Current input file name and path]
%</package>
%
%<*driver>
\documentclass{ltxdoc}
\usepackage{currfile}[2010/04/08]
\usepackage{ifpdf}
\usepackage{booktabs}
\usepackage{hyperref}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\providecommand*\pkg{\texttt}
\begin{document}
  \DocInput{currfile.dtx}
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{209}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.1}{2010/04/08}{Initial version}
% \changes{v0.2}{2010/04/10}{Now work for all files, not only for \cs{input} and \cs{include} files.
%  Added package option 'fink' to define the same macros as the 'fink' package.
% }
%
% \GetFileInfo{currfile.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment}
% 
% \ifpdf
% \hypersetup{%
%   pdfauthor   = {Martin Scharrer <martin@scharrer-online.de>},
%   pdftitle    = {The currfile package},
%   pdfsubject  = {Documentation of LaTeX package 'currfile'},
%   pdfkeywords = {current filename, filename, file, name, LaTeX, TeX}
% }%
% \fi
% \clearpage
% \null
% \vspace*{-2em}
% \begin{center}
%   {\LARGE\sffamily The \emph{currfile} Package\\[\medskipamount]}
%   {\large Martin Scharrer \\[\medskipamount]\normalsize 
%   \url{martin@scharrer-online.de}\\[.8ex]
%   \url{http://www.ctan.org/pkg/currfile/}\\[\bigskipamount]}
%   {\large Version \fileversion\ -- \filedate}\\
% \end{center}
% \vspace{1.2em}%
%
% \begin{abstract}
% This small package provides the file name and path information of the current input file as \LaTeX{} macros.
% \end{abstract}
%
% \section{Usage}
%
% \DescribeMacro{\currfiledir}
% \DescribeMacro{\currfilebase}
% \DescribeMacro{\currfileext}
% \DescribeMacro{\currfilename}
% \DescribeMacro{\currfilepath}
% The directory, base (name without extension), extension (without dot), name (=base+`|.|'+ext) and path (=dir+name) of the current file are provided by these macros.
% This means that the macros returns the file information of the file they are used in. All macros are fully expanded, i.e.\ only hold
% text and not further macros.
% Special care is taken to keep the file information of |\include|d files till the final |\clearpage| command, so that page header and footer of the last page 
% will hold the correct data.
%
% Since v0.2 all files are are taken into account, i.e.\ files read using |\input|, |\include|, |\InputIfFileExists|, |\usepackage|, |\RequirePackage| and even
% |\LoadClass| and similar macros. Before v0.2 only |\input| or |\include| and the main file were taken into account.
%
% This package uses the |filehook| package written by the same author. See there for possible incompatibilities with classes or other packages.
%
% More detailed information can be found in the implementation section \ref{sec:impl} if required.
%
% \subsection*{Package Options}
% The package provides two options |mainext| and |maindir| which can be used to provide the extension and directory of the main file.
% This is required if the above macros should be used for the main file itself and if this does has a file extension other than `|.tex|' (e.g.\ a |.dtx| file)
% or is not located in the current directory. To provide support for the macros defined by the |fink| package (see section~\ref{sec:fink}) a |fink| option exists.
%
% \section{Compatibility with the \texttt{fink} package}\label{sec:fink}
% The |fink| package (\emph{fi}le \emph{n}ame \emph{k}eeper) provides a similar functionality. It has inspired this package in several points (e.g.\ package
% options). However, it does not exclude package and other preamble files and does not take care to change the filename \emph{after} the |\clearpage| of
% |\include|. The author of \texttt{fink} is now discontinuing it in favour of this package.
% Existing documents which use |fink| should either rename the related macros as shown by Table~\ref{tab:fink} or use the |fink| option of |currfile| which defines
% the |fink| macros to use the |currfile| ones.
%
% Because both packages do basically the same thing, especially patch the same macros, there are incompatible and should not be loaded both.
% In consent with the |fink| package author this package will undo most of the |fink| code if it was already loaded or prevent it from being loaded afterwards.
%
% \begin{table}
% \belowcaptionskip=\abovecaptionskip
% \abovecaptionskip=0pt
% \caption{Conversion from \texttt{fink} package to \texttt{currfile}.}
% \label{tab:fink}
% \centering
% \begin{tabular}{lll}
%   \toprule
%    \texttt{fink}  &  \texttt{currfile} &  Example Result \\
%   \midrule
%      \cs{finkdir}  &  \cs{currfiledir}  & \ttfamily\currfiledir  \\
%      \cs{finkbase} &  \cs{currfilebase} & \ttfamily\currfilebase \\
%      \cs{finkext}  &  \cs{currfileext}  & \ttfamily\currfileext  \\
%      \cs{finkfile} &  \cs{currfilename} & \ttfamily\currfilename \\
%      \cs{finkpath} &  \cs{currfilepath} & \ttfamily\currfilepath \\
%   \bottomrule
% \end{tabular}
% \end{table}
%
% \StopEventually{}
%
%
% \section{Implementation}\label{sec:impl}
%
% \iffalse
%<*package>
% \fi
% \subsection{Options}
%
%    \begin{macrocode}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{family=currfile,prefix=currfile@}

\@ifl@aded{\@pkgextension}{fink}{%
    \DeclareStringOption[\fnk@mainext]{mainext}%
    \DeclareStringOption[\fnk@maindir]{maindir}%
    \DeclareBoolOption[true]{fink}%
    \PackageWarning{currfile}{Package 'fink' detected. %
      The 'fink' option will default to 'true'. %
      If set to 'false' no 'fink' macros will be changed but they will stop
      working correctly!}{}{}{}%
}{%
    \DeclareStringOption[tex]{mainext}%
    \DeclareStringOption[\@currdir]{maindir}%
    \DeclareBoolOption[false]{fink}%
}%
\ProcessKeyvalOptions*\relax

\begingroup
\xdef\currfile@mainext{\currfile@mainext}%
\xdef\currfile@maindir{\currfile@maindir}%
\def\@tempa{./}%
\ifx\@tempa\currfile@maindir
    \global\let\currfile@maindir\empty
\fi
\endgroup
%    \end{macrocode}
%
%
% \subsection{File Hooks}
% The \pkg{filehook} package is used to execute the macros at the correct places.
% The internal interface, not the user-interface, is used to make sure that the file names are valid for all other hooks.
%
%    \begin{macrocode}
\RequirePackage{filehook}
%    \end{macrocode}
%
%    \begin{macrocode}
\filehook@prefixwarg\filehook@include@atbegin{%
  \currfile@push
  \currfile@set{#1}%
}
\filehook@appendwarg\filehook@include@after{%
  \currfile@pop
}
\filehook@prefixwarg\filehook@atbegin{%
  \currfile@push
  \currfile@set{#1}%
}
\filehook@appendwarg\filehook@atend{%
  \currfile@pop
}
%    \end{macrocode}
%
%
% \subsection{Set Current Values}
%
% \begin{macro}{\currfile@set}
% Sets the file information which are parsed by \LaTeX's |\filename@parse|.
%    \begin{macrocode}
\def\currfile@set#1{%
  \begingroup
    \filename@parse{#1}%
    \global\let\currfiledir\filename@area
    \global\let\currfilebase\filename@base
    \xdef\currfileext{\ifx\filename@ext\relax tex\else\filename@ext\fi}%
    \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}%
    \xdef\currfilepath{\currfiledir\currfilename}%
  \endgroup
%<debug> \expandafter\gdef\expandafter\dindent\expandafter{\dindent\space}%
%<debug> \message{^^JDEBUG: \dindent\empty Entering file '\currfilename' ^^J }%
}
%    \end{macrocode}
% \end{macro}
%
%
% \subsection{File Stack}
% The file information are pushed and popped on a stack to save and restore them when
% entering and leaving a sub-file, respectively. This is quite similar to the way 
% \LaTeX\ saves file base names and extension as well as the `@' status (letter or other) for
% package and class files.
%
% \begin{macro}{\currfile@push}
%    \begin{macrocode}
\def\currfile@push{%
  \xdef\currfile@stack{%
    {\currfiledir}%
    {\currfilebase}%
    {\currfileext}%
    \currfile@stack
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\currfile@pop}
%    \begin{macrocode}
\def\currfile@pop{%
%<debug> \message{^^JDEBUG: \dindent\empty Leaving file '\currfilename' ^^J }%
  \ifx\currfile@stack\empty
    \PackageWarning{currfile}{File stack underflow!}{}{}%
    \global\let\currfile@stack\currfile@stackinit
  \fi
  \expandafter\currfile@pop@\currfile@stack\relax
  \relax\relax\relax
%<debug> \message{^^JDEBUG: \dindent\empty Restoring file '\currfilename' ^^J }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\currfile@pop@}
%    \begin{macrocode}
\def\currfile@pop@#1#2#3#4\relax{%
  \gdef\currfiledir{#1}%
  \gdef\currfilebase{#2}%
  \gdef\currfileext{#3}%
  \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}%
  \xdef\currfilepath{\currfiledir\currfilename}%
  \gdef\currfile@stack{#4}%
%<debug> \expandafter\expandafter\expandafter\gdef
%<debug> \expandafter\expandafter\expandafter\dindent
%<debug> \expandafter\expandafter\expandafter{\expandafter\@gobble\dindent}%
}
%    \end{macrocode}
% \end{macro}
%
% \iffalse
%<debug> \def\dindent{}
% \fi
%
% \begin{macro}{\currfile@stack}
% \begin{macro}{\currfile@stackinit}
% Place |\jobname| values on stack and use this as init value.
%    \begin{macrocode}
\def\currfile@stack{}
\currfile@set{\currfile@maindir\jobname.\currfile@mainext}
\currfile@push
\let\currfile@stackinit\currfile@stack
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{Fink Macros}
%
% The |fink| option defines all |fink| package macros to use the ones provided
% by this package. If the |fink| package was loaded beforehand the restoration
% of these macros must be avoided at the end of this file
% (|fink|s |\InputIfFileExists| was then used to load this package).
% If the package was not loaded its version is set to a dummy value and its
% options to this package options. If |fink| is attempted to be loaded later
% it will trigger an package option clash if different option are used.
% Otherwise it will be taken as already loaded and not loaded ``again''.
%
%    \begin{macrocode}
\ifcurrfile@fink
    \def\finkfile{\currfilename}%
    \def\finkdir{\currfiledir}%
    \def\finkpath{\currfilepath}%
    \def\finkbase{\currfilebase}%
    \def\finkext{\currfileext}%
    \@ifl@aded{\@pkgextension}{fink}{%
        \def\fink@restore#1{}%
    }{%
        \@namedef{ver@fink.sty}{2010/12/06}%
        \expandafter\edef\csname opt@fink.sty\endcsname{%
            maindir=\currfile@maindir,mainext=\currfile@mainext
        }%
    }%
\else
    \@ifl@aded{\@pkgextension}{fink}{}{%
        \AtBeginOfFile{fink.sty}{%
            \PackageError{currfile}{Package class with deprecated 'fink'. %
             Load 'currfile' with the 'fink' option or see the upgrade guide in the manual}{}{}{}%
        }%
    }%
\fi
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale
\endinput