I am looking for wisdom i.e. potential side-effects that I may not have considered.. Underscores are quite common and irritating for inexperienced LaTeX users to escape. Let's assume that I have no interest in subscript of math mode. Is it safe to set underscore to a non-active character?
By default _ is for subscript and you need to convert it to a literal character by prefixing it with a catcode 0 \.
Is there any danger of making life easier by putting this in my document?
Category 12 Other Character
\catcode`\_=12 %
\catcode`_=12 %
\catcode"005F=12 % unicode decimal syntax
\catcode'137=12 % octal syntax
\catcode95=12 % decimal syntax
or
Category 11 Alphabetic Character
\catcode`\_=11 %
\catcode`_=11 %
\catcode"005F=11 % unicode decimal syntax
\catcode'137=11 % octal syntax
\catcode95=11 % decimal syntax
My thought is that it would not be if done at the right time (after loading all packages).
Notes
- I am using
xelatexwithfontspec, therefore I ensure that all of my documents are UTF-8 encoded. etocadds stuff to the\contentslinewhich means that the catcode of underscore must be changed prior to definition time of these macros, otherwise when the .toc is read after\begin{document}on the following run, an underscore will be read as catcode 8 within the\contentslinemacro even if you set it later, because the group protects any postdefinition changes.
T1encoding. Otherwisea_bwould producea ̇b, rendering the_as a raised dot. – egreg Mar 22 '17 at 12:24fontspec. – Jonathan Komar Mar 22 '17 at 12:25\catcode`\<char>=12is equivalent to\catcode`<char>=12(unless<char>has category code 0, 5, 9 or 15). – egreg Mar 22 '17 at 12:27\begin{document}macro. It is not enough to just set the catcode after\begin{document}. – Jonathan Komar Mar 22 '17 at 12:51\catcode'=12 % octal syntaxdid you mean\catcode'137=rather than\catcode'=(which is a syntax error) – David Carlisle Mar 22 '17 at 12:57.auxfile is read in at begin document. So the catcode change has to be done before. – egreg Mar 22 '17 at 13:00