Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a "hook" for \include?

35 views
Skip to first unread message

Ivan Shmakov

unread,
Sep 4, 2012, 2:14:13 PM9/4/12
to
BTW, is there an easy way to invoke an arbitrary TeX macro just
before a file is read within \include? The macro is to be
called with either the filename, or just the \include argument
(i. e., without the .tex suffix.)

TIA.

--
FSF associate member #7257 http://sfd.am-1.org/

Enrico Gregorio

unread,
Sep 4, 2012, 3:46:01 PM9/4/12
to
Ivan Shmakov <onei...@gmail.com> wrote:

> BTW, is there an easy way to invoke an arbitrary TeX macro just
> before a file is read within \include? The macro is to be
> called with either the filename, or just the \include argument
> (i. e., without the .tex suffix.)

\let\latexinclude\include
\def\include#1{\macro{#1}\latexinclude{#1}}

You may write also \macro{#1.tex} if you need the complete
file name (.tex is implicitly added for \include).

Ciao
Enrico

Ivan Shmakov

unread,
Sep 5, 2012, 12:56:48 AM9/5/12
to
>>>>> Enrico Gregorio <Facile.d...@in.rete.it> writes:
>>>>> Ivan Shmakov <onei...@gmail.com> wrote:

>> BTW, is there an easy way to invoke an arbitrary TeX macro just
>> before a file is read within \include? The macro is to be called
>> with either the filename, or just the \include argument (i. e.,
>> without the .tex suffix.)

> \let\latexinclude\include
> \def\include#1{\macro{#1}\latexinclude{#1}}

There's a catch: this way, \macro will be invoked before
\clearpage (which is in turn invoked by \include before doing
\input) and thus may be unfit for my purposes. (I hope to check
it shortly.)

> You may write also \macro{#1.tex} if you need the complete file name
> (.tex is implicitly added for \include).

Actually, I'd need to strip leading directories of the filename
instead. I guess I can, e. g.:

\def \@basename #1/#2\@endbasename {%
#2}

But I'm curious, is there be a predefined LaTeX macro to do
that? (I believe there is, but it's probably undocumented.)

Alain Ketterlin

unread,
Sep 5, 2012, 2:22:16 AM9/5/12
to
The filehook package provides hooks that let you run arbitrary code
before/after many file inclusion mechanisms. The currfile package is a
wrapper around filehook (afaiu) that keeps file paths around.

-- Alain.

Heiko Oberdiek

unread,
Sep 5, 2012, 2:24:34 AM9/5/12
to
Ivan Shmakov <onei...@gmail.com> wrote:

> >>>>> Enrico Gregorio <Facile.d...@in.rete.it> writes:
> >>>>> Ivan Shmakov <onei...@gmail.com> wrote:

> > \let\latexinclude\include
> > \def\include#1{\macro{#1}\latexinclude{#1}}

> Actually, I'd need to strip leading directories of the filename
> instead. I guess I can, e. g.:
>
> \def \@basename #1/#2\@endbasename {%
> #2}
>
> But I'm curious, is there be a predefined LaTeX macro to do
> that? (I believe there is, but it's probably undocumented.)

\documentclass{article}
\makeatletter
\newcommand*{\orig@include}{}
\let\orig@include\include
\renewcommand*{\include}[1]{%
\filename@parse{#1}%
\orig@include{\filename@base}%
}
\makeatother

\begin{document}
\include{abc/inc}
\end{document}

--
Heiko Oberdiek

Ivan Shmakov

unread,
Sep 5, 2012, 8:07:45 AM9/5/12
to
>>>>> Alain Ketterlin <al...@dpt-info.u-strasbg.fr> writes:
>>>>> Ivan Shmakov <onei...@gmail.com> writes:

[...]

>> Actually, I'd need to strip leading directories of the filename
>> instead. I guess I can, e. g.:

>> \def \@basename #1/#2\@endbasename {%
>> #2}

>> But I'm curious, is there be a predefined LaTeX macro to do that?
>> (I believe there is, but it's probably undocumented.)

> The filehook package provides hooks that let you run arbitrary code
> before/after many file inclusion mechanisms. The currfile package is
> a wrapper around filehook (afaiu) that keeps file paths around.

That's it, thanks!

What's even better is that currfile also splits the filename
into its leading directories, prefix and suffix parts.
0 new messages