I've written several LaTeX environments to format a "use case flow" sequence for a college project. Being a computer programmer, I find quite annoying to not be able to use newlines and indentation (like C/Java code) to format the LaTeX code and make it more readable, as I know I must be aware of the "spurious spaces" problem. I know I can make safe newlines using %
, but it's still quite weird.
Then, I remembered that each character read by TeX has assigned a 'catcode' that governs its behavior, and there's a catcode for characters that must be ignored (9). So, I had the idea of changing temporally the catcodes for newlines and tabs (that will be used for code formatting) and ignore them while the macros are being defined. For example, this code:
% UCSubFlow counter definition, etc
\newenvironment{subflow}[1]{%
\subparagraph{Subflow \arabic{UCSubFlow}: #1}%
\stepcounter{UCSubFlow}%
\begin{enumerate}%
}{%
\end{enumerate}%
}
becomes the, IMO, more pleasing to read:
% Ignore tabs and newlines
\catcode9=9
\catcode13=9
% UCSubFlow counter definition, etc
\newenvironment{subflow}[1]{
\subparagraph{Subflow \arabic{UCSubFlow}: #1}
\stepcounter{UCSubFlow}
\begin{enumerate}
}{
\end{enumerate}
}
% More macro definitions...
% Return tabs and newlines back to normal
\catcode9=10
\catcode13=5
The spacing at the start of the line are tabs, not spaces (they are still used). I'm assuming that:
- Most of the time, macros don't use
<tab>
s in its definition - Most of the time, macros don't have large paragraphs of text. If I want to start a paragraph in my macro, it's better to use
\par
- Macros always can be written in one line (very long ones, but one line anyway)
I've used it in my document and it seems to be all OK. The environment works as expected and it doesn't seems to have broken anything. Granted, my environment is quite simple (an special list). My question is: is this 'hack' safe in general when it comes to macro writing, of there is some hidden danger? (specially if I use other packages' macros inside my macro)