[OS X TeX] jobname
Ross Moore
ross at ics.mq.edu.au
Wed Jan 24 17:53:20 EST 2007
Hi Alain,
On 25/01/2007, at 4:28 AM, Alain Schremmer wrote:
>> FAQ: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=filename
>
> Thanks: I had looked but of course didn't find this.
>
> However, I cannot make it work. The code given there,
>
> \def\ThisFile{\jobname}
> \newcounter{FileStack}
> \let\OrigInput\input
> \renewcommand{\input}[1]{%
> \stackinput{#1}{\OrigInput}%
> }
> \newcommand{\stackinput}[2]{%
> \stepcounter{FileStack}%
> \expandafter\let
> \csname NameStack\theFileStack\endcsname
> \ThisFile
> \def\ThisFile{#1}%
> #2{#1}%
> \expandafter\let\expandafter
> \ThisFile
> \csname NameStack\theFileStack\endcsname
> \addtocounter{FileStack}{-1}%
> }
>
> gives me "This makes 100 errors; please try again"
This coding doesn't seem to have been well-tested with
modern LaTeX. It falls foul of things that happen both
at \begin{document} and \end{document} .
However, it can be easily fixed as follows:
\def\ThisFile{\jobname}
\newcounter{FileStack}
\newcommand{\recordinput}[1]{% <<--- new name
\stackinput{#1}{\OrigInput}%
}
\newcommand{\stackinput}[2]{%
\stepcounter{FileStack}%
\expandafter\let
\csname NameStack\theFileStack\endcsname
\ThisFile
\def\ThisFile{#1}% <<---- \edef might be better here !
#2{#1}%
\expandafter\let\expandafter
\ThisFile
\csname NameStack\theFileStack\endcsname
\addtocounter{FileStack}{-1}%
}
%% delay the re-definition of \input until later
\AtBeginDocument{%
\let\OrigInput\input
\let\input\recordinput
}
%% set it back at the end of the document
\AtEndDocument{\let \input \OrigInput}
> I looked at the reference, patching techniques, but this is way
> beyond the little bit I have learned so I am crying for help.
Above is an example of how it should be done.
That is,
(i) define a new function (or "method") to do what you want;
(ii) preserve, using \let , a pointer to the original method;
(iii) use \let to rebind the macro-name to your new method,
delaying to a time when it is safe to do so;
(iv) use \let again, to rebind the macro name back to the
original method, after you have finished using your
new method.
Beware though. I've not tested the above instance with a serious job;
nor have I tested for how it works with \include .
>
> Hopeful regards
> --schremmer
>
>
>
>
>
>
> ------------------------- Helpful Info -------------------------
> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
> TeX FAQ: http://www.tex.ac.uk/faq
> List Archive: http://tug.org/pipermail/macostex-archives/
> List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/
>
>
------------------------------------------------------------------------
Ross Moore ross at maths.mq.edu.au
Mathematics Department office: E7A-419
Macquarie University tel: +61 +2 9850 8955
Sydney, Australia 2109 fax: +61 +2 9850 8114
------------------------------------------------------------------------
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/
More information about the MacOSX-TeX
mailing list