diff options
-rw-r--r-- | Master/texmf-dist/doc/latex/currfile/currfile.pdf | bin | 180357 -> 162131 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/currfile/currfile.dtx | 519 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/currfile/currfile.ins | 1 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/currfile/currfile-abspath.sty | 171 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/currfile/currfile.sty | 73 |
5 files changed, 742 insertions, 22 deletions
diff --git a/Master/texmf-dist/doc/latex/currfile/currfile.pdf b/Master/texmf-dist/doc/latex/currfile/currfile.pdf Binary files differindex 600f388ebab..8bc8e82c5a4 100644 --- a/Master/texmf-dist/doc/latex/currfile/currfile.pdf +++ b/Master/texmf-dist/doc/latex/currfile/currfile.pdf diff --git a/Master/texmf-dist/source/latex/currfile/currfile.dtx b/Master/texmf-dist/source/latex/currfile/currfile.dtx index 621d391b17f..5d12b323912 100644 --- a/Master/texmf-dist/source/latex/currfile/currfile.dtx +++ b/Master/texmf-dist/source/latex/currfile/currfile.dtx @@ -29,10 +29,10 @@ \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesFile{currfile.dtx}[% %<=*DATE> - 2011/09/18 + 2012/05/06 %<=/DATE> %<=*VERSION> - v0.5 + v0.6 %<=/VERSION> DTX file for currfile package] @@ -44,6 +44,11 @@ \EnableCrossrefs \CodelineIndex \RecordChanges +\let\IncludeImplementation\relax +%\let\IncludeImplementation\empty %^^A Enable implementation +\ifx\IncludeImplementation\relax + \OnlyDescription +\fi \begin{document} \DocInput{currfile.dtx} \PrintChanges @@ -52,7 +57,7 @@ %</driver> % \fi % -% \CheckSum{341} +% \CheckSum{814} % % \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 @@ -90,11 +95,13 @@ % % \author{Martin Scharrer} % \email{martin@scharrer-online.de} +% \repository{https://bitbucket.org/martin_scharrer/currfile/} % \maketitle % % \begin{abstract} % This small package provides the file name and path information of the current input file as \LaTeX{} macros. -% It properly supports file name with multiple dots and the \cs{input@path} feature used by some packages like \pkg{import}. +% It properly supports file names with multiple dots and the \cs{input@path} feature used by some packages like \pkg{import}. +% Optionally also the absolute location of current input file can be provided if a special compiler option is enabled. % \end{abstract} % % \section{Usage} @@ -109,6 +116,7 @@ % text and not further macros. They are also ``sanitized'' to ensure that all characters, especially special ones like `|_|', are taken verbatim. % However this special characters might not be displayed correctly in all fonts. A good font is text-type (\Macro\ttfamily, \Macro\texttt{\ldots}), % but other fonts can be used using the \pkg{url} package, e.g.: |\urlstyle{rm}\expandafter\nolinkurl\expandafter{\currfilename}|. +% Note that the directory separator is always `|/|' even under MS Windows. % % 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 % will hold the correct data. @@ -119,7 +127,8 @@ % % This package uses the \pkg{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. +% If required more detailed information can be found in the implementation section \ifx\IncludeImplementation\relax(compile this manual with \Macro\AlsoImplementation)\else +% \unskip~\ref{sec:impl}\fi. % % \DescribeMacro{\ifcurrfiledir}{<text>}{<true>}{<false>} % \DescribeMacro{\ifcurrfilebase}{<text>}{<true>}{<false>} @@ -134,10 +143,102 @@ % 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. % 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. % -% \subsection*{Package Options} -% The package provides two options \opt{mainext} and \opt{maindir} which can be used to provide the extension and directory of the main file. +% \subsection{Package Options} +% The package provides the following options: +% +% The string options \opt{mainext} and \opt{maindir} can be used to provide the extension (without the dot) 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 \pkg{fink} package (see section~\ref{sec:fink}) a \pkg{fink} option exists. +% or is not located in the current directory. The \opt{mainext} is by default `|tex|' and the \opt{maindir} is the empty +% string. See also the related \pkg{realmainfile} option. +% +% To provide support for the macros defined by the \pkg{fink} package (see section~\ref{sec:fink}) a boolean \opt{fink} option exists. +% If the \pkg{fink} package is loaded before \pkg{currfile} this option is automatically enabled to provide +% compatibility. The \opt{mainext} and \opt{maindir} options are then automatically set to the values of the identical +% options of \pkg{fink}. Note that \pkg{fink} is now officially declared deprecated by its author in favour of +% \pkg{currfile}. +% +% Using the boolean \opt{abspath} option\marginpar{\raggedright New in v0.6 from 2012/05/06} +% the support for absolute directories and paths is enabled. This loads the +% sub-package \pkg{currfile-abspath}. +% This requires the compiler option `|-recorder|' to be used. +% See \autoref{sec:abspath} for more details. +% This option will also enabled the related option \opt{realmainfile} if it isn't explicitly used. +% +% If the boolean \opt{realmainfile} option\marginpar{\raggedright New in v0.6 from 2012/05/06} +% is enabled the real main file path is determined using the sub-package \pkg{currfile-abspath}. +% This option is very useful if the job-name is set to something else then the main file base name, e.g.\ using the +% `|-jobname|' compiler option. Note that this option requires the correct file extension being set using \opt{mainext} +% (without the dot). If the main file has the default extension `|.tex|' then no extra efford is required. For `|.dtx|' files +% |mainext=dtx| must also be used, otherwise the correct file name can't be determined. +% This option requires the compiler option `|-recorder|' to be used in order to work correctly. +% See \autoref{sec:abspath} for more details. +% +% +% \section{Absolute paths}\label{sec:abspath} +% If\marginpar{\raggedright New in v0.6 from 2012/05/06} +% required also the absolute path and directory of the current input file can be provided. +% This feature is implemented by the sub-package \pkg{currfile-abspath} which is automatically loaded by the +% \opt{abspath} option. +% The absolute path information are read from the `|\jobname.fls|' file produced by the `|-recorder|' compiler option +% (i.e.\ compile with `|pdflatex -recorder file.tex|'). +% Without this compiler option a warning is produced and the related macros stay empty. +% Note that TeX Live under Linux and Windows is able to read the currently produced `|.fls|' file while with MiKTeX +% the file of the last run is still active. The means that the information is not available with MiKTeX in the very +% first compiler run and every time the `|.fls|' file is deleted. Also, changes in the file structure are taking +% two compiler runs in order to be noticed. With TeX Live the `|.fls|' file and its information is always current. +% +% +% \subsection{Additional \pkg{currfile} macros for absolute dir and path} +% Using the \opt{abspath} package option of \pkg{currfile} the following macros with absolute directories and paths are enabled. +% +% \DescribeMacro{\currfileabsdir} +% \DescribeMacro{\currfileabspath} +% Hold the absolute directory and path (directory plus filename) of the current input file, respectively. +% Both macros will always be empty if the `|.fls|' file is not available. +% +% \DescribeMacro{\ifcurrfileabsdir}{<text>}{<true>}{<false>} +% \DescribeMacro{\ifcurrfileabspath}{<text>}{<true>}{<false>} +% These if-macros allow the comparison of \meta{text} with the current absolute file directory and path, respectively. +% The \meta{text} is fully expanded and sanitized for the comparison. +% +% \subsection{Stand-alone usage of \pkg{currfile-abspath}} +% The sub-package \pkg{currfile-abspath} can also be used on its own and provides the following lower-level macros: +% +% \DescribeMacro\getpwd +% \DescribeMacro\thepwd +% The parent working directory (PWD) is read by \Macro\getpwd from the `|.fls|' file and stored in \Macro\thepwd. +% All characters of the directory will have catcode 12 (other) except spaces which still have catcode 10 (space). +% If the PWD could not be determined, because there was not `|.fls|' file, then `\Macro\thepwd` will be empty. +% Note that \Macro\getmainfile and \Macro\getabspath both also set \Macro\thepwd while reading the `|.fls|' file. +% +% \DescribeMacro\getmainfile +% \DescribeMacro\themainfile +% With \Macro\getmainfile the name of the main file is read from the `|.fls|' file and stored in \Macro\themainfile. +% All characters of the file name will have catcode 12 (other) except spaces which still have catcode 10 (space). +% If the main file name could not be determined, because there was not `|.fls|' file, then `\Macro\themainfile` will be empty. +% +% 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 +% sub-package to change this extension (to e.g.\ `|.dtx|'). However, this can be done using the \opt{mainext} option +% of the main package \pkg{currfile}. +% +% \DescribeMacro\getabspath{<file name>} +% \DescribeMacro\getabspath{<dir/file name>} +% \DescribeMacro\theabspath +% \DescribeMacro\theabsdir +% With \Macro\getabspath{<file name>} the absolute path of the given file is read from the `|.fls|' file and stored in \Macro\theabspath. +% The directory component (path without file name) is stored in \Macro\theabsdir. +% The directory always ends in a `|/|' (even under MS Windows), so that a file name can be appended directly. +% All characters of both macros will have catcode 12 (other) except spaces which still have catcode 10 (space). +% Note that \meta{file name} must include the full extension but can include a directory component (e.g.\ `|subdir/file.tex|'). +% If a directory component is given it will not be part of \Macro\theabsdir. +% For example \Macro\getabspath{'subdir/file.tex'} will return \Macro\theabspath as `|/absolute/path/subdir/file.tex|' +% and \Macro\theabsdir as `|/absolute/path/|'. This differs from \Macro\currfileabsdir which will always includes all directory +% elements, which is done by appending \Macro\currfiledir after \Macro\theabsdir. +% +% The given file must be directly accessible by \TeX, i.e.\ from the current directory or using the |TEXMF| tree, +% otherwise it the absolute location can not be determined. If the file can't be found in the `|.fls|' file the macros +% \Macro\theabspath and \Macro\theabsdir are empty. +% % % \section{Usage inside file hooks} % This package uses the `EveryFile' hooks of the \pkg{filehook} package to update its macros. @@ -182,7 +283,9 @@ %<*currfile.sty> % \fi % -% \subsection{Package header} +% \subsection{Package \pkg{currfile}} +% +% \subsubsection{Package header} % % \begin{macrocode} \NeedsTeXFormat{LaTeX2e}[1999/12/01] @@ -195,7 +298,7 @@ ydoc package to describe macros, environments, options etc.] % \end{macrocode} % -% \subsection{Options} +% \subsubsection{Options} % % \begin{macrocode} \RequirePackage{kvoptions} @@ -215,6 +318,9 @@ \DeclareBoolOption[false]{fink}% }% \DeclareVoidOption{force}{\PassOptionsToPackage{force}{filehook}} +\DeclareBoolOption[false]{realmainfile}% +\let\ifcurrfile@realmainfile\relax +\DeclareBoolOption[false]{abspath}% \RequirePackage{filehook}[2011/01/09] \ProcessKeyvalOptions*\relax @@ -223,13 +329,34 @@ \xdef\currfile@maindir{\currfile@maindir}% \def\@tempa{./}% \ifx\@tempa\currfile@maindir - \global\let\currfile@maindir\empty + \global\let\currfile@maindir\@empty \fi \endgroup + +% \end{macrocode} +% Check if \opt{realmainfile} option was used. If not it is determined +% by the \opt{abspath} option. +% \begin{macrocode} +\expandafter\ifx\csname ifcurrfile@realmainfile\endcsname\relax + \ifcurrfile@abspath + \currfile@realmainfiletrue + \else + \currfile@realmainfilefalse + \fi +\fi + +\let\currfileabspath\@empty +\let\currfileabsdir\@empty +\ifcurrfile@abspath + \RequirePackage{currfile-abspath} +\else +\ifcurrfile@realmainfile + \RequirePackage{currfile-abspath} +\fi\fi % \end{macrocode} % % -% \subsection{File Hooks} +% \subsubsection{File Hooks} % The \pkg{filehook} package is used to execute the macros at the correct places. % However it must be loaded before the option processed because the |fink| compatibility % code in |filehook-fink| will modify the option list. @@ -246,7 +373,7 @@ % \end{macrocode} % % -% \subsection{Set Current Values} +% \subsubsection{Set Current Values} % % \begin{macro}{\currfile@set} % Sets the file information which are parsed by \LaTeX's \Macro\filename@parse. @@ -268,6 +395,11 @@ \global\let\currfileext\filename@ext \xdef\currfilename{\currfilebase\ifx\currfileext\@empty\else.\currfileext\fi}% \xdef\currfilepath{\currfiledir\currfilename}% + \ifcurrfile@abspath + \getabspath\currfilepath + \global\let\currfileabspath\theabspath + \xdef\currfileabsdir{\theabsdir\currfiledir}% + \fi \endgroup %<debug> \expandafter\gdef\expandafter\dindent\expandafter{\dindent\space}% %<debug> \message{^^JDEBUG: \dindent\empty Entering file '\currfilename' ^^J }% @@ -336,7 +468,7 @@ % \end{macrocode} % \end{macro} % -% \subsection{File Stack} +% \subsubsection{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 @@ -344,6 +476,17 @@ % % \begin{macro}{\currfile@push} % \begin{macrocode} +\ifcurrfile@abspath +\def\currfile@push{% + \xdef\currfile@stack{% + {\currfiledir}% + {\currfilebase}% + {\currfileext}% + {\currfileabsdir}% + \currfile@stack + }% +} +\else \def\currfile@push{% \xdef\currfile@stack{% {\currfiledir}% @@ -352,6 +495,7 @@ \currfile@stack }% } +\fi % \end{macrocode} % \end{macro} % @@ -372,6 +516,21 @@ % % \begin{macro}{\currfile@pop@} % \begin{macrocode} +\ifcurrfile@abspath +\def\currfile@pop@#1#2#3#4#5\relax{% + \gdef\currfiledir{#1}% + \gdef\currfilebase{#2}% + \gdef\currfileext{#3}% + \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}% + \xdef\currfilepath{\currfiledir\currfilename}% + \gdef\currfileabsdir{#4}% + \xdef\currfileabspath{\ifx\currfileabsdir\@empty\else\currfileabsdir\currfilename\fi}% + \gdef\currfile@stack{#5}% +%<debug> \expandafter\expandafter\expandafter\gdef +%<debug> \expandafter\expandafter\expandafter\dindent +%<debug> \expandafter\expandafter\expandafter{\expandafter\@gobble\dindent}% +} +\else \def\currfile@pop@#1#2#3#4\relax{% \gdef\currfiledir{#1}% \gdef\currfilebase{#2}% @@ -383,6 +542,7 @@ %<debug> \expandafter\expandafter\expandafter\dindent %<debug> \expandafter\expandafter\expandafter{\expandafter\@gobble\dindent}% } +\fi % \end{macrocode} % \end{macro} % @@ -392,18 +552,33 @@ % % \begin{macro}{\currfile@stack} % \begin{macro}{\currfile@stackinit} -% Place \Macro\jobname values on stack and use this as init value. +% Place the main file values on stack and use this as init value. % \begin{macrocode} \def\currfile@stack{} -\currfile@set{\currfile@maindir\jobname.\currfile@mainext} +\ifcurrfile@realmainfile + \getmainfile + \ifx\themainfile\@empty + \currfile@set{\currfile@maindir\jobname.\currfile@mainext} + \else + \currfile@set{\themainfile} + \fi +\else + \currfile@set{\currfile@maindir\jobname.\currfile@mainext} +\fi \currfile@push \let\currfile@stackinit\currfile@stack % \end{macrocode} % \end{macro} % \end{macro} % +% Disable the change of the \opt{abspath} option at this point +% in order to freeze the stack format. +% \begin{macrocode} +\let\currfile@abspathfalse\relax +\let\currfile@abspathtrue\relax +% \end{macrocode} % -% \subsection{If Macros} +% \subsubsection{If Macros} % \begin{macro}{\ifcurrfilename} % \begin{macrocode} \newcommand*\ifcurrfilename{\begingroup\currfile@if\currfilename} @@ -434,6 +609,26 @@ % \end{macrocode} % \end{macro} % +% \begin{macrocode} +\ifcurrfile@abspath +% \end{macrocode} +% +% \begin{macro}{\ifcurrfileabspath} +% \begin{macrocode} +\newcommand*\ifcurrfileabspath{\begingroup\currfile@if\currfileabspath} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfileabsdir} +% \begin{macrocode} +\newcommand*\ifcurrfileabsdir{\begingroup\currfile@if\currfileabsdir} +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\fi +% \end{macrocode} +% % \begin{macro}{\ifcurrfile}[1]{currfile macro or text} % Expands and sanitizes the first argument and then calls the internal if-macro % with the result. @@ -466,7 +661,7 @@ % \end{macro} % % -% \subsection{Fink Macros} +% \subsubsection{Fink Macros} % % The \pkg{fink} option defines all \pkg{fink} package macros to use the ones provided % by this package. If the \pkg{fink} package was loaded beforehand the restoration @@ -506,5 +701,293 @@ %</currfile.sty> % \fi % +% \iffalse +%<*currfile-abspath.sty> +% \fi +% \subsection{Sub-package \pkg{currfile-abspath}} +% +% \subsubsection{Package header} +% +% \begin{macrocode} +\NeedsTeXFormat{LaTeX2e}[1999/12/01] +\ProvidesPackage{currfile-abspath}[% +%<!DATE> +%<!VERSION> +%<*DRIVER> + 2099/01/01 develop +%</DRIVER> + Provides absolute file paths, the parent working directory and the main file name] +% \end{macrocode} +% +% +% \subsubsection{Preliminary Code} +% +% Declare and init macros +% \begin{macrocode} +\newcommand*\thepwd{} +\newcommand*\theabspath{} +\newcommand*\theabsdir{} +\newcommand*\themainfile{} +% \end{macrocode} +% Long, empty: +% \begin{macrocode} +\newif\ifcurrfile@abspath@windows +% \end{macrocode} +% +% Ensure that the main file extension is defined and not empty. +% \begin{macrocode} +\providecommand\currfile@mainext{tex} +\ifx\currfile@mainext\@empty + \PackageError{currfile-abspath} + {Empty main file extension is not supported}{}% +\fi +% \end{macrocode} +% +% \iffalse +%\edef\themainfile{\jobname.\currfile@mainext} +%\@onelevel@sanitize\themainfile +% \fi +% +% +% \begin{macro}{\currfile@abspath@noflswarning} +% +% \begin{macrocode} +\def\currfile@abspath@noflswarning{% + \PackageWarning{currfile-abspath} + {The required recorder file (.fls) was not found.\MessageBreak + Please compile with the '-recorder' option.\MessageBreak + Note that MikTeX requires two compiler runs.\MessageBreak + Occurred}% + \global\let\currfile@abspath@noflswarning\relax + \global\csname currfile@abspathfalse\endcsname +}% +% \end{macrocode} +% \end{macro} +% +% +% \subsubsection{Parent Working Directory (PWD)} +% Opens the |\jobname.fls| file and checks for the `|PWD|' line (should be the very first one). +% \begin{macro}{\getpwd} +% \begin{macrocode} +\newcommand\getpwd{% + \begingroup + \let\thepwd\@empty + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + } + \currfile@abspath@noflswarning + \edef\@tempa{% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{\currfile@checkpwd} +% Checks if the read line starts with `|PWD|' and stores the rest +% of the line in \Macro\thepwd. The space after `|PWD|' is skipped by +% \TeX\ when looking for |#4|. +% \begin{macrocode} +\def\currfile@checkpwd#1#2#3#4#5\relax{% + \edef\@tempa{#1#2#3}% + \edef\@tempb{PWD}% + \@onelevel@sanitize\@tempb + \ifx\@tempa\@tempb + \edef\thepwd{#4#5/}% + \def\@tempa{#4}% + \def\@tempb{/}% + \ifx\@tempa\@tempb + \currfile@abspath@windowsfalse + \else + \currfile@abspath@windowstrue + \fi + \let\iterate\relax + \fi +} +% \end{macrocode} +% \end{macro} +% +% +% \subsubsection{Absolute Path} +% +% \begin{macro}{\getabspath} +% Opens the |\jobname.fls| file and checks for the first `|INPUT|' line +% which lists the given filename. +% \begin{macrocode} +\newcommand\getabspath[1]{% + \begingroup + \edef\filename{#1}% + \@onelevel@sanitize\filename% + \let\theabspath\@empty + \let\theabsdir\@empty + \IfFileExists{\filename}{% + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \expandafter\currfile@abspath@defs\expandafter{\filename}% + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@abspath@getabspath\expandafter{\line}% + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + }\currfile@abspath@noflswarning + }{}% + \edef\@tempa{% + \def\noexpand\theabspath{\theabspath}% + \def\noexpand\theabsdir{\theabsdir}% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{\getmainfile} +% Opens the |\jobname.fls| file and checks for the first `|INPUT|' line +% which lists a file with the main file extension (usually `|.tex|'). +% \begin{macrocode} +\newcommand\getmainfile{% + \begingroup + \let\themainfile\@empty + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@abspath@getmainfile\expandafter{\line}% + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + }% + \currfile@abspath@noflswarning + \edef\@tempa{% + \def\noexpand\themainfile{\themainfile}% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +% \end{macrocode} +% \end{macro} +% +% +% \subsubsection{Line scanning macros for abspath and mainfile} +% +% +% \begin{macro}{\currfile@abspath@testfname} +% Test if directory is empty because the file is only listed by name, i.e. is in the PWD +% or because the searched path was an absolute one and no further path elements are therefore listed +% In the first case set \Macro\theabsdir to \Macro\thepwd, in the second case keep it empty. +% \begin{macrocode} +\def\currfile@abspath@testfname#1#2#3\relax{% + \ifcurrfile@abspath@windows + \def\@tempa{#2}% + \def\@tempb{:}% + \else + \def\@tempa{#1}% + \def\@tempb{/}% + \fi + \ifx\@tempa\@tempb\else + \let\theabsdir\thepwd + \fi +} +% \end{macrocode} +% \end{macro} +% +% Change catcodes for `|INPUT|' to 12 (\emph{other}), because we need +% them this way in the parameter lists of the following macros. +% \begin{macrocode} +\begingroup +\catcode`I=12 +\catcode`N=12 +\catcode`P=12 +\catcode`U=12 +\catcode`T=12 +% \end{macrocode} +% +% \begin{macro}{\currfile@abspath@defs} +% Dynamically defines the macros needed to find the line with the requested file name. +% \begin{macrocode} +\gdef\currfile@abspath@defs#1{% + \def\currfile@abspath@checkabspath ##1INPUT ##2#1\relax##3\relax##4\@nnil{% + \ifx\@empty##4\@empty\else + \def\theabsdir{##2}% + \ifx\theabsdir\@empty + \currfile@abspath@testfname#1\@empty\@empty\relax + \fi + \edef\theabspath{\theabsdir#1}% + \let\iterate\relax + \fi + }% + \def\currfile@abspath@getabspath##1{% + \currfile@abspath@checkabspath##1\relax INPUT \@empty#1\relax{}\relax\@nnil + }% +} +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{\currfile@abspath@checkmainfile} +% \begin{macro}{\currfile@abspath@getmainfile} +% These two macros are defined with the main file extension given by +% \Macro\currfile@mainext in their parameter texts. To insert the extension +% with the correct catcode 12 two temporary auxiliary macros are utilized. +% The |get| macro places the line content before the |check| macro with a suitable +% fallback code so that the search text is always found and no \TeX\ error is raised. +% The |check| macro tests if the fallback has occurred and stores the read path +% if this was not the case. +% \begin{macrocode} +\def\@tempa#1{% + \gdef\currfile@abspath@checkmainfile ##1INPUT ##2#1\relax##3\relax##4\@nnil{% + \ifx\@empty##4\@empty\else + \def\themainfile{##2#1}% + \let\iterate\relax + \fi + }% + \gdef\currfile@abspath@getmainfile##1{% + \currfile@abspath@checkmainfile##1\relax INPUT \@empty#1\relax{}\relax\@nnil + }% +} +\edef\@tempb{.\currfile@mainext} +\@onelevel@sanitize\@tempb +\expandafter\@tempa\expandafter{\@tempb} +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% Ends catcode changes: +% \begin{macrocode} +\endgroup +% \end{macrocode} +% +% \iffalse +%</currfile-abspath.sty> +% \fi +% % \Finale \endinput diff --git a/Master/texmf-dist/source/latex/currfile/currfile.ins b/Master/texmf-dist/source/latex/currfile/currfile.ins index dd03ac0a415..bf77cb405a3 100644 --- a/Master/texmf-dist/source/latex/currfile/currfile.ins +++ b/Master/texmf-dist/source/latex/currfile/currfile.ins @@ -4,4 +4,5 @@ \keepsilent \askforoverwritefalse \generate{\nopreamble\file{currfile.sty}{\from{currfile.dtx}{currfile.sty}}} +\generate{\nopreamble\file{currfile-abspath.sty}{\from{currfile.dtx}{currfile-abspath.sty}}} \endbatchfile diff --git a/Master/texmf-dist/tex/latex/currfile/currfile-abspath.sty b/Master/texmf-dist/tex/latex/currfile/currfile-abspath.sty new file mode 100644 index 00000000000..f598d5d6ccb --- /dev/null +++ b/Master/texmf-dist/tex/latex/currfile/currfile-abspath.sty @@ -0,0 +1,171 @@ +\NeedsTeXFormat{LaTeX2e}[1999/12/01] +\ProvidesPackage{currfile-abspath}[% + 2012/05/06 + v0.6 + Provides absolute file paths, the parent working directory and the main file name] +\newcommand*\thepwd{} +\newcommand*\theabspath{} +\newcommand*\theabsdir{} +\newcommand*\themainfile{} +\newif\ifcurrfile@abspath@windows +\providecommand\currfile@mainext{tex} +\ifx\currfile@mainext\@empty + \PackageError{currfile-abspath} + {Empty main file extension is not supported}{}% +\fi +\def\currfile@abspath@noflswarning{% + \PackageWarning{currfile-abspath} + {The required recorder file (.fls) was not found.\MessageBreak + Please compile with the '-recorder' option.\MessageBreak + Note that MikTeX requires two compiler runs.\MessageBreak + Occurred}% + \global\let\currfile@abspath@noflswarning\relax + \global\csname currfile@abspathfalse\endcsname +}% +\newcommand\getpwd{% + \begingroup + \let\thepwd\@empty + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + } + \currfile@abspath@noflswarning + \edef\@tempa{% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +\def\currfile@checkpwd#1#2#3#4#5\relax{% + \edef\@tempa{#1#2#3}% + \edef\@tempb{PWD}% + \@onelevel@sanitize\@tempb + \ifx\@tempa\@tempb + \edef\thepwd{#4#5/}% + \def\@tempa{#4}% + \def\@tempb{/}% + \ifx\@tempa\@tempb + \currfile@abspath@windowsfalse + \else + \currfile@abspath@windowstrue + \fi + \let\iterate\relax + \fi +} +\newcommand\getabspath[1]{% + \begingroup + \edef\filename{#1}% + \@onelevel@sanitize\filename% + \let\theabspath\@empty + \let\theabsdir\@empty + \IfFileExists{\filename}{% + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \expandafter\currfile@abspath@defs\expandafter{\filename}% + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@abspath@getabspath\expandafter{\line}% + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + }\currfile@abspath@noflswarning + }{}% + \edef\@tempa{% + \def\noexpand\theabspath{\theabspath}% + \def\noexpand\theabsdir{\theabsdir}% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +\newcommand\getmainfile{% + \begingroup + \let\themainfile\@empty + \IfFileExists{\jobname.fls}{% + \openin\@inputcheck=\jobname.fls\relax + \endlinechar\m@ne + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@checkpwd\line\relax\relax\relax\relax\relax + \loop + \readline\@inputcheck to \line + \@onelevel@sanitize\line + \expandafter\currfile@abspath@getmainfile\expandafter{\line}% + \ifeof\@inputcheck\else + \repeat + \closein\@inputcheck + }% + \currfile@abspath@noflswarning + \edef\@tempa{% + \def\noexpand\themainfile{\themainfile}% + \def\noexpand\thepwd{\thepwd}% + }% + \expandafter + \endgroup + \@tempa +} +\def\currfile@abspath@testfname#1#2#3\relax{% + \ifcurrfile@abspath@windows + \def\@tempa{#2}% + \def\@tempb{:}% + \else + \def\@tempa{#1}% + \def\@tempb{/}% + \fi + \ifx\@tempa\@tempb\else + \let\theabsdir\thepwd + \fi +} +\begingroup +\catcode`I=12 +\catcode`N=12 +\catcode`P=12 +\catcode`U=12 +\catcode`T=12 +\gdef\currfile@abspath@defs#1{% + \def\currfile@abspath@checkabspath ##1INPUT ##2#1\relax##3\relax##4\@nnil{% + \ifx\@empty##4\@empty\else + \def\theabsdir{##2}% + \ifx\theabsdir\@empty + \currfile@abspath@testfname#1\@empty\@empty\relax + \fi + \edef\theabspath{\theabsdir#1}% + \let\iterate\relax + \fi + }% + \def\currfile@abspath@getabspath##1{% + \currfile@abspath@checkabspath##1\relax INPUT \@empty#1\relax{}\relax\@nnil + }% +} +\def\@tempa#1{% + \gdef\currfile@abspath@checkmainfile ##1INPUT ##2#1\relax##3\relax##4\@nnil{% + \ifx\@empty##4\@empty\else + \def\themainfile{##2#1}% + \let\iterate\relax + \fi + }% + \gdef\currfile@abspath@getmainfile##1{% + \currfile@abspath@checkmainfile##1\relax INPUT \@empty#1\relax{}\relax\@nnil + }% +} +\edef\@tempb{.\currfile@mainext} +\@onelevel@sanitize\@tempb +\expandafter\@tempa\expandafter{\@tempb} +\endgroup +\endinput +%% +%% End of file `currfile-abspath.sty'. diff --git a/Master/texmf-dist/tex/latex/currfile/currfile.sty b/Master/texmf-dist/tex/latex/currfile/currfile.sty index 9697d4679c2..01ed8381aee 100644 --- a/Master/texmf-dist/tex/latex/currfile/currfile.sty +++ b/Master/texmf-dist/tex/latex/currfile/currfile.sty @@ -1,7 +1,7 @@ \NeedsTeXFormat{LaTeX2e}[1999/12/01] \ProvidesPackage{currfile}[% - 2011/09/18 - v0.5 + 2012/05/06 + v0.6 ydoc package to describe macros, environments, options etc.] \RequirePackage{kvoptions} \SetupKeyvalOptions{family=currfile,prefix=currfile@} @@ -20,6 +20,9 @@ \DeclareBoolOption[false]{fink}% }% \DeclareVoidOption{force}{\PassOptionsToPackage{force}{filehook}} +\DeclareBoolOption[false]{realmainfile}% +\let\ifcurrfile@realmainfile\relax +\DeclareBoolOption[false]{abspath}% \RequirePackage{filehook}[2011/01/09] \ProcessKeyvalOptions*\relax @@ -28,9 +31,26 @@ \xdef\currfile@maindir{\currfile@maindir}% \def\@tempa{./}% \ifx\@tempa\currfile@maindir - \global\let\currfile@maindir\empty + \global\let\currfile@maindir\@empty \fi \endgroup + +\expandafter\ifx\csname ifcurrfile@realmainfile\endcsname\relax + \ifcurrfile@abspath + \currfile@realmainfiletrue + \else + \currfile@realmainfilefalse + \fi +\fi + +\let\currfileabspath\@empty +\let\currfileabsdir\@empty +\ifcurrfile@abspath + \RequirePackage{currfile-abspath} +\else +\ifcurrfile@realmainfile + \RequirePackage{currfile-abspath} +\fi\fi \filehook@prefixwarg\filehook@every@atbegin{% \currfile@push \currfile@set{#1}% @@ -53,6 +73,11 @@ \global\let\currfileext\filename@ext \xdef\currfilename{\currfilebase\ifx\currfileext\@empty\else.\currfileext\fi}% \xdef\currfilepath{\currfiledir\currfilename}% + \ifcurrfile@abspath + \getabspath\currfilepath + \global\let\currfileabspath\theabspath + \xdef\currfileabsdir{\theabsdir\currfiledir}% + \fi \endgroup } \def\currfile@checkpath{% @@ -89,6 +114,17 @@ \endgroup \def\currfile@defaultext{tex} \@onelevel@sanitize\currfile@defaultext +\ifcurrfile@abspath +\def\currfile@push{% + \xdef\currfile@stack{% + {\currfiledir}% + {\currfilebase}% + {\currfileext}% + {\currfileabsdir}% + \currfile@stack + }% +} +\else \def\currfile@push{% \xdef\currfile@stack{% {\currfiledir}% @@ -97,6 +133,7 @@ \currfile@stack }% } +\fi \def\currfile@pop{% \ifx\currfile@stack\empty \PackageWarning{currfile}{File stack underflow!}% @@ -105,6 +142,18 @@ \expandafter\currfile@pop@\currfile@stack\relax \relax\relax\relax } +\ifcurrfile@abspath +\def\currfile@pop@#1#2#3#4#5\relax{% + \gdef\currfiledir{#1}% + \gdef\currfilebase{#2}% + \gdef\currfileext{#3}% + \xdef\currfilename{\currfilebase\ifx\currfileext\empty\else.\currfileext\fi}% + \xdef\currfilepath{\currfiledir\currfilename}% + \gdef\currfileabsdir{#4}% + \xdef\currfileabspath{\ifx\currfileabsdir\@empty\else\currfileabsdir\currfilename\fi}% + \gdef\currfile@stack{#5}% +} +\else \def\currfile@pop@#1#2#3#4\relax{% \gdef\currfiledir{#1}% \gdef\currfilebase{#2}% @@ -113,15 +162,31 @@ \xdef\currfilepath{\currfiledir\currfilename}% \gdef\currfile@stack{#4}% } +\fi \def\currfile@stack{} -\currfile@set{\currfile@maindir\jobname.\currfile@mainext} +\ifcurrfile@realmainfile + \getmainfile + \ifx\themainfile\@empty + \currfile@set{\currfile@maindir\jobname.\currfile@mainext} + \else + \currfile@set{\themainfile} + \fi +\else + \currfile@set{\currfile@maindir\jobname.\currfile@mainext} +\fi \currfile@push \let\currfile@stackinit\currfile@stack +\let\currfile@abspathfalse\relax +\let\currfile@abspathtrue\relax \newcommand*\ifcurrfilename{\begingroup\currfile@if\currfilename} \newcommand*\ifcurrfilebase{\begingroup\currfile@if\currfilebase} \newcommand*\ifcurrfileext{\begingroup\currfile@if\currfileext} \newcommand*\ifcurrfiledir{\begingroup\currfile@if\currfiledir} \newcommand*\ifcurrfilepath{\begingroup\currfile@if\currfilepath} +\ifcurrfile@abspath +\newcommand*\ifcurrfileabspath{\begingroup\currfile@if\currfileabspath} +\newcommand*\ifcurrfileabsdir{\begingroup\currfile@if\currfileabsdir} +\fi \newcommand*\ifcurrfile[1]{% \begingroup \edef\@tempb{#1}% |