% \iffalse                                                 -*- mode: LaTeX -*-
%
% fink.dtx --- Doc file for FiNK
%
% Copyright (C) 1999-2001 Didier Verna.
%
% PRCS: $Id: fink.dtx 1.21 Wed, 03 Apr 2002 12:51:24 +0200 didier $
%
% Author:        Didier Verna <didier@epita.fr>
% Maintainer:    Didier Verna <didier@epita.fr>
% Created:       Thu Sep 23 18:23:48 1999
% Last Revision: Mon Mar 26 16:35:16 2001
%
% This file is part of FiNK.
%
% FiNK may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.1
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.1 or later is part of all distributions of LaTeX
% version 1999/06/01 or later.
%
% FiNK consists of all files listed in the file `README'.
%
%
% Commentary:
%
% Contents management by FCM version 0.1.
%
%
% Code:
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
% \OnlyDescription
% \CodelineIndex
% \RecordChanges
\newcommand{\fink}{%
  \mbox{\fontfamily{ptm}\fontseries{b}\fontshape{it}\selectfont%
    F\hspace{-.4ex}\protect\raisebox{-.5ex}{\textmd{i}}\hspace{0.2ex}NK}%
  }
\begin{document}
\DocInput{fink.dtx}
\end{document}
%</driver>
%
% \fi
%
% \catcode`\�=14
% \CheckSum{106}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%
% ^^A $Format: "% \\newcommand{\\version}{v$Version$}"$
% \newcommand{\version}{v1.2}
% ^^A $Format: "% \\newcommand{\\releasedate}{$ReleaseDate$}"$
% \newcommand{\releasedate}{2002/04/03}
% ^^A $Format: "% \\newcommand{\\packagecopyright}{$LaTeXCopyright$}"$
% \newcommand{\packagecopyright}{Copyright \copyright{} 1999--2002 Didier Verna}
% \newcommand{\auctex}{AUC-\TeX}
% \MakeShortVerb{\|}
% \date{\today}
% \title{\fink{} -- the \LaTeXe{} \textbf{Fi}le \textbf{N}ame \textbf{K}eeper
% \thanks{This document describes \fink{} \version, release date
% \releasedate.}}
% \author{Didier Verna\\
% \texttt{mailto:didier@lrde.epita.fr}\\
% \texttt{http://www.lrde.epita.fr/\~{}didier/}}
% \maketitle
%
% \section{Description}
% This package is a real fink indeed: it looks over your shoulder and keeps
% track of files |\input|'ed (the \LaTeX{} way) or |\include|'ed in your
% document. You then have a permanent access to the name of the file currently
% being processed through the macro |\finkfile|. Dis packache fas orichinally
% a hack dat I used somefere elss, but since it might be of a cheneral
% interest, I'fe decided to make it a separate fink\ldots\par
% The \fink{} package is \packagecopyright{}, and distributed under the terms
% of the LPPL license.
%
% \section{User Interface}
% To use the package, simply say |\usepackage[|\meta{options}|]{fink}| in the
% preamble of your document. This will do everything for you. Now,
%
% \subsection{Available Options}
% \DescribeEnv{tex}\DescribeEnv{ltx}
% Because there's no way \TeX{} can give you back the extension of the main
% file being processed, it is not possible to determine it automatically if
% it's not just |tex|. To cope with this problem, these two options are
% provided in order for you to specify the initial file's extension. For
% instance, if you're processing a file named |foo.ltx|, you would say
% |\usepackage[ltx]{fink}| in the preamble of your document. By default, the
% |tex| extension is assumed.
%
% \subsection{Available Macros}
% \DescribeMacro{\finkextension}
% This macro is another way of specifying the main file's extension. It takes
% one argument, the extension of your main file. This can be useful if you
% happen to process a file with a rilly rilly weird extension, or without any
% extension at all. However, be cautious: if you're using this macro instead
% of one of the options, \textbf{you must give the dot explicitly}. For
% instance, to process a file named |foo.doh|, say this:
% \begin{verbatim}
% \usepackage{fink}
% \finkextension{.doh}
% \end{verbatim}
% Similarly, just say |\finkextension{}| for files without any extension.
% This macro can only be used once, in the preamble of your document. If you
% have to use it, do so just after the package inclusion, otherwise you might
% get a wrong filename for a while.\par
% \DescribeMacro{\finkfile}
% The name of the file currently being processed is kept in the |\finkfile|
% macro. Feel free to use it in your sources. Also, remember that this macro
% might expand to something wrong from time to time, when files are included
% with the \TeX{} (not \LaTeX) primitive. \fink{} won't notice the inclusion
% of these files. See the ``Caveat'' section below for more information on
% this problem.
%
% \section{\auctex{} support}
% \auctex{} is a powerful major mode for editing \TeX{} documents in
% \textsf{Emacs} or \textsf{XEmacs}. In particular, it provides automatic
% completion of macro names once they are known. \fink{} supports \auctex{}
% by providing a style file named \texttt{fink.el} which contains \auctex{}
% definitions for the relevant macros. This file should be installed to a
% location where \auctex{} can find it (usually in a subdirectory of your
% \LaTeX{} styles directory). Please refer to the \auctex{} documentation for
% more information on this.
%
% \section{Caveat}
% As said before, \fink{} cannot follow files included with the \TeX{}
% |\input| primitive. That's because \TeX{} has a very insensible way of
% defining primitives whose argument parsing syntax is not available for
% macros. As a consequence, it's almost impossible to redefine the |\input|
% primitive without breaking its syntax (one would have to parse the
% characters one by one, and I'm not ready to do so\ldots).
%
% \section{Changes}
% \begin{itemize}
% \item[v1.2] Fixed conflict with |\includegraphics|,\\
%   reported by Jim Crumley |<crumley@belka.space.umn.edu>|
% \item[v1.1] Fixed missing 3rd arg to |\PackageError| call from |\finkextension|
% \end{itemize}
%
% \StopEventually{\par Well, I think that's it. Enjoy using \fink{}!
%   \vfill\hfill\small \packagecopyright{}.}
%
% \section{The Code}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
� $Format: "\\ProvidesPackage{fink}[$ReleaseDate$ v$Version$"$
\ProvidesPackage{fink}[2002/04/03 v1.2
                       Keep track of the current filename]

%    \end{macrocode}
% \subsection{Filename macros}
% \begin{macro}{\finkfile}
%   \begin{macro}{\finkextentsion}
%     Macros for dealing with the name of the main file:
%     ^^A \changes{v1.1}{2000/12/20}{Fix missing 3rd arg in call to
%     ^^A `PackageError}
%   \end{macro}
% \end{macro}
%    \begin{macrocode}
\newcommand\finkfile{}
\def\fink@extension#1{\xdef\finkfile{\jobname#1}}
\newcommand\finkextension[1]{
  \fink@extension{#1}
  \PackageInfo{FiNK}{main filename switched to `\finkfile'}
  \renewcommand\finkextension[1]{
    \PackageError{FiNK}{\protect\finkextension\space can only be used once}{%
      You seem to have called \protect\finkextension\space twice.\MessageBreak
      Type X to quit, remove spurious call(s) and rerun LaTeX.}}}
\@onlypreamble\finkextension

%    \end{macrocode}
% \subsection{Options processing}
% \DescribeEnv{tex}
% \DescribeEnv{ltx}
% These options define common extensions:
%    \begin{macrocode}
\DeclareOption{tex}{\fink@extension{.tex}}
\DeclareOption{ltx}{\fink@extension{.ltx}}
%    \end{macrocode}
% Delaying the following message permits to emit it somewhat closer to a
% similar one which might be generated by a call to |\finkextension|
% afterwards.
%    \begin{macrocode}
\AtEndOfPackage{\PackageInfo{FiNK}{main filename is `\finkfile'}}

%    \end{macrocode}
% Let's process the options. By default, the main file's extension is `tex'.
%    \begin{macrocode}
\ExecuteOptions{tex}
\ProcessOptions*

%    \end{macrocode}
% \subsection{Commands overriding}
% \begin{macro}{\@finkfile}
%   \begin{macro}{\fink@setnewfile}
%     This macro prepares the name of next file to be input, and ensures we
%     get the proper extension in all cases:
%   \end{macro}
% ^^A \changes{v1.2}{2002/03/26}{Fix conflict with |\includegraphics|
% ^^A reported by |Jim Crumley <crumley@belka.space.umn.edu>|}
% As of version 1.2, this macro performs in a group of its own. This fixes a
% problem that appeared when using |\includegraphics| with a filename with an
% explicit extension. |\includegraphics| calls itself |\filename@parse|, so it
% is important that the same call in |\fink@setnewfile| only have a local
% effect, just the time to compute the new value of |\@finkfile|.
% \end{macro}
%    \begin{macrocode}
\def\fink@setnewfile#1{%
  {\filename@parse{#1}%
    \xdef\@finkfile{%
      \filename@base.\ifx\filename@ext\relax tex\else\filename@ext\fi}}}

%    \end{macrocode}
% \begin{macro}{\fink@input}
%   \begin{macro}{\fink@restore}
%     These macros are defined for a convenient use of |\expandafter|. They
%     save and restore the current filename. Remember that |\@@input| is
%     \LaTeX's redefinition of the \TeX{} primitive.
%   \end{macro}
% \end{macro}
%    \begin{macrocode}
\def\fink@input{%
  \xdef\finkfile{\@finkfile}%
  \@@input\@filef@und}
\def\fink@restore{\xdef\finkfile}

%    \end{macrocode}
% \begin{macro}{\IfFileExists}
% The following macro is redefined only to let \fink{} update its filename.
% \end{macro}
%    \begin{macrocode}
\long\def\IfFileExists#1#2#3{%
  \openin\@inputcheck#1 %
  \ifeof\@inputcheck
    \ifx\input@path\@undefined
      \def\reserved@a{#3}%
    \else
      \def\reserved@a{\@iffileonpath{#1}{#2}{#3}}%
    \fi
  \else
    \closein\@inputcheck
    \edef\@filef@und{#1 }%
    \fink@setnewfile{#1}%
    \def\reserved@a{#2}%
  \fi
  \reserved@a}

%    \end{macrocode}
% \begin{macro}{\InputIfFileExists}
%   And finally, let's redefine the \LaTeX{} file inclusion macros:
% \end{macro}
%    \begin{macrocode}
\long\def\InputIfFileExists#1#2{%
  \IfFileExists{#1}{%
    #2\@addtofilelist{#1}%
    \expandafter\fink@input%
    \expandafter\fink@restore\expandafter{\finkfile}}}
\def\@input#1{%
  \IfFileExists{#1}{%
    \expandafter\fink@input%
    \expandafter\fink@restore\expandafter{\finkfile}}{%
    %% else
    \GenericWarning{}{no file #1.}}}

%    \end{macrocode}
%
% ^^A \PrintChanges
% ^^A \PrintIndex
% \Finale
%
% ^^A fink.dtx ends here.
