Debian Codegraph @

texmf-dist/source/latex/currfile/currfile.dtx

raw
1 % \iffalse meta-comment
2 %<=*COPYRIGHT>
3 %%
4 %% Copyright (c) 2010-2024 by Martin Scharrer <[email protected]>
5 %% ----------------------------------------------------------------------
6 %%
7 %% This work may be distributed and/or modified under the
8 %% conditions of the LaTeX Project Public License, either version 1.3c
9 %% of this license or (at your option) any later version.
10 %% The latest version of this license is in
11 %%
12 %% http://www.latex-project.org/lppl.txt
13 %%
14 %% and version 1.3c or later is part of all distributions of LaTeX
15 %% version 2008/05/04 or later.
16 %%
17 %% This work has the LPPL maintenance status `maintained'.
18 %%
19 %% The Current Maintainer of this work is Martin Scharrer.
20 %%
21 %% This work consists of the files currfile.dtx, currfile.ins
22 %% and currfile.sty.
23 %%
24 %<=/COPYRIGHT>
25 % \fi
26 %
27 % \iffalse
28 %<*driver>
29 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
30 \ProvidesFile{currfile.dtx}[%
31 %<=*DATE>
32 2024/03/14
33 %<=/DATE>
34 %<=*VERSION>
35 v1.0
36 %<=/VERSION>
37 DTX file for currfile package]
38
39 \documentclass{ydoc}[2011/03/19]
40 \usepackage{currfile}[2011/09/18]
41 \usepackage{ifpdf}
42 \usepackage{booktabs}
43 \usepackage{hyperref}
44 \usepackage{flafter}
45 \EnableCrossrefs
46 \CodelineIndex
47 \RecordChanges
48 \let\IncludeImplementation\relax
49 %\let\IncludeImplementation\empty %^^A Enable implementation
50 \ifx\IncludeImplementation\relax
51 \OnlyDescription
52 \fi
53 \let\cnt\env
54 \begin{document}
55 \DocInput{currfile.dtx}
56 \PrintChanges
57 \PrintIndex
58 \end{document}
59 %</driver>
60 % \fi
61 %
62 % \CheckSum{1115}
63 %
64 % \CharacterTable
65 % {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
66 % 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
67 % Digits \0\1\2\3\4\5\6\7\8\9
68 % Exclamation \! Double quote \" Hash (number) \#
69 % Dollar \$ Percent \% Ampersand \&
70 % Acute accent \' Left paren \( Right paren \)
71 % Asterisk \* Plus \+ Comma \,
72 % Minus \- Point \. Solidus \/
73 % Colon \: Semicolon \; Less than \<
74 % Equals \= Greater than \> Question mark \?
75 % Commercial at \@ Left bracket \[ Backslash \\
76 % Right bracket \] Circumflex \^ Underscore \_
77 % Grave accent \` Left brace \{ Vertical bar \|
78 % Right brace \} Tilde \~}
79 %
80 %
81 % \changes{v0.1}{2010/04/08}{Initial version}
82 % \changes{v0.2}{2010/04/10}{Now work for all files, not only for \cs{input} and \cs{include} files.
83 % Added package option 'fink' to define the same macros as the 'fink' package.
84 % }
85 % \changes{v0.3}{2011/01/03}{Update to use new version of filehook.}
86 % \changes{v0.4}{2011/01/09}{Added if-macros and sanitized currfile macros.}
87 % \changes{v0.5}{2011/09/18}{Added support for \cs{input@path} and files with multiple dots.}
88 % \changes{v0.6}{2012/05/06}{Added support for absolute file paths.}
89 % \changes{v0.7}{2012/05/15}{Added support for parent file paths.}
90 % \changes{v0.7a}{2012/10/28}{Fixed issue with \pkg{enumitem} package which redefines \cs{value}.}
91 % \changes{v0.7b}{2013/02/01}{Support for \cs{\subinput*} etc.\ from the \pkg{import} package which requires a different path search order.}
92 % \changes{v0.7c}{2015/04/23}{Removed stack underflow warning if loaded by other package. Set default file name in this case to main file name.}
93 % \changes{v0.7d}{2020/09/29}{Updated documentation for 2020/10/01 \LaTeX\ release.}
94 % \changes{v0.8}{2022/10/10}{Fixed issue with filename with spaces.}
95 %
96 %
97 % \GetFileInfo{currfile.dtx}
98 %
99 % \DoNotIndex{\newcommand,\newenvironment,\fi,\relax,\def,\gdef,\xdef}
100 % \DoNotIndex{\RequirePackage,\space,\PackageError,\PackageWarning,\let}
101 % \DoNotIndex{\ifx,\global,\long,\dindent,\else,\empty,\expandafter}
102 % \DoNotIndex{\csname,\endcsname,\DeclareBoolOption,\DeclareStringOption}
103 % \DoNotIndex{\SetupKeyvalOptions,\begingroup,\endgroup,\@gobble,\edef}
104 % \DoNotIndex{\message,\jobname,\@namedef}
105 %
106 % \author{Martin Scharrer}
107 % \email{[email protected]}
108 % \repository{https://github.com/MartinScharrer/currfile}
109 % \maketitle
110 %
111 % \begin{abstract}
112 % This small package provides the file name and path information of the current input file as \LaTeX{} macros.
113 % It properly supports file names with multiple dots and the \cs{input@path} feature used by some packages like \pkg{import}.
114 % Optionally also the absolute location of current input file can be provided if a special compiler option is enabled.
115 % \end{abstract}
116 %
117 % \tableofcontents
118 %
119 % \section{Direct filename support in \LaTeX\ 2020/10/01}
120 % With the \LaTeX\ release 2020/10/01 the core now provides own filehooks and access to the current filename and path.
121 % This package still uses the authors \pkg{filehook} package to collect the filenames but there the core implementation is now used internally.
122 % Due to this users could see changes in the output in some special cases.
123 %
124 % For new documents users might want to use the new core macros \Macro\CurrentFile and \Macro\CurrentFilePath discribed in
125 % \href{http://mirrors.ctan.org/macros/latex-dev/base/ltfilehook-doc.pdf}{\texttt{ltfilehook-doc}}
126 % directly and use this package only if the advanced features -- like parent or absolute file names - are required.
127 % Note that \Macro\CurrentFile is empty for the main document which filename can be accessed usually over \Macro\jobname.
128 %
129 %
130 % \section{Important notice}
131 % This package relies heavily on the package \pkg{filehook} by the same author and installs at-begin and at-end hooks for all files.
132 % The provided macros for the file names \emph{will only work for files loaded \emph{after} the package}.
133 % This means only for files which are getting opened afterwards and where not yet opened, as the at-begin hook is required to run.
134 % The macros will therefore not work correctly in a package which loaded \pkg{currfile}, but for all further loaded packages.
135 %
136 % The options \opt{abspath} and \opt{realmainfile} may be used to improve the behavior in such cases.
137 %
138 % However, it is simply recommended to load \pkg{currfile} as early as possible. It can even be loaded before the class using
139 % \Macro\RequirePackage{currfile}.
140 %
141 % \section{Usage}
142 %
143 % \DescribeMacro{\currfiledir}
144 % \DescribeMacro{\currfilebase}
145 % \DescribeMacro{\currfileext}
146 % \DescribeMacro{\currfilename}
147 % \DescribeMacro{\currfilepath}
148 % 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.
149 % 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
150 % text and not further macros. They are also ``sanitized'' to ensure that all characters, especially special ones like `|_|', are taken verbatim.
151 % However this special characters might not be displayed correctly in all fonts. A good font is text-type (\Macro\ttfamily, \Macro\texttt{\ldots}),
152 % but other fonts can be used using the \pkg{url} package, e.g.: |\urlstyle{rm}\expandafter\nolinkurl\expandafter{\currfilename}|.
153 % Note that the directory separator is always `|/|' even under MS Windows.
154 %
155 % Special care is taken to keep the file information of \Macro\included files till the final \Macro\clearpage command, so that page header and footer of the last page
156 % will hold the correct data.
157 %
158 % Since v0.2 all files are are taken into account, i.e.\ files read using \Macro\input, \Macro\include, \Macro\InputIfFileExists, \Macro\usepackage, \Macro\RequirePackage and even
159 % \Macro\LoadClass and similar macros. Before v0.2 only \Macro\input or \Macro\include and the main file were taken into account.
160 %
161 % This package uses the \pkg{filehook} package written by the same author. See there for possible incompatibilities with classes or other packages.
162 %
163 % If required more detailed information can be found in the implementation section \ifx\IncludeImplementation\relax(compile this manual with \Macro\AlsoImplementation)\else
164 % \unskip~\ref{sec:impl}\fi.
165 %
166 % \begingroup
167 % \let\DescribeCounter\DescribeKey
168 % \let\keydescstyle\macrodescstyle
169 % \DescribeCounter{currfiledepth}
170 % This\marginpar{\raggedright New in v0.7 from 2012/05/15} \LaTeX\ counter provides the nesting depth of the current input file.
171 % For the main file name it has a value of 0.
172 % Inside a sub-file of the main file it has a value of 1, while in a sub-file to that file it has a value of 2, etc.
173 % Like all \LaTeX\ counter it can be typeset using \Macro\arabic{currfiledepth} and its numeric value can be accessed
174 % using \Macro\value{currfiledepth}.
175 % \endgroup
176 %
177 % \DescribeMacro{\ifcurrfiledir}{<text>}{<true>}{<false>}
178 % \DescribeMacro{\ifcurrfilebase}{<text>}{<true>}{<false>}
179 % \DescribeMacro{\ifcurrfileext}{<text>}{<true>}{<false>}
180 % \DescribeMacro{\ifcurrfilename}{<text>}{<true>}{<false>}
181 % \DescribeMacro{\ifcurrfilepath}{<text>}{<true>}{<false>}
182 % This\marginpar{\raggedright New in v0.4 from 2011/01/09} if-macros allow the comparison of \meta{text} with the current file directory, base, extension, name and path, respectively.
183 % The \meta{text} is fully expanded and sanitized for the comparison. Example: |\ifcurrfileext{cfg}{I'm in a config file}{No config file!}|
184 %
185 % \DescribeMacro{\ifcurrfile}{<currfile macro or text>}{<text>}{<true>}{<false>}
186 % Compares the given \meta{currfile macro or text} with \meta{text}. Both are taken as file name parts and are fully expanded and sanitized before the comparison.
187 % This general macro is a little slower then the specialised macros above but might be useful to compare different file names/paths where non of the two is the current file.
188 % Note that the all comparisons are done insensitive to the catcodes of the texts, which is what users want. Different comparision macros (|\ifx|, \pkg{ifthenelse}) might not do this.
189 %
190 % \subsection{Package Options}
191 % The package provides the following options:
192 %
193 % The string options \opt{mainext} and \opt{maindir} can be used to provide the extension (without the dot) and directory of the main file.
194 % 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)
195 % or is not located in the current directory. The \opt{mainext} is by default `|tex|' and the \opt{maindir} is the empty
196 % string. See also the related \pkg{realmainfile} option.
197 %
198 % To provide support for the macros defined by the \pkg{fink} package (see section~\ref{sec:fink}) a boolean \opt{fink} option exists.
199 % If the \pkg{fink} package is loaded before \pkg{currfile} this option is automatically enabled to provide
200 % compatibility. The \opt{mainext} and \opt{maindir} options are then automatically set to the values of the identical
201 % options of \pkg{fink}. Note that \pkg{fink} is now officially declared deprecated by its author in favour of
202 % \pkg{currfile}.
203 %
204 % Using the boolean \opt{abspath} option\marginpar{\raggedright New in v0.6 from 2012/05/06}
205 % the support for absolute directories and paths is enabled. This loads the
206 % sub-package \pkg{currfile-abspath}.
207 % This requires the compiler option `|-recorder|' to be used.
208 % See \autoref{sec:abspath} for more details.
209 % This option will also enabled the related option \opt{realmainfile} if it isn't explicitly used.
210 %
211 % If the boolean \opt{realmainfile} option\marginpar{\raggedright New in v0.6 from 2012/05/06}
212 % is enabled the real main file path is determined using the sub-package \pkg{currfile-abspath}.
213 % This option is very useful if the job-name is set to something else then the main file base name, e.g.\ using the
214 % `|-jobname|' compiler option. Note that this option requires the correct file extension being set using \opt{mainext}
215 % (without the dot). If the main file has the default extension `|.tex|' then no extra efford is required. For `|.dtx|' files
216 % |mainext=dtx| must also be used, otherwise the correct file name can't be determined.
217 % This option requires the compiler option `|-recorder|' to be used in order to work correctly.
218 % See \autoref{sec:abspath} for more details.
219 %
220 % Using the boolean \opt{parent} option\marginpar{\raggedright New in v0.7 from 2012/05/15}
221 % additional macros are set for the parent file of the current file.
222 % See \autoref{sec:parent} for more details.
223 %
224 % \section{Absolute paths}\label{sec:abspath}
225 % If\marginpar{\raggedright New in v0.6 from 2012/05/06}
226 % required also the absolute path and directory of the current input file can be provided.
227 % This feature is implemented by the sub-package \pkg{currfile-abspath} which is automatically loaded by the
228 % \opt{abspath} option.
229 % The absolute path information are read from the `|\jobname.fls|' file produced by the `|-recorder|' compiler option
230 % (i.e.\ compile with `|pdflatex -recorder file.tex|').
231 % Without this compiler option a warning is produced and the related macros stay empty.
232 % Note that TeX Live under Linux and Windows is able to read the currently produced `|.fls|' file while with MiKTeX
233 % the file of the last run is still active. The means that the information is not available with MiKTeX in the very
234 % first compiler run and every time the `|.fls|' file is deleted. Also, changes in the file structure are taking
235 % two compiler runs in order to be noticed. With TeX Live the `|.fls|' file and its information is always current.
236 %
237 %
238 % \subsection{Additional \pkg{currfile} macros for absolute dir and path}
239 % Using the \opt{abspath} package option of \pkg{currfile} the following macros with absolute directories and paths are enabled.
240 %
241 % \DescribeMacro{\currfileabsdir}
242 % \DescribeMacro{\currfileabspath}
243 % Hold the absolute directory and path (directory plus filename) of the current input file, respectively.
244 % Both macros will always be empty if the `|.fls|' file is not available.
245 %
246 % \DescribeMacro{\ifcurrfileabsdir}{<text>}{<true>}{<false>}
247 % \DescribeMacro{\ifcurrfileabspath}{<text>}{<true>}{<false>}
248 % These if-macros allow the comparison of \meta{text} with the current absolute file directory and path, respectively.
249 % The \meta{text} is fully expanded and sanitized for the comparison.
250 %
251 % \subsection{Stand-alone usage of \pkg{currfile-abspath}}
252 % The sub-package \pkg{currfile-abspath} can also be used on its own and provides the following lower-level macros:
253 %
254 % \DescribeMacro\getpwd
255 % \DescribeMacro\thepwd
256 % The parent working directory (PWD) is read by \Macro\getpwd from the `|.fls|' file and stored in \Macro\thepwd.
257 % All characters of the directory will have catcode 12 (other) except spaces which still have catcode 10 (space).
258 % If the PWD could not be determined, because there was not `|.fls|' file, then `\Macro\thepwd` will be empty.
259 % Note that \Macro\getmainfile and \Macro\getabspath both also set \Macro\thepwd while reading the `|.fls|' file.
260 %
261 % \DescribeMacro\getmainfile
262 % \DescribeMacro\themainfile
263 % With \Macro\getmainfile the name of the main file is read from the `|.fls|' file and stored in \Macro\themainfile.
264 % All characters of the file name will have catcode 12 (other) except spaces which still have catcode 10 (space).
265 % If the main file name could not be determined, because there was not `|.fls|' file, then `\Macro\themainfile` will be empty.
266 %
267 % Here it is assumed that the first read file with the `|.tex|' extension is the main file. There is currently no user interface for this
268 % sub-package to change this extension (to e.g.\ `|.dtx|'). However, this can be done using the \opt{mainext} option
269 % of the main package \pkg{currfile}.
270 %
271 % \DescribeMacro\getabspath{<file name>}
272 % \DescribeMacro\getabspath{<dir/file name>}
273 % \DescribeMacro\theabspath
274 % \DescribeMacro\theabsdir
275 % With \Macro\getabspath{<file name>} the absolute path of the given file is read from the `|.fls|' file and stored in \Macro\theabspath.
276 % The directory component (path without file name) is stored in \Macro\theabsdir.
277 % The directory always ends in a `|/|' (even under MS Windows), so that a file name can be appended directly.
278 % All characters of both macros will have catcode 12 (other) except spaces which still have catcode 10 (space).
279 % Note that \meta{file name} must include the full extension but can include a directory component (e.g.\ `|subdir/file.tex|').
280 % If a directory component is given it will not be part of \Macro\theabsdir.
281 % For example \Macro\getabspath{'subdir/file.tex'} will return \Macro\theabspath as `|/absolute/path/subdir/file.tex|'
282 % and \Macro\theabsdir as `|/absolute/path/|'. This differs from \Macro\currfileabsdir which will always includes all directory
283 % elements, which is done by appending \Macro\currfiledir after \Macro\theabsdir.
284 %
285 % The given file must be directly accessible by \TeX, i.e.\ from the current directory or using the |TEXMF| tree,
286 % otherwise it the absolute location can not be determined. If the file can't be found in the `|.fls|' file the macros
287 % \Macro\theabspath and \Macro\theabsdir are empty.
288 %
289 % \section{Parent file macros}\label{sec:parent}
290 % If\marginpar{\raggedright New in v0.7 from 2012/05/15}
291 % the \opt{parent} package option is enabled the following macros are provided.
292 % They are no direct |\if...| macros for these but the general \Macro\ifcurrfile macro can be used with them.
293 %
294 % \DescribeMacro{\parentfiledir}
295 % \DescribeMacro{\parentfilebase}
296 % \DescribeMacro{\parentfileext}
297 % \DescribeMacro{\parentfilename}
298 % \DescribeMacro{\parentfilepath}
299 % These macros are analog to the |\currfile...| macros but for the parent file of the current file.
300 % They are all empty for the main file which does not have a parent file.
301 %
302 % \DescribeMacro{\parentfileabsdir}
303 % \DescribeMacro{\parentfileabspath}
304 % These macros are provided if the \opt{abspath} option is used in addition to \opt{parent}.
305 % They are also empty for the main file.
306 %
307 %
308 % \section{Access all parent files}\label{sec:parents}
309 % If\marginpar{\raggedright New in v0.7 from 2012/05/15}
310 % the \opt{parents} package option is enabled the following macros are provided.
311 % Note that this option does not enable the \opt{parent} option.
312 %
313 % \DescribeMacro{\currfilegetparents}
314 % This macro locally defines file name macros for all parent files of the current input file:
315 % The macros are named like the ones of the \opt{parent} option, but also include a trailing
316 % roman number to indicate the parent file level, starting with `i` for the first parent file:
317 %
318 % \begin{DescribeMacrosTab}{llll}
319 % \Macro{\parentfilediri} & \Macro{\parentfiledirii} & $\ldots$ \\
320 % \Macro{\parentfilebasei} & \Macro{\parentfilebaseii} & $\ldots$ \\
321 % \Macro{\parentfileexti} & \Macro{\parentfileextii} & $\ldots$ \\
322 % \Macro{\parentfilenamei} & \Macro{\parentfilenameii} & $\ldots$ \\
323 % \Macro{\parentfilepathi} & \Macro{\parentfilepathii} & $\ldots$ \\
324 % \Macro{\parentfileabsdiri} & \Macro{\parentfileabsdirii} & $\ldots$ \\
325 % \Macro{\parentfileabspathi} & \Macro{\parentfileabspathii} & $\ldots$ \\
326 % \end{DescribeMacrosTab}
327 % Note that these macros are only defined in the current group and not globally like all other file name macros.
328 % The number of the highest parent file is given by the \cnt{currfiledepth} counter.
329 %
330 % For example, if \Macro\currfilegetparents is used in a sub-sub-sub-file the \cnt{currfiledepth} counter is 3
331 % and \Macro\parentfilenameiii is the name of the main document file.
332 %
333 % \section{Usage inside file hooks}
334 % This package uses the `EveryFile' hooks of the \pkg{filehook} package to update its macros.
335 % Special care is taken to do this in a way so that the macros can be used safely inside other hook code, including other `EveryFile' hooks.
336 % Please note that the `AtEndOfPackageFile' and `AtEndOfClassFile' hooks are executed after `AtEndOfEveryFile'
337 % and therefore the |currfile| macros will hold the values of the parent file, not of that package or class file.
338 %
339 % \section{Compatibility with the \texttt{fink} package}\label{sec:fink}
340 % The \pkg{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
341 % options). However, it does not exclude package and other preamble files and does not take care to change the filename \emph{after} the \Macro\clearpage of
342 % \Macro\include. The author of \texttt{fink} is now discontinuing it in favour of this package.
343 % Existing documents which use \pkg{fink} should either rename the related macros as shown by Table~\ref{tab:fink} or use the \pkg{fink} option of \pkg{currfile} which defines
344 % the \pkg{fink} macros to use the \pkg{currfile} ones.
345 %
346 % Because both packages do basically the same thing, especially patch the same macros, there are incompatible and should not be loaded at the same time.
347 % In consent with the \pkg{fink} package author this package will undo most of the \pkg{fink} code if it was already loaded or prevent it from being loaded afterwards.
348 %
349 % \begin{table}
350 % \belowcaptionskip=\abovecaptionskip
351 % \abovecaptionskip=0pt
352 % \caption{Conversion from \texttt{fink} package to \texttt{currfile}.}
353 % \label{tab:fink}
354 % \centering
355 % \begin{tabular}{lll}
356 % \toprule
357 % \texttt{fink} & \texttt{currfile} & Example Result \\
358 % \midrule
359 % \cs{finkdir} & \cs{currfiledir} & \ttfamily\currfiledir \\
360 % \cs{finkbase} & \cs{currfilebase} & \ttfamily\currfilebase \\
361 % \cs{finkext} & \cs{currfileext} & \ttfamily\currfileext \\
362 % \cs{finkfile} & \cs{currfilename} & \ttfamily\currfilename \\
363 % \cs{finkpath} & \cs{currfilepath} & \ttfamily\currfilepath \\
364 % \bottomrule
365 % \end{tabular}
366 % \end{table}
367 %
368 % \StopEventually{}
369 %
370 % \section{Implementation}\label{sec:impl}
371 %
372 % \iffalse
373 %<*currfile.sty>
374 % \fi
375 %
376 % \subsection{Package \pkg{currfile}}
377 %
378 % \subsubsection{Package header}
379 %
380 % \begin{macrocode}
381 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
382 \ProvidesPackage{currfile}[%
383 %<!DATE>
384 %<!VERSION>
385 %<*DRIVER>
386 2099/01/01 develop
387 %</DRIVER>
388 Provides the file path elements of the current input file]
389 % \end{macrocode}
390 %
391 % \subsubsection{Options}
392 %
393 % \begin{macrocode}
394 \RequirePackage{kvoptions}
395 \SetupKeyvalOptions{family=currfile,prefix=currfile@}
396 % \end{macrocode}
397 %
398 % Handle already loaded \pkg{currfile-abspath} package.
399 % \begin{macrocode}
400 \@ifpackageloaded{currfile-abspath}{%
401 \let\currfile@mainext\relax
402 }{}%
403 % \end{macrocode}
404 %
405 % \begin{macrocode}
406 \@ifpackageloaded{fink}{%
407 \DeclareStringOption[\fnk@mainext]{mainext}%
408 \DeclareStringOption[\fnk@maindir]{maindir}%
409 \DeclareBoolOption[true]{fink}%
410 \PackageWarning{currfile}{Deprecated package 'fink' detected. %
411 The 'fink' option will default to 'true'.^^J%
412 If set to 'false' no 'fink' macros will be changed but they will stop
413 working correctly!}%
414 }{%
415 \DeclareStringOption[tex]{mainext}%
416 \DeclareStringOption[\@currdir]{maindir}%
417 \DeclareBoolOption[false]{fink}%
418 }%
419 \DeclareVoidOption{force}{\PassOptionsToPackage{force}{filehook}}
420 \DeclareBoolOption[false]{parent}
421 \DeclareBoolOption[false]{parents}
422 \DeclareBoolOption[false]{realmainfile}%
423 \let\ifcurrfile@realmainfile\relax
424 \DeclareBoolOption[false]{abspath}%
425 \RequirePackage{filehook}[2011/01/09]
426 \ProcessKeyvalOptions*\relax
427
428 \begingroup
429 \xdef\currfile@mainext{\currfile@mainext}%
430 \xdef\currfile@maindir{\currfile@maindir}%
431 \def\@tempa{./}%
432 \ifx\@tempa\currfile@maindir
433 \global\let\currfile@maindir\@empty
434 \fi
435 \endgroup
436
437 % \end{macrocode}
438 % Check if \opt{realmainfile} option was used. If not it is determined
439 % by the \opt{abspath} option.
440 % \begin{macrocode}
441 \expandafter\ifx\csname ifcurrfile@realmainfile\endcsname\relax
442 \ifcurrfile@abspath
443 \currfile@realmainfiletrue
444 \else
445 \currfile@realmainfilefalse
446 \fi
447 \fi
448 % \end{macrocode}
449 %
450 % \begin{macrocode}
451 \begingroup
452 \@tempswafalse
453 \ifcurrfile@abspath
454 \@tempswatrue
455 \else
456 \ifcurrfile@realmainfile
457 \@tempswatrue
458 \fi\fi
459
460 \if@tempswa
461 \endgroup
462 \@ifpackageloaded{currfile-abspath}{%
463 \PackageWarning{currfile}{Sub-package 'currfile-abspath' already loaded beforehand.
464 This might lead to wrong results when non-default options are used.}%
465 }{}%
466 \RequirePackage{currfile-abspath}
467 \else
468 \endgroup
469 \fi
470 % \end{macrocode}
471 %
472 %
473 % \subsubsection{File Hooks}
474 % The \pkg{filehook} package is used to execute the macros at the correct places.
475 % However it must be loaded before the option processed because the |fink| compatibility
476 % code in |filehook-fink| will modify the option list.
477 % The internal interface, not the user-interface, is used to make sure that the file names are valid for all other hooks.
478 %
479 % \begin{macrocode}
480 \filehook@prefixwarg\filehook@every@atbegin{%
481 \currfile@push
482 \currfile@set{#1}%
483 }
484 \filehook@appendwarg\filehook@every@atend{%
485 \currfile@pop
486 }
487 % \end{macrocode}
488 %
489 %
490 % \subsubsection{Set Current Values}
491 %
492 % \begin{macro}{\currfile@set}
493 % Sets the file information which are parsed by \LaTeX's \Macro\filename@parse.
494 % \changes{2011/09/18}{v0.5}{Now supports path elements from \cs{input@path}.}
495 % \changes{2011/09/18}{v0.5}{Now supports multiple dots in the file name.}
496 % \begin{macrocode}
497 \def\currfile@set#1{%
498 \begingroup
499 \currfile@setparent
500 \edef\@filef@und{#1}%
501 \ifx\input@path\@undefined\else
502 \currfile@checkpath
503 \fi
504 \@onelevel@sanitize\@filef@und
505 \let\filename@simple\currfile@parseext
506 \let\filename@base\@gobble
507 \expandafter\filename@parse\expandafter{\@filef@und}%
508 \global\let\currfiledir\filename@area
509 \global\let\currfilebase\filename@base
510 \global\let\currfileext\filename@ext
511 \xdef\currfilename{\currfilebase\ifx\currfileext\@empty\else.\currfileext\fi}%
512 \xdef\currfilepath{\currfiledir\currfilename}%
513 \ifcurrfile@abspath
514 \getabspath\currfilepath
515 \global\let\currfileabspath\theabspath
516 \xdef\currfileabsdir{\theabsdir\currfiledir}%
517 \fi
518 \global\advance\c@currfiledepth by\@ne
519 \endgroup
520 %<debug> \expandafter\gdef\expandafter\dindent\expandafter{\dindent\space}%
521 %<debug> \message{^^JDEBUG: \dindent\empty Entering file '\currfilename' ^^J }%
522 }
523 % \end{macrocode}
524 % \end{macro}
525 %
526 % \begin{macro}{\currfile@parent}
527 % Sets the current file data as parent file data. Must be called directly before
528 % updating the current file data.
529 % \begin{macrocode}
530 \ifcurrfile@parent
531 \ifcurrfile@abspath
532 \def\currfile@setparent{%
533 \global\let\parentfiledir\currfiledir
534 \global\let\parentfilebase\currfilebase
535 \global\let\parentfileext\currfileext
536 \global\let\parentfilename\currfilename
537 \global\let\parentfilepath\currfilepath
538 \global\let\parentfileabspath\currfileabspath
539 \global\let\parentfileabsdir\currfileabsdir
540 }
541 \else
542 \def\currfile@setparent{%
543 \global\let\parentfiledir\currfiledir
544 \global\let\parentfilebase\currfilebase
545 \global\let\parentfileext\currfileext
546 \global\let\parentfilename\currfilename
547 \global\let\parentfilepath\currfilepath
548 }
549 \fi
550 \else
551 \let\currfile@setparent\relax
552 \fi
553 % \end{macrocode}
554 % \end{macro}
555 %
556 %
557 % \begin{macro}{\currfile@openin}[2]{file handle}{file path}
558 % Opens the given file for reading.
559 % \begin{macrocode}
560 \def\currfile@openin#1#2{%
561 \openin#1="#2"\relax
562 }
563 % \end{macrocode}
564 % \end{macro}
565 %
566 %
567 % \begin{macro}{\currfile@checkpath}
568 % This loop is placed in an own macro for efficiency reasons.
569 % In the majority of cases it should not be needed and having it as
570 % a macro avoids the need to skip over this code as part of a conditional clause
571 % for every read file.
572 % \changes{2011/09/18}{v0.5}{New macro as part of the \cs{input@path} support.}
573 % \begin{macrocode}
574 \def\currfile@checkpath{%
575 \currfile@openin{\@inputcheck}{\@filef@und}%
576 \ifeof\@inputcheck
577 \currfile@check@inputpath
578 \fi
579 \closein\@inputcheck
580 }
581 % \end{macrocode}
582 % \end{macro}
583 %
584 %
585 % \begin{macro}{\currfile@check@inputpath}
586 % Check all paths in the \cs{input@path} macro.
587 % \begin{macrocode}
588 \def\currfile@check@inputpath{%
589 \expandafter\@tfor
590 \expandafter\@tempb
591 \expandafter:\expandafter=\input@path\do{%
592 \currfile@openin{\@inputcheck}{\@tempb\@filef@und}%
593 \ifeof\@inputcheck\else
594 \edef\@filef@und{\@tempb\@filef@und}%
595 \@break@tfor
596 \fi
597 }%
598 }
599 % \end{macrocode}
600 % \end{macro}
601 %
602 % \begin{macro}{\currfile@checkpath}
603 % Special version for the \pkg{import} package.
604 % \begin{macrocode}
605 \AtEndOfPackageFile*{import}{%
606 \def\currfile@checkpath{%
607 \ifx\IfFileExists\@iffileonpath
608 \currfile@check@inputpath
609 \else
610 \currfile@openin{\@inputcheck}{\@filef@und}%
611 \ifeof\@inputcheck
612 \currfile@check@inputpath
613 \fi
614 \fi
615 \closein\@inputcheck
616 }%
617 }
618 % \end{macrocode}
619 % \end{macro}
620 %
621 % \begin{macro}{\currfile@parseext}
622 % Replacement for \Macro\filename@simple to allow multiple dots in a filename.
623 % This needs |\let\filename@base\@gobble| before it is called.
624 % \changes{2011/09/18}{v0.5}{New macro as part of the multi-dot support.}
625 % \begin{macrocode}
626 \begingroup
627 \@makeother{.}
628 \gdef\currfile@parseext#1.#2\\{%
629 \ifx\\#2\\%
630 \ifx\filename@base\@gobble
631 \def\filename@base{#1}%
632 \let\filename@ext\currfile@defaultext%
633 \else
634 \def\filename@ext{#1}%
635 \fi
636 \else
637 \edef\filename@base{\filename@base.#1}%
638 \def\@tempa{\currfile@parseext#2\\}%
639 \expandafter\@tempa
640 \fi
641 }
642 \endgroup
643 % \end{macrocode}
644 % \end{macro}
645 %
646 % \begin{macro}{\currfile@defaultext}
647 % Holds the default extension `|tex|' with catcode \emph{other} like \Macro\jobname.
648 % \changes{2011/09/18}{v0.5}{New macro as part of the multi-dot support.}
649 % \begin{macrocode}
650 \def\currfile@defaultext{tex}
651 \@onelevel@sanitize\currfile@defaultext
652 % \end{macrocode}
653 % \end{macro}
654 %
655 % \subsubsection{File Stack}
656 % The file information are pushed and popped on a stack to save and restore them when
657 % entering and leaving a sub-file, respectively. This is quite similar to the way
658 % \LaTeX\ saves file base names and extension as well as the `@' status (letter or other) for
659 % package and class files.
660 %
661 % \begin{macro}{\currfile@push}
662 % \begin{macrocode}
663 \ifcurrfile@abspath
664 \def\currfile@push{%
665 \xdef\currfile@stack{%
666 {\currfiledir}%
667 {\currfilebase}%
668 {\currfileext}%
669 {\currfileabsdir}%
670 \currfile@stack
671 }%
672 }
673 \else
674 \def\currfile@push{%
675 \xdef\currfile@stack{%
676 {\currfiledir}%
677 {\currfilebase}%
678 {\currfileext}%
679 \currfile@stack
680 }%
681 }
682 \fi
683 % \end{macrocode}
684 % \end{macro}
685 %
686 % \begin{macro}{\currfile@pop}
687 % \begin{macrocode}
688 \def\currfile@pop{%
689 %<debug> \message{^^JDEBUG: \dindent\empty Leaving file '\currfilename' ^^J }%
690 \ifcase0%
691 \ifx\currfile@stack\empty 1\else
692 \ifnum\c@currfiledepth<\@ne 1\fi\fi
693 \relax
694 \global\advance\c@currfiledepth by\m@ne
695 \else
696 \global\let\currfile@stack\currfile@stackinit
697 \global\c@currfiledepth=\z@
698 \fi
699 \expandafter\currfile@pop@\currfile@stack\relax
700 \relax\relax\relax\relax\relax\relax\relax
701 %<debug> \message{^^JDEBUG: \dindent\empty Restoring file '\currfilename' ^^J }%
702 }
703 % \end{macrocode}
704 % \end{macro}
705 %
706 % \begin{macro}{\currfile@pop@}
707 % \begin{macrocode}
708 \ifcurrfile@abspath
709 \def\currfile@pop@#1#2#3#4{%
710 \gdef\currfiledir{#1}%
711 \gdef\currfilebase{#2}%
712 \gdef\currfileext{#3}%
713 \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}%
714 \xdef\currfilepath{\currfiledir\currfilename}%
715 \gdef\currfileabsdir{#4}%
716 \xdef\currfileabspath{\ifx\currfileabsdir\@empty\else\currfileabsdir\currfilename\fi}%
717 \currfile@updatestack
718 }
719 \else
720 \def\currfile@pop@#1#2#3{%
721 \gdef\currfiledir{#1}%
722 \gdef\currfilebase{#2}%
723 \gdef\currfileext{#3}%
724 \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}%
725 \xdef\currfilepath{\currfiledir\currfilename}%
726 \currfile@updatestack
727 }
728 \fi
729 % \end{macrocode}
730 % \end{macro}
731 %
732 % \begin{macro}{\currfile@updatestack}
733 % \begin{macrocode}
734 \ifcurrfile@parent
735 \ifcurrfile@abspath
736 \def\currfile@updatestack#1#2#3#4#5\relax{%
737 \gdef\parentfiledir{#1}%
738 \gdef\parentfilebase{#2}%
739 \gdef\parentfileext{#3}%
740 \xdef\parentfilename{\parentfilebase\ifx\parentfileext\empty\else.\parentfileext\fi}%
741 \xdef\parentfilepath{\parentfiledir\parentfilename}%
742 \gdef\parentfileabsdir{#4}%
743 \xdef\parentfileabspath{\ifx\parentfileabsdir\@empty\else\parentfileabsdir\parentfilename\fi}%
744 \gdef\currfile@stack{{#1}{#2}{#3}{#4}#5}%
745 }
746 \else
747 \def\currfile@updatestack#1#2#3#4\relax{%
748 \gdef\parentfiledir{#1}%
749 \gdef\parentfilebase{#2}%
750 \gdef\parentfileext{#3}%
751 \xdef\parentfilename{\parentfilebase\ifx\parentfileext\empty\else.\parentfileext\fi}%
752 \xdef\parentfilepath{\parentfiledir\parentfilename}%
753 \gdef\currfile@stack{{#1}{#2}{#3}#4}%
754 }
755 \fi
756 \else
757 \def\currfile@updatestack#1\relax{%
758 \gdef\currfile@stack{#1}%
759 }
760 \fi
761 % \end{macrocode}
762 % \end{macro}
763 %
764 % \begin{macrocode}
765 \ifcurrfile@parents
766 % \end{macrocode}
767 %
768 % \begin{macro}{\currfilegetparents}
769 % \begin{macrocode}
770 \newcommand*\currfilegetparents{%
771 \@tempcnta\@ne
772 \expandafter\currfile@getparents\currfile@stack\relax
773 \relax\relax\relax\relax\relax\relax\relax
774 }
775 \ifcurrfile@abspath
776 \def\currfile@getparents#1#2#3#4{%
777 \@namedef{parentfiledir\romannumeral\@tempcnta}{#1}%
778 \@namedef{parentfilebase\romannumeral\@tempcnta}{#2}%
779 \@namedef{parentfileext\romannumeral\@tempcnta}{#3}%
780 \expandafter\edef\csname parentfilename\romannumeral\@tempcnta\endcsname{#2\ifx\empty#3\empty\else.#3\fi}%
781 \expandafter\edef\csname parentfilepath\romannumeral\@tempcnta\endcsname{#1\csname parentfilename\romannumeral\@tempcnta\endcsname}%
782 \@namedef{parentfileabsdir\romannumeral\@tempcnta}{#4}%
783 \expandafter\edef\csname parentfileabspath\romannumeral\@tempcnta\endcsname{%
784 \expandafter\ifx\csname parentfileabsdir\romannumeral\@tempcnta\endcsname\@empty\else
785 \csname parentfileabsdir\romannumeral\@tempcnta\endcsname
786 \csname parentfilename\romannumeral\@tempcnta\endcsname
787 \fi
788 }%
789 \ifnum\@tempcnta<\c@currfiledepth
790 \advance\@tempcnta\@ne
791 \expandafter\currfile@getparents
792 \fi
793 }
794 \else
795 \def\currfile@getparents#1#2#3{%
796 \@namedef{parentfiledir\romannumeral\@tempcnta}{#1}%
797 \@namedef{parentfilebase\romannumeral\@tempcnta}{#2}%
798 \@namedef{parentfileext\romannumeral\@tempcnta}{#3}%
799 \expandafter\edef\csname parentfilename\romannumeral\@tempcnta\endcsname{#2\ifx\empty#3\empty\else.#3\fi}%
800 \expandafter\edef\csname parentfilepath\romannumeral\@tempcnta\endcsname{#1\csname parentfilename\romannumeral\@tempcnta\endcsname}%
801 \ifnum\@tempcnta<\c@currfiledepth
802 \advance\@tempcnta\@ne
803 \expandafter\currfile@getparents
804 \fi
805 }
806 \fi
807 % \end{macrocode}
808 % \end{macro}
809 %
810 % \begin{macro}{\parentfile}[2]{file path part}{number}
811 % Expands to the \Macro\parentfile<part><roman number> macro.
812 % \begin{macrocode}
813 \newcommand\parentfile[2]{%
814 \csname parentfile#1\romannumeral#2\endcsname
815 }
816 % \end{macrocode}
817 % \end{macro}
818 %
819 % \begin{macrocode}
820 \fi
821 % \end{macrocode}
822 %
823 % \iffalse
824 %<debug> \def\dindent{}
825 % \fi
826 %
827 % \begin{macro}{\currfile@stack}
828 % \begin{macro}{\currfile@stackinit}
829 % Initialise the stack with empty values and set the main file values.
830 % \begin{macrocode}
831 \let\currfile@stack\@empty
832 \let\currfiledir\@empty
833 \let\currfilebase\@empty
834 \let\currfileext\@empty
835 \let\currfilename\@empty
836 \let\currfilepath\@empty
837 \let\currfileabspath\@empty
838 \let\currfileabsdir\@empty
839 \newcounter{currfiledepth}
840 \global\c@currfiledepth\m@ne
841 \ifcurrfile@realmainfile
842 \getmainfile
843 \ifx\themainfile\@empty
844 \currfile@set{\currfile@maindir\jobname.\currfile@mainext}
845 \else
846 \currfile@set{\themainfile}
847 \fi
848 \else
849 \currfile@set{\currfile@maindir\jobname.\currfile@mainext}
850 \fi
851 \currfile@push
852 \let\currfile@stackinit\currfile@stack
853 % \end{macrocode}
854 % \end{macro}
855 % \end{macro}
856 %
857 % Disable the change of the \opt{abspath} option at this point
858 % in order to freeze the stack format.
859 % \begin{macrocode}
860 \let\currfile@abspathfalse\relax
861 \let\currfile@abspathtrue\relax
862 % \end{macrocode}
863 %
864 % \subsubsection{If Macros}
865 % \begin{macro}{\ifcurrfilename}
866 % \begin{macrocode}
867 \newcommand*\ifcurrfilename{\begingroup\currfile@if\currfilename}
868 % \end{macrocode}
869 % \end{macro}
870 %
871 % \begin{macro}{\ifcurrfilebase}
872 % \begin{macrocode}
873 \newcommand*\ifcurrfilebase{\begingroup\currfile@if\currfilebase}
874 % \end{macrocode}
875 % \end{macro}
876 %
877 % \begin{macro}{\ifcurrfileext}
878 % \begin{macrocode}
879 \newcommand*\ifcurrfileext{\begingroup\currfile@if\currfileext}
880 % \end{macrocode}
881 % \end{macro}
882 %
883 % \begin{macro}{\ifcurrfiledir}
884 % \begin{macrocode}
885 \newcommand*\ifcurrfiledir{\begingroup\currfile@if\currfiledir}
886 % \end{macrocode}
887 % \end{macro}
888 %
889 % \begin{macro}{\ifcurrfilepath}
890 % \begin{macrocode}
891 \newcommand*\ifcurrfilepath{\begingroup\currfile@if\currfilepath}
892 % \end{macrocode}
893 % \end{macro}
894 %
895 % \begin{macrocode}
896 \ifcurrfile@abspath
897 % \end{macrocode}
898 %
899 % \begin{macro}{\ifcurrfileabspath}
900 % \begin{macrocode}
901 \newcommand*\ifcurrfileabspath{\begingroup\currfile@if\currfileabspath}
902 % \end{macrocode}
903 % \end{macro}
904 %
905 % \begin{macro}{\ifcurrfileabsdir}
906 % \begin{macrocode}
907 \newcommand*\ifcurrfileabsdir{\begingroup\currfile@if\currfileabsdir}
908 % \end{macrocode}
909 % \end{macro}
910 %
911 % \begin{macrocode}
912 \fi
913 % \end{macrocode}
914 %
915 % \begin{macro}{\ifcurrfile}[1]{currfile macro or text}
916 % Expands and sanitizes the first argument and then calls the internal if-macro
917 % with the result.
918 % \begin{macrocode}
919 \newcommand*\ifcurrfile[1]{%
920 \begingroup
921 \edef\@tempb{#1}%
922 \@onelevel@sanitize\@tempb
923 \currfile@if\@tempb
924 }
925 % \end{macrocode}
926 % \end{macro}
927 %
928 % \begin{macro}{\currfile@if}[2]{currfile macro to compare}{compare text}
929 % Expands the text and sanitize it to ensure correct neutral catcodes.
930 % Then it temp macro is compared to the given currfile macro.
931 % \begin{macrocode}
932 \def\currfile@if#1#2{%
933 \edef\@tempa{#2}%
934 \@onelevel@sanitize\@tempa
935 \ifx\@tempa#1%
936 \endgroup
937 \expandafter\@firstoftwo
938 \else
939 \endgroup
940 \expandafter\@secondoftwo
941 \fi
942 }
943 % \end{macrocode}
944 % \end{macro}
945 %
946 %
947 % \subsubsection{Fink Macros}
948 %
949 % The \pkg{fink} option defines all \pkg{fink} package macros to use the ones provided
950 % by this package. If the \pkg{fink} package was loaded beforehand the restoration
951 % of these macros must be avoided at the end of this file
952 % (\pkg{fink}s \Macro\InputIfFileExists was then used to load this package).
953 % If the package was not loaded its version is set to a dummy value and its
954 % options to this package options. If \pkg{fink} is attempted to be loaded later
955 % it will trigger an package option clash if different option are used.
956 % Otherwise it will be taken as already loaded and not loaded ``again''.
957 %
958 % \begin{macrocode}
959 \ifcurrfile@fink
960 \def\finkfile{\currfilename}%
961 \def\finkdir{\currfiledir}%
962 \def\finkpath{\currfilepath}%
963 \def\finkbase{\currfilebase}%
964 \def\finkext{\currfileext}%
965 \@ifpackageloaded{fink}{%
966 \def\fink@restore#1{}%
967 }{%
968 \@namedef{[email protected]}{2011/01/09}%
969 \expandafter\edef\csname [email protected]\endcsname{%
970 maindir=\currfile@maindir,mainext=\currfile@mainext
971 }%
972 }%
973 \else
974 \@ifpackageloaded{fink}{}{%
975 \AtBeginOfPackageFile{fink}{%
976 \PackageError{currfile}{The 'fink' package is now deprecated. %
977 Load 'currfile' with the 'fink' option or see the upgrade guide in the manual}{}%
978 }%
979 }%
980 \fi
981 % \end{macrocode}
982 %
983 % \iffalse
984 %</currfile.sty>
985 % \fi
986 %
987 % \iffalse
988 %<*currfile-abspath.sty>
989 % \fi
990 % \subsection{Sub-package \pkg{currfile-abspath}}
991 %
992 % \subsubsection{Package header}
993 %
994 % \begin{macrocode}
995 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
996 \ProvidesPackage{currfile-abspath}[%
997 %<!DATE>
998 %<!VERSION>
999 %<*DRIVER>
1000 2099/01/01 develop
1001 %</DRIVER>
1002 Provides absolute file paths, the parent working directory and the main file name]
1003 % \end{macrocode}
1004 %
1005 %
1006 % \subsubsection{Preliminary Code}
1007 %
1008 % Declare and init macros
1009 % \begin{macrocode}
1010 \newcommand*\thepwd{}
1011 \newcommand*\theabspath{}
1012 \newcommand*\theabsdir{}
1013 \newcommand*\themainfile{}
1014 % \end{macrocode}
1015 % Long, empty:
1016 % \begin{macrocode}
1017 \newif\ifcurrfile@abspath@windows
1018 % \end{macrocode}
1019 %
1020 % Ensure that the main file extension is defined and not empty.
1021 % \begin{macrocode}
1022 \providecommand\currfile@mainext{tex}
1023 \ifx\currfile@mainext\@empty
1024 \PackageError{currfile-abspath}
1025 {Empty main file extension is not supported}{}%
1026 \fi
1027 % \end{macrocode}
1028 %
1029 % \iffalse
1030 %\edef\themainfile{\jobname.\currfile@mainext}
1031 %\@onelevel@sanitize\themainfile
1032 % \fi
1033 %
1034 %
1035 % \begin{macro}{\currfile@abspath@noflswarning}
1036 %
1037 % \begin{macrocode}
1038 \def\currfile@abspath@noflswarning{%
1039 \PackageWarning{currfile-abspath}
1040 {The required recorder file (.fls) was not found.\MessageBreak
1041 Please compile with the '-recorder' option.\MessageBreak
1042 Note that MikTeX requires two compiler runs.\MessageBreak
1043 Occurred}%
1044 \global\let\currfile@abspath@noflswarning\relax
1045 \global\csname currfile@abspathfalse\endcsname
1046 }%
1047 % \end{macrocode}
1048 % \end{macro}
1049 %
1050 %
1051 % \subsubsection{Parent Working Directory (PWD)}
1052 % Opens the |\jobname.fls| file and checks for the `|PWD|' line (should be the very first one).
1053 % \begin{macro}{\getpwd}
1054 % \begin{macrocode}
1055 \newcommand\getpwd{%
1056 \begingroup
1057 \let\thepwd\@empty
1058 \IfFileExists{\jobname.fls}{%
1059 \openin\@inputcheck=\jobname.fls\relax
1060 \endlinechar\m@ne
1061 \loop
1062 \readline\@inputcheck to \line
1063 \@onelevel@sanitize\line
1064 \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax
1065 \ifeof\@inputcheck\else
1066 \repeat
1067 \closein\@inputcheck
1068 }
1069 \currfile@abspath@noflswarning
1070 \edef\@tempa{%
1071 \def\noexpand\thepwd{\thepwd}%
1072 }%
1073 \expandafter
1074 \endgroup
1075 \@tempa
1076 }
1077 % \end{macrocode}
1078 % \end{macro}
1079 %
1080 %
1081 % \begin{macro}{\currfile@checkpwd}
1082 % Checks if the read line starts with `|PWD|' and stores the rest
1083 % of the line in \Macro\thepwd. The space after `|PWD|' is skipped by
1084 % \TeX\ when looking for |#4|.
1085 % \begin{macrocode}
1086 \def\currfile@checkpwd#1#2#3#4#5\relax{%
1087 \edef\@tempa{#1#2#3}%
1088 \edef\@tempb{PWD}%
1089 \@onelevel@sanitize\@tempb
1090 \ifx\@tempa\@tempb
1091 \edef\thepwd{#4#5/}%
1092 \def\@tempa{#4}%
1093 \def\@tempb{/}%
1094 \ifx\@tempa\@tempb
1095 \currfile@abspath@windowsfalse
1096 \else
1097 \currfile@abspath@windowstrue
1098 \fi
1099 \let\iterate\relax
1100 \fi
1101 }
1102 % \end{macrocode}
1103 % \end{macro}
1104 %
1105 %
1106 % \subsubsection{Absolute Path}
1107 %
1108 % \begin{macro}{\getabspath}
1109 % Opens the |\jobname.fls| file and checks for the first `|INPUT|' line
1110 % which lists the given filename.
1111 % \begin{macrocode}
1112 \newcommand\getabspath[1]{%
1113 \begingroup
1114 \edef\filename{#1}%
1115 \@onelevel@sanitize\filename%
1116 \let\theabspath\@empty
1117 \let\theabsdir\@empty
1118 \IfFileExists{\filename}{%
1119 \IfFileExists{\jobname.fls}{%
1120 \openin\@inputcheck=\jobname.fls\relax
1121 \endlinechar\m@ne
1122 \expandafter\currfile@abspath@defs\expandafter{\filename}%
1123 \readline\@inputcheck to \line
1124 \@onelevel@sanitize\line
1125 \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax
1126 \loop
1127 \readline\@inputcheck to \line
1128 \@onelevel@sanitize\line
1129 \expandafter\currfile@abspath@getabspath\expandafter{\line}%
1130 \ifeof\@inputcheck\else
1131 \repeat
1132 \closein\@inputcheck
1133 }\currfile@abspath@noflswarning
1134 }{}%
1135 \edef\@tempa{%
1136 \def\noexpand\theabspath{\theabspath}%
1137 \def\noexpand\theabsdir{\theabsdir}%
1138 \def\noexpand\thepwd{\thepwd}%
1139 }%
1140 \expandafter
1141 \endgroup
1142 \@tempa
1143 }
1144 % \end{macrocode}
1145 % \end{macro}
1146 %
1147 %
1148 % \begin{macro}{\getmainfile}
1149 % Opens the |\jobname.fls| file and checks for the first `|INPUT|' line
1150 % which lists a file with the main file extension (usually `|.tex|').
1151 % \begin{macrocode}
1152 \newcommand\getmainfile{%
1153 \begingroup
1154 \let\themainfile\@empty
1155 \IfFileExists{\jobname.fls}{%
1156 \openin\@inputcheck=\jobname.fls\relax
1157 \endlinechar\m@ne
1158 \readline\@inputcheck to \line
1159 \@onelevel@sanitize\line
1160 \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax
1161 \loop
1162 \readline\@inputcheck to \line
1163 \@onelevel@sanitize\line
1164 \expandafter\currfile@abspath@getmainfile\expandafter{\line}%
1165 \ifeof\@inputcheck\else
1166 \repeat
1167 \closein\@inputcheck
1168 }%
1169 \currfile@abspath@noflswarning
1170 \edef\@tempa{%
1171 \def\noexpand\themainfile{\themainfile}%
1172 \def\noexpand\thepwd{\thepwd}%
1173 }%
1174 \expandafter
1175 \endgroup
1176 \@tempa
1177 }
1178 % \end{macrocode}
1179 % \end{macro}
1180 %
1181 %
1182 % \subsubsection{Line scanning macros for abspath and mainfile}
1183 %
1184 %
1185 % \begin{macro}{\currfile@abspath@testfname}
1186 % Test if directory is empty because the file is only listed by name, i.e. is in the PWD
1187 % or because the searched path was an absolute one and no further path elements are therefore listed
1188 % In the first case set \Macro\theabsdir to \Macro\thepwd, in the second case keep it empty.
1189 % \begin{macrocode}
1190 \def\currfile@abspath@testfname#1#2#3\relax{%
1191 \ifcurrfile@abspath@windows
1192 \def\@tempa{#2}%
1193 \def\@tempb{:}%
1194 \else
1195 \def\@tempa{#1}%
1196 \def\@tempb{/}%
1197 \fi
1198 \ifx\@tempa\@tempb\else
1199 \let\theabsdir\thepwd
1200 \fi
1201 }
1202 % \end{macrocode}
1203 % \end{macro}
1204 %
1205 % Change catcodes for `|INPUT|' to 12 (\emph{other}), because we need
1206 % them this way in the parameter lists of the following macros.
1207 % \begin{macrocode}
1208 \begingroup
1209 \catcode`I=12
1210 \catcode`N=12
1211 \catcode`P=12
1212 \catcode`U=12
1213 \catcode`T=12
1214 % \end{macrocode}
1215 %
1216 % \begin{macro}{\currfile@abspath@defs}
1217 % Dynamically defines the macros needed to find the line with the requested file name.
1218 % \begin{macrocode}
1219 \gdef\currfile@abspath@defs#1{%
1220 \def\currfile@abspath@checkabspath ##1INPUT ##2#1\relax##3\relax##4\@nnil{%
1221 \ifx\@empty##4\@empty\else
1222 \def\theabsdir{##2}%
1223 \ifx\theabsdir\@empty
1224 \currfile@abspath@testfname#1\@empty\@empty\relax
1225 \fi
1226 \edef\theabspath{\theabsdir#1}%
1227 \let\iterate\relax
1228 \fi
1229 }%
1230 \def\currfile@abspath@getabspath##1{%
1231 \currfile@abspath@checkabspath##1\relax INPUT \@empty#1\relax{}\relax\@nnil
1232 }%
1233 }
1234 % \end{macrocode}
1235 % \end{macro}
1236 %
1237 %
1238 % \begin{macro}{\currfile@abspath@checkmainfile}
1239 % \begin{macro}{\currfile@abspath@getmainfile}
1240 % These two macros are defined with the main file extension given by
1241 % \Macro\currfile@mainext in their parameter texts. To insert the extension
1242 % with the correct catcode 12 two temporary auxiliary macros are utilized.
1243 % The |get| macro places the line content before the |check| macro with a suitable
1244 % fallback code so that the search text is always found and no \TeX\ error is raised.
1245 % The |check| macro tests if the fallback has occurred and stores the read path
1246 % if this was not the case.
1247 % \begin{macrocode}
1248 \def\@tempa#1{%
1249 \gdef\currfile@abspath@checkmainfile ##1INPUT ##2#1\relax##3\relax##4\@nnil{%
1250 \ifx\@empty##4\@empty\else
1251 \def\themainfile{##2#1}%
1252 \let\iterate\relax
1253 \fi
1254 }%
1255 \gdef\currfile@abspath@getmainfile##1{%
1256 \currfile@abspath@checkmainfile##1\relax INPUT \@empty#1\relax{}\relax\@nnil
1257 }%
1258 }
1259 \edef\@tempb{.\currfile@mainext}
1260 \@onelevel@sanitize\@tempb
1261 \expandafter\@tempa\expandafter{\@tempb}
1262 % \end{macrocode}
1263 % \end{macro}
1264 % \end{macro}
1265 %
1266 % Ends catcode changes:
1267 % \begin{macrocode}
1268 \endgroup
1269 % \end{macrocode}
1270 %
1271 % \iffalse
1272 %</currfile-abspath.sty>
1273 % \fi
1274 %
1275 % \iffalse
1276 % \fi
1277 %
1278 % \Finale
1279 \endinput