Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!ifistg!raichle From: raichle@informatik.uni-stuttgart.de (Bernd Raichle) Newsgroups: comp.text.tex Subject: Re: How can I get the current input file name in TeX? Message-ID: Date: 23 Apr 91 14:35:09 GMT References: <31860@usc> <1991Apr17.140022.11948@nntphost.ciba-geigy.ch> Sender: news@ifistg.uucp Distribution: comp Organization: Informatik, Univ. Stuttgart. W.Germany Lines: 81 In-reply-to: wrtc@ciba-geigy.ch's message of 17 Apr 91 14:00:22 GMT wrtc@ciba-geigy.ch (Roland Tucci) writes: > 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. > > [Inputfile style deleted] > There is a better way to do this (and without nesting boundaries). It uses a little trick to change a value locally without explicit grouping (with {...} or \begingroup...\endgroup}: \def\value{default} % value must be expandable! \def\doit#1{\def\temporary{#1}% \expandafter\ldoit\expandafter{\value}} \def\ldoit#1{% \let\value=\temporary % set to new value \doitoriginal % ... do something ... \def\value{#1}} % and reset it Ok, here is the LaTeX style option: -------------------- CUT HERE -------------------- % filename.sty \filename contains the actual filename % % first version: 1 Mar 91 (br) % last change : 5 Mar 91 (br) % % \typeout{Style option `filename' <5 Mar 91> (br)} % default-value of \filename is \jobname. % (\let is ok, because \jobname is one of the expandable primitives) % \let\filename=\jobname % LaTeX saves TeX's \input-primitive in \@@input, we save it % in \old@@input. % \let\old@@input=\@@input % The macros \input and \include (and all internal \input's) % expand the macro \@@input. % % First we save the argument (the new filename). Then we expand the current % \filename with \expandafter as argument of \reset@filename, before we % change the value of \filename. % After the expansion with \expandafter's we have % \file@input \reset@filename{} % and in \file@name is #1, the . % After reading the file with \file@input (we set \filename % to ), we reset \filename to . % % We can't use \begingroup ... \input ... \endgroup, because % assignments in shouldn't be local. % \def\@@input#1 {\def\file@name{#1}% \expandafter\file@@input \expandafter\reset@filename\expandafter{\filename}} \def\file@@input{\let\filename=\file@name \old@@input\filename\relax} %% Short form for... %\def\reset@filename#1{\def\filename{#1}} %% ...is... \def\reset@filename{\def\filename} \endinput % -- end of `filename.sty' -------------------- CUT HERE -------------------- -bernd __________________________________________________________________________ Bernd Raichle, Student der Universit"at Stuttgart | "Le langage est source privat: Stettener Str. 73, D-7300 Esslingen | de malentendus" email: raichle@azu.informatik.uni-stuttgart.de | (A. de Saint-Exupery)