Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!cernvax!chx400!chx400!cgch!ciba-geigy.ch!wrtc From: wrtc@ciba-geigy.ch (Roland Tucci) Newsgroups: comp.text.tex Subject: Re: How can I get the current input file name in TeX? Message-ID: <1991Apr17.140022.11948@nntphost.ciba-geigy.ch> Date: 17 Apr 91 14:00:22 GMT References: <31860@usc> Sender: news@nntphost.ciba-geigy.ch (USENET News Agent) Reply-To: wrtc@ciba-geigy.ch (Roland Tucci) Distribution: comp Organization: Ciba-Geigy AG, Basel, Switzerland Lines: 63 Nntp-Posting-Host: 192.37.10.20 In article <31860@usc>, siemsen@sol.usc.edu (Pete Siemsen) writes: |> |>Is there a way to put the name of the file currently being processed |>into a LaTeX or TeX file? I'd like something like \inputfilename that |>puts the file name into my DVI file in the current font. |> |>-- |>Pete Siemsen Pete Siemsen siemsen@usc.edu |>University of Southern California 645 Ohio Ave. #302 (213) |>740-7391 (w) |>1020 West Jefferson Blvd. Long Beach, CA 90814 (213) |>433-3059 (h) |>Los Angeles, CA 90089-0251 |> The following code does it. Hope this helps you >>>----------------------------------------------------------------------<<< % % Inputfile style : Designed by R.Tucci, Ciba-Geigy AG Basle, June 29, 1990 % modified by R.Tucci Feb. 21, 1991 % % The following commands are defined for internal use % % \@fileindex : To keep the current level of \input{} % \@iinput : Redefines the \@iinput command of \latex.tex to % save the filename of \input{...} % \inputfilename : Returns the filename depending on \@fileindex % \@filenamei : Contains the filename for \@fileindex=1 % \@filenameii : Contains the filename for \@fileindex=2 % \@filenameiii : Contains the filename for \@fileindex=3 % \@filename... : ... etc. % This Style should be used in the following manner % % 1. add this file to the \documentstyle[...] % 2. use the command \inputfilename somewhere in the text and the current % input file name will be substituted \typeout{filename environment loaded. WRTC , Version 1.1 22.02.91} % % Redefine \@iinput from latex.tex to keep the filename % available \newcount\@fileindex % defines the pointer to the current filename \@fileindex=0 % and initialize it. \def\@iinput#1{\advance\@fileindex by 1 % increment the pointer % save the filename % the following line dose this Job: % 1. \expandafter prevents to redefine \csname, so % 2. \csname filename\romannumeral\@fileindex\endcsname % expands to the control sequence \filename where is % the roman character representation of \@fileindex. (e.g ii) % 3. \def defines the resulted control sequence of 2. to be #1 \expandafter\def\csname filename\romannumeral\@fileindex\endcsname {#1} \@@input#1 % now read the file \ifnum\@fileindex>0 % check for end of stack \advance\@fileindex by -1 \fi} % and decrement the pointer % read the current filename if an \input % has been performed, otherwise use \jobname \def\inputfilename{\ifnum\@fileindex=0\jobname \else\csname filename\romannumeral\@fileindex\endcsname \fi}