From 16d9f4855f8b6ffc886506f977596c5aa7b2ef12 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 11 Jan 2011 00:37:24 +0000 Subject: currfile 0.4 (10jan11) git-svn-id: svn://tug.org/texlive/trunk@21012 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/latex/currfile/currfile.dtx | 107 +++++++++++++++++++-- 1 file changed, 98 insertions(+), 9 deletions(-) (limited to 'Master/texmf-dist/source/latex/currfile') diff --git a/Master/texmf-dist/source/latex/currfile/currfile.dtx b/Master/texmf-dist/source/latex/currfile/currfile.dtx index c5e3a3f7dab..a1c159a4d53 100644 --- a/Master/texmf-dist/source/latex/currfile/currfile.dtx +++ b/Master/texmf-dist/source/latex/currfile/currfile.dtx @@ -19,7 +19,7 @@ %% This work consists of the files currfile.dtx, currfile.ins %% and the derived file currfile.sty. %% -%% $Id: currfile.dtx 2006 2011-01-03 22:54:46Z martin $ +%% $Id: currfile.dtx 2036 2011-01-09 17:51:42Z martin $ % \fi % % \iffalse @@ -29,12 +29,12 @@ %\NeedsTeXFormat{LaTeX2e}[1999/12/01] %\ProvidesPackage{currfile} %<*package> - [2011/01/03 v0.3 Current input file name and path] + [2011/01/09 v0.4 Current input file name and path] % % %<*driver> -\documentclass{ydoc}[2011/01/03] -\usepackage{currfile}[2011/01/03] +\documentclass{ydoc}[2011/01/09] +\usepackage{currfile}[2011/01/09] \usepackage{ifpdf} \usepackage{booktabs} \usepackage{hyperref} @@ -52,7 +52,7 @@ % % \fi % -% \CheckSum{201} +% \CheckSum{258} % % \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 @@ -76,6 +76,7 @@ % Added package option 'fink' to define the same macros as the 'fink' package. % } % \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.} % % \GetFileInfo{currfile.dtx} % @@ -119,22 +120,45 @@ % \DescribeMacro{\currfilepath} % The directory, base (name without extension), extension (without dot), name (=base+`|.|'+ext) and path (=dir+name) of the current file are provided by these macros. % This means that the macros returns the file information of the file they are used in. All macros are fully expanded, i.e.\ only hold -% text and not further macros. +% 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}|. +% % 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. % % 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. % % More detailed information can be found in the implementation section \ref{sec:impl} if required. % +% \DescribeMacro{\ifcurrfiledir}{}{}{} +% \DescribeMacro{\ifcurrfilebase}{}{}{} +% \DescribeMacro{\ifcurrfileext}{}{}{} +% \DescribeMacro{\ifcurrfilename}{}{}{} +% \DescribeMacro{\ifcurrfilepath}{}{}{} +% 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. +% The \meta{text} is fully expanded and sanitized for the comparison. Example: |\ifcurrfileext{cfg}{I'm in a config file}{No config file!}| +% +% \DescribeMacro{\ifcurrfile}{}{}{}{} +% 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. +% 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. % 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. % +% \section{Usage inside file hooks} +% This package uses the `EveryFile' hooks of the \pkg{filehook} package to update its macros. +% 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. +% Please note that the `AtEndOfPackageFile' and `AtEndOfClassFile' hooks are executed after `AtEndOfEveryFile' +% and therefore the |currfile| macros will hold the values of the parent file, not of that package or class file. +% % \section{Compatibility with the \texttt{fink} package}\label{sec:fink} % 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 % 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 @@ -192,7 +216,7 @@ \DeclareBoolOption[false]{fink}% }% \DeclareVoidOption{force}{\PassOptionsToPackage{force}{filehook}} -\RequirePackage{filehook}[2011/01/03] +\RequirePackage{filehook}[2011/01/09] \ProcessKeyvalOptions*\relax \begingroup @@ -230,7 +254,9 @@ % \begin{macrocode} \def\currfile@set#1{% \begingroup - \filename@parse{#1}% + \edef\@tempa{#1}% + \@onelevel@sanitize\@tempa + \expandafter\filename@parse\expandafter{\@tempa}% \global\let\currfiledir\filename@area \global\let\currfilebase\filename@base \xdef\currfileext{\ifx\filename@ext\relax tex\else\filename@ext\fi}% @@ -311,6 +337,69 @@ % \end{macro} % % +% \subsection{If Macros} +% \begin{macro}{\ifcurrfilename} +% \begin{macrocode} +\newcommand*\ifcurrfilename{\begingroup\currfile@if\currfilename} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfilebase} +% \begin{macrocode} +\newcommand*\ifcurrfilebase{\begingroup\currfile@if\currfilebase} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfileext} +% \begin{macrocode} +\newcommand*\ifcurrfileext{\begingroup\currfile@if\currfileext} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfiledir} +% \begin{macrocode} +\newcommand*\ifcurrfiledir{\begingroup\currfile@if\currfiledir} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfilepath} +% \begin{macrocode} +\newcommand*\ifcurrfilepath{\begingroup\currfile@if\currfilepath} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\ifcurrfile}[1]{currfile macro or text} +% Expands and sanitizes the first argument and then calls the internal if-macro +% with the result. +% \begin{macrocode} +\newcommand*\ifcurrfile[1]{% + \begingroup + \edef\@tempb{#1}% + \@onelevel@sanitize\@tempb + \currfile@if\@tempb +} +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\currfile@if}[2]{currfile macro to compare}{compare text} +% Expands the text and sanitize it to ensure correct neutral catcodes. +% Then it temp macro is compared to the given currfile macro. +% \begin{macrocode} +\def\currfile@if#1#2{% + \edef\@tempa{#2}% + \@onelevel@sanitize\@tempa + \ifx\@tempa#1% + \endgroup + \expandafter\@firstoftwo + \else + \endgroup + \expandafter\@secondoftwo + \fi +} +% \end{macrocode} +% \end{macro} +% +% % \subsection{Fink Macros} % % The \pkg{fink} option defines all \pkg{fink} package macros to use the ones provided @@ -332,7 +421,7 @@ \@ifpackageloaded{fink}{% \def\fink@restore#1{}% }{% - \@namedef{ver@fink.sty}{2011/01/03}% + \@namedef{ver@fink.sty}{2011/01/09}% \expandafter\edef\csname opt@fink.sty\endcsname{% maindir=\currfile@maindir,mainext=\currfile@mainext }% -- cgit v1.2.3