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

Replacing a command at the end

24 views
Skip to first unread message

Sensei

unread,
May 22, 2013, 10:07:49 AM5/22/13
to
Dear all,

this might sound weird, but I ask: can I "replace" an environment ending
string? In particular, I'd like to add something before \end{document}!


So in something like:


\documentclass[11pt, oneside]{article}
\title{Brief Article}
\author{The Author}

\begin{document}
Hello.

\end{document}



I'd like to add a command *before* the end, something like an override
of \end{document}, let's say that it should behave like this:


\documentclass[11pt, oneside]{article}

% HERE SOME MAGIC TRICK

\title{Brief Article}
\author{The Author}

\begin{document}
Hello.


\maketitle
\end{document}



Is it possible?


Thanks & Cheers!

GL

unread,
May 22, 2013, 10:32:50 AM5/22/13
to
Le 22/05/2013 16:07, Sensei a �crit :
> Dear all,
>
> this might sound weird, but I ask: can I "replace" an environment ending
> string? In particular, I'd like to add something before \end{document}!

{document} is not an environment... it is just like
an environment (starting with \begin and ending with \end).

For document, you can use \AtEndDocument (LaTeX2e)
and its variants: \AtVeryEndDocument and \AfterLastShipout
in atveryend.sty and \AfterEndDocument in etoolbox.sty

For a real environment, you can use \AtEndEnvironment and
\AfterEndEnvironment in etoolbox.sty.
But don't use: \AtEndEnvironment {document} nor
\AfterEndEnvironment {document}
just remind that {document} is not an environment.

Regards.

Lee Rudolph

unread,
May 22, 2013, 11:02:20 AM5/22/13
to
Sensei <sensei.wa...@apple.me.com> writes:

>Dear all,
>
>this might sound weird, but I ask: can I "replace" an environment ending
>string? In particular, I'd like to add something before \end{document}!

Analogously to \renewcommand, there is \renewenvironment;
once you find the code (wherever it may be) for the environment
you want to "replace", you can copy it, modify it (in particular,
modify its final argument, which is the "ending string"), and
put your modified code into \renewenvironment.

There may be pitfalls in some cases; so far I have avoided them
but I can't swear you will.

Lee Rudolph

Sensei

unread,
May 22, 2013, 11:28:24 AM5/22/13
to
On 5/22/13 4:32pm, GL wrote:
> For document, you can use \AtEndDocument (LaTeX2e)
> and its variants: \AtVeryEndDocument and \AfterLastShipout
> in atveryend.sty and \AfterEndDocument in etoolbox.sty
>
> For a real environment, you can use \AtEndEnvironment and
> \AfterEndEnvironment in etoolbox.sty.
> But don't use: \AtEndEnvironment {document} nor
> \AfterEndEnvironment {document}
> just remind that {document} is not an environment.


That's awesome, thanks! I didn't (obviously) know of \AtEndDocument!

By the way, if document isn't an environment (but behaves and looks like
one), what is then, technically?


Cheers!

Sensei

unread,
May 22, 2013, 11:29:38 AM5/22/13
to
Thanks Rudolph. What pitfall might I get into, just for being paranoid?

Robin Fairbairns

unread,
May 22, 2013, 12:19:56 PM5/22/13
to
the pitfall is thinking you can patch \end{document}.
--
Robin Fairbairns, Cambridge

GL

unread,
May 22, 2013, 12:37:32 PM5/22/13
to
Le 22/05/2013 17:28, Sensei a �crit :
>
> That's awesome, thanks! I didn't (obviously) know of \AtEndDocument!
>
> By the way, if document isn't an environment (but behaves and looks like
> one), what is then, technically?

Roughly speaking, an environment is the LaTeX concept for
TeX : \begingroup ... \endgroup so that :

\begin{envir} ... \end{envir} is pseudo-equivalent to:
\begingroup \envir ... \endenvir \endgroup

While \begin{document} ... \end{document} is pseudo-equivalent to :
\document ... \enddocument

so that \begin{document} is the command : \document
and \end{document} is the command : \enddocument
and finally {document} is not an environment, even if
it mimicks the syntax... I'm almost sure this is the only
exception (even if the grouping may be more complex in some
environment, for example {lrbox}).

Regards.
0 new messages