diff options
author | Karl Berry <karl@freefriends.org> | 2012-05-15 23:33:29 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-05-15 23:33:29 +0000 |
commit | b86f7fb42fa95eef8764f121728bb48e0fc6e6d7 (patch) | |
tree | 4e0e79794637c081541c3649ec148819fb6f5e83 /Master/texmf-dist/source/latex | |
parent | 8a5513026f7211045d0f6e358c4d64b77ee45410 (diff) |
currfile 0.7 (15may12)
git-svn-id: svn://tug.org/texlive/trunk@26425 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex')
-rw-r--r-- | Master/texmf-dist/source/latex/currfile/currfile.dtx | 232 |
1 files changed, 212 insertions, 20 deletions
diff --git a/Master/texmf-dist/source/latex/currfile/currfile.dtx b/Master/texmf-dist/source/latex/currfile/currfile.dtx index 6996625b5ad..063c20e5fb6 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> - 2012/05/06 + 2012/05/15 %<=/DATE> %<=*VERSION> - v0.6 + v0.7 %<=/VERSION> DTX file for currfile package] @@ -41,6 +41,7 @@ \usepackage{ifpdf} \usepackage{booktabs} \usepackage{hyperref} +\usepackage{flafter} \EnableCrossrefs \CodelineIndex \RecordChanges @@ -49,6 +50,7 @@ \ifx\IncludeImplementation\relax \OnlyDescription \fi +\let\cnt\env \begin{document} \DocInput{currfile.dtx} \PrintChanges @@ -83,6 +85,8 @@ % \changes{v0.3}{2011/01/03}{Update to use new version of filehook.} % \changes{v0.4}{2011/01/09}{Added if-macros and sanitized currfile macros.} % \changes{v0.5}{2011/09/18}{Added support for \cs{input@path} and files with multiple dots.} +% \changes{v0.6}{2012/05/06}{Added support for absolute file paths.} +% \changes{v0.7}{2012/05/15}{Added support for parent file paths.} % % \GetFileInfo{currfile.dtx} % @@ -124,12 +128,22 @@ % 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 % \Macro\LoadClass and similar macros. Before v0.2 only \Macro\input or \Macro\include and the main file were taken into account. % -% % This package uses the \pkg{filehook} package written by the same author. See there for possible incompatibilities with classes or other packages. % % 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. % +% \begingroup +% \let\DescribeCounter\DescribeKey +% \let\keydescstyle\macrodescstyle +% \DescribeCounter{currfiledepth} +% This\marginpar{\raggedright New in v0.7 from 2012/05/15} \LaTeX\ counter provides the nesting depth of the current input file. +% For the main file name it has a value of 0. +% 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. +% Like all \LaTeX\ counter it can be typeset using \Macro\arabic{currfiledepth} and its numeric value can be accessed +% using \Macro\value{currfiledepth}. +% \endgroup +% % \DescribeMacro{\ifcurrfiledir}{<text>}{<true>}{<false>} % \DescribeMacro{\ifcurrfilebase}{<text>}{<true>}{<false>} % \DescribeMacro{\ifcurrfileext}{<text>}{<true>}{<false>} @@ -173,6 +187,9 @@ % This option requires the compiler option `|-recorder|' to be used in order to work correctly. % See \autoref{sec:abspath} for more details. % +% Using the boolean \opt{parent} option\marginpar{\raggedright New in v0.7 from 2012/05/15} +% additional macros are set for the parent file of the current file. +% See \autoref{sec:parent} for more details. % % \section{Absolute paths}\label{sec:abspath} % If\marginpar{\raggedright New in v0.6 from 2012/05/06} @@ -239,6 +256,49 @@ % 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{Parent file macros}\label{sec:parent} +% If\marginpar{\raggedright New in v0.7 from 2012/05/15} +% the \opt{parent} package option is enabled the following macros are provided. +% They are no direct |\if...| macros for these but the general \Macro\ifcurrfile macro can be used with them. +% +% \DescribeMacro{\parentfiledir} +% \DescribeMacro{\parentfilebase} +% \DescribeMacro{\parentfileext} +% \DescribeMacro{\parentfilename} +% \DescribeMacro{\parentfilepath} +% These macros are analog to the |\currfile...| macros but for the parent file of the current file. +% They are all empty for the main file which does not have a parent file. +% +% \DescribeMacro{\parentfileabsdir} +% \DescribeMacro{\parentfileabspath} +% These macros are provided if the \opt{abspath} option is used in addition to \opt{parent}. +% They are also empty for the main file. +% +% +% \section{Access all parent files}\label{sec:parents} +% If\marginpar{\raggedright New in v0.7 from 2012/05/15} +% the \opt{parents} package option is enabled the following macros are provided. +% Note that this option does not enable the \opt{parent} option. +% +% \DescribeMacro{\currfilegetparents} +% This macro locally defines file name macros for all parent files of the current input file: +% The macros are named like the ones of the \opt{parent} option, but also include a trailing +% roman number to indicate the parent file level, starting with `i` for the first parent file: +% +% \begin{DescribeMacrosTab}{llll} +% \Macro{\parentfilediri} & \Macro{\parentfiledirii} & $\ldots$ \\ +% \Macro{\parentfilebasei} & \Macro{\parentfilebaseii} & $\ldots$ \\ +% \Macro{\parentfileexti} & \Macro{\parentfileextii} & $\ldots$ \\ +% \Macro{\parentfilenamei} & \Macro{\parentfilenameii} & $\ldots$ \\ +% \Macro{\parentfilepathi} & \Macro{\parentfilepathii} & $\ldots$ \\ +% \Macro{\parentfileabsdiri} & \Macro{\parentfileabsdirii} & $\ldots$ \\ +% \Macro{\parentfileabspathi} & \Macro{\parentfileabspathii} & $\ldots$ \\ +% \end{DescribeMacrosTab} +% Note that these macros are only defined in the current group and not globally like all other file name macros. +% The number of the highest parent file is given by the \cnt{currfiledepth} counter. +% +% For example, if \Macro\currfilegetparents is used in a sub-sub-sub-file the \cnt{currfiledepth} counter is 3 +% and \Macro\parentfilenameiii is the name of the main document file. % % \section{Usage inside file hooks} % This package uses the `EveryFile' hooks of the \pkg{filehook} package to update its macros. @@ -318,6 +378,8 @@ \DeclareBoolOption[false]{fink}% }% \DeclareVoidOption{force}{\PassOptionsToPackage{force}{filehook}} +\DeclareBoolOption[false]{parent} +\DeclareBoolOption[false]{parents} \DeclareBoolOption[false]{realmainfile}% \let\ifcurrfile@realmainfile\relax \DeclareBoolOption[false]{abspath}% @@ -345,8 +407,6 @@ \fi \fi -\let\currfileabspath\@empty -\let\currfileabsdir\@empty \ifcurrfile@abspath \RequirePackage{currfile-abspath} \else @@ -382,6 +442,7 @@ % \begin{macrocode} \def\currfile@set#1{% \begingroup + \currfile@setparent \edef\@filef@und{#1}% \ifx\input@path\@undefined\else \currfile@checkpath @@ -400,6 +461,7 @@ \global\let\currfileabspath\theabspath \xdef\currfileabsdir{\theabsdir\currfiledir}% \fi + \addtocounter{currfiledepth}\@ne \endgroup %<debug> \expandafter\gdef\expandafter\dindent\expandafter{\dindent\space}% %<debug> \message{^^JDEBUG: \dindent\empty Entering file '\currfilename' ^^J }% @@ -407,6 +469,36 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\currfile@parent} +% Sets the current file data as parent file data. Must be called directly before +% updating the current file data. +% \begin{macrocode} +\ifcurrfile@parent +\ifcurrfile@abspath +\def\currfile@setparent{% + \global\let\parentfiledir\currfiledir + \global\let\parentfilebase\currfilebase + \global\let\parentfileext\currfileext + \global\let\parentfilename\currfilename + \global\let\parentfilepath\currfilepath + \global\let\parentfileabspath\currfileabspath + \global\let\parentfileabsdir\currfileabsdir +} +\else +\def\currfile@setparent{% + \global\let\parentfiledir\currfiledir + \global\let\parentfilebase\currfilebase + \global\let\parentfileext\currfileext + \global\let\parentfilename\currfilename + \global\let\parentfilepath\currfilepath +} +\fi +\else +\let\currfile@setparent\relax +\fi +% \end{macrocode} +% \end{macro} +% % % \begin{macro}{\currfile@checkpath} % This loop is placed in an own macro for efficiency reasons. @@ -503,12 +595,18 @@ % \begin{macrocode} \def\currfile@pop{% %<debug> \message{^^JDEBUG: \dindent\empty Leaving file '\currfilename' ^^J }% - \ifx\currfile@stack\empty + \ifcase0% + \ifx\currfile@stack\empty 1\else + \ifnum\value{currfiledepth}<\@ne 1\fi\fi + \relax + \addtocounter{currfiledepth}\m@ne + \else \PackageWarning{currfile}{File stack underflow!}% \global\let\currfile@stack\currfile@stackinit + \setcounter{currfiledepth}\z@ \fi \expandafter\currfile@pop@\currfile@stack\relax - \relax\relax\relax + \relax\relax\relax\relax\relax\relax\relax %<debug> \message{^^JDEBUG: \dindent\empty Restoring file '\currfilename' ^^J }% } % \end{macrocode} @@ -517,7 +615,7 @@ % \begin{macro}{\currfile@pop@} % \begin{macrocode} \ifcurrfile@abspath -\def\currfile@pop@#1#2#3#4#5\relax{% +\def\currfile@pop@#1#2#3#4{% \gdef\currfiledir{#1}% \gdef\currfilebase{#2}% \gdef\currfileext{#3}% @@ -525,36 +623,131 @@ \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}% + \currfile@updatestack } \else -\def\currfile@pop@#1#2#3#4\relax{% +\def\currfile@pop@#1#2#3{% \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}% + \currfile@updatestack } \fi % \end{macrocode} % \end{macro} % +% \begin{macro}{\currfile@updatestack} +% \begin{macrocode} +\ifcurrfile@parent +\ifcurrfile@abspath +\def\currfile@updatestack#1#2#3#4#5\relax{% + \gdef\parentfiledir{#1}% + \gdef\parentfilebase{#2}% + \gdef\parentfileext{#3}% + \xdef\parentfilename{\parentfilebase\ifx\parentfileext\empty\else.\parentfileext\fi}% + \xdef\parentfilepath{\parentfiledir\parentfilename}% + \gdef\parentfileabsdir{#4}% + \xdef\parentfileabspath{\ifx\parentfileabsdir\@empty\else\parentfileabsdir\parentfilename\fi}% + \gdef\currfile@stack{{#1}{#2}{#3}{#4}#5}% +} +\else +\def\currfile@updatestack#1#2#3#4\relax{% + \gdef\parentfiledir{#1}% + \gdef\parentfilebase{#2}% + \gdef\parentfileext{#3}% + \xdef\parentfilename{\parentfilebase\ifx\parentfileext\empty\else.\parentfileext\fi}% + \xdef\parentfilepath{\parentfiledir\parentfilename}% + \gdef\currfile@stack{{#1}{#2}{#3}#4}% +} +\fi +\else +\def\currfile@updatestack#1\relax{% + \gdef\currfile@stack{#1}% +} +\fi +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\ifcurrfile@parents +% \end{macrocode} +% +% \begin{macro}{\currfilegetparents} +% \begin{macrocode} +\newcommand*\currfilegetparents{% + \@tempcnta\@ne + \expandafter\currfile@getparents\currfile@stack\relax + \relax\relax\relax\relax\relax\relax\relax +} +\ifcurrfile@abspath +\def\currfile@getparents#1#2#3#4{% + \@namedef{parentfiledir\romannumeral\@tempcnta}{#1}% + \@namedef{parentfilebase\romannumeral\@tempcnta}{#2}% + \@namedef{parentfileext\romannumeral\@tempcnta}{#3}% + \expandafter\edef\csname parentfilename\romannumeral\@tempcnta\endcsname{#2\ifx\empty#3\empty\else.#3\fi}% + \expandafter\edef\csname parentfilepath\romannumeral\@tempcnta\endcsname{#1\csname parentfilename\romannumeral\@tempcnta\endcsname}% + \@namedef{parentfileabsdir\romannumeral\@tempcnta}{#4}% + \expandafter\edef\csname parentfileabspath\romannumeral\@tempcnta\endcsname{% + \expandafter\ifx\csname parentfileabsdir\romannumeral\@tempcnta\endcsname\@empty\else + \csname parentfileabsdir\romannumeral\@tempcnta\endcsname + \csname parentfilename\romannumeral\@tempcnta\endcsname + \fi + }% + \ifnum\@tempcnta<\c@currfiledepth + \advance\@tempcnta\@ne + \expandafter\currfile@getparents + \fi +} +\else +\def\currfile@getparents#1#2#3{% + \@namedef{parentfiledir\romannumeral\@tempcnta}{#1}% + \@namedef{parentfilebase\romannumeral\@tempcnta}{#2}% + \@namedef{parentfileext\romannumeral\@tempcnta}{#3}% + \expandafter\edef\csname parentfilename\romannumeral\@tempcnta\endcsname{#2\ifx\empty#3\empty\else.#3\fi}% + \expandafter\edef\csname parentfilepath\romannumeral\@tempcnta\endcsname{#1\csname parentfilename\romannumeral\@tempcnta\endcsname}% + \ifnum\@tempcnta<\c@currfiledepth + \advance\@tempcnta\@ne + \expandafter\currfile@getparents + \fi +} +\fi +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\parentfile}[2]{file path part}{number} +% Expands to the \Macro\parentfile<part><roman number> macro. +% \begin{macrocode} +\newcommand\parentfile[2]{% + \csname parentfile#1\romannumeral#2\endcsname +} +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\fi +% \end{macrocode} +% % \iffalse %<debug> \def\dindent{} % \fi % % \begin{macro}{\currfile@stack} % \begin{macro}{\currfile@stackinit} -% Place the main file values on stack and use this as init value. +% Initialise the stack with empty values and set the main file values. % \begin{macrocode} -\def\currfile@stack{} +\let\currfile@stack\@empty +\let\currfiledir\@empty +\let\currfilebase\@empty +\let\currfileext\@empty +\let\currfilename\@empty +\let\currfilepath\@empty +\let\currfileabspath\@empty +\let\currfileabsdir\@empty +\newcounter{currfiledepth} +\setcounter{currfiledepth}\m@ne +\currfile@push \ifcurrfile@realmainfile \getmainfile \ifx\themainfile\@empty @@ -565,7 +758,6 @@ \else \currfile@set{\currfile@maindir\jobname.\currfile@mainext} \fi -\currfile@push \let\currfile@stackinit\currfile@stack % \end{macrocode} % \end{macro} |