[Tex/LaTex] How to disable new paragraph at empty line

paragraphs

With the goal of making the latex source easier to parse, I was wondering if one could (locally or globally) disable the latex default behaviour of creating a new paragraph when it encounters an empty line.

Obviously, I can always just put a % on empty lines when I don't want a paragraph. Nevertheless, I was wondering if there is a different solution.

Finally, I would also like to know if such an alternative solution would be considered good form or not.

Best Answer

The blank-line-gives-new-paragraph mechanism works on a lower level than LaTeX; it is TeX. You may want to read sections 2.5 and 2.9 of TeX by Topic. There are basically two possibilities, both of which should certainly be confined to a group.

  1. Redefine \par, for example \let\par\relax
  2. Redefine \endlinechar to be 32, so that the actual (platform-dependent) end-of-line-marker(s) are replaced by a space token. You can also set it to some value outside the range 0-255, meaning that nothing will be inserted in the input stream.

In both cases, note that if a line ends with a control sequence, one has to take care of spaces in the output. You can also mess around with catcodes, but I'm not sure what would be gained by this compared to 1. and 2 (except perhaps that the space-issue would be easier to solve).

This said, to answer your final question: No, I certainly don't think it's a good idea. In code that no one but you will see you can of course do anything, but as soon as you need to collaborate on some projects, tricks such as these can cause quite a lot of confusion. The standard way of increasing readability while preventing insertion of \par tokens is the one you describe. The % doesn't actually have to appear as the very first character; spaces before it are automatically ignored. This can be useful if you use indentation inside environments:

\begin{align}
  something &= some complicated expression \\
  %
  other &= more complicated stuff
\end{align}
Related Question