I would like to configure a custom command so that it only affects the document environment. Because the command changes a number of catcodes, it has to be included after the begin{document} tag in order to work properly. However, I would prefer to set it up so that I can include it in its own .sty file. Is there some way to define a command so that it is only active within the document environment?
The type of code that I am trying to use is similar to the following:
\AtBeginDocument{
\catcode`\_=13 \def_#1_{\emph{#1}}
}
When I typeset the document with the \AtBeginDocument command, the console stops at the \begin{document} line and notes the following:
Missing control sequence inserted.
<inserted text>
\inaccessible
If I include the code (without the \AtBeginDocument{} rule) after the \begin{document} command, however, the document will process correctly.