6

I have been using LaTeX for about a year now, and I quite like it.

However, I like to space out my source code. In most languages, this doesn't cause an issue, as extra newlines don't affect meaning.

However, in LaTeX, two newlines in fact changes the document, by creating a new paragraph.

I'm wondering, is there a way to turn this feature off in latex, and require me to specify new paragraphs manually? If not, is there an alternative to LaTeX (preferably similar i.e. still TeX based) which isn't so sensitive?

6
  • You can always specify new paragraphs by \par. May 10, 2013 at 16:40
  • 2
  • 5
    You could say \endlinechar=32; this would avoid the problem of empty lines, but not that of spaces, of course. Ignoring spaces in TeX's source code would require you to manually insert some different character for it. The main problem is that in a printed document one does want spaces.
    – egreg
    May 10, 2013 at 16:44
  • I like that solution. I don't really want to avoid spaces, manually inserting them would be a hassle. I guess to me they're less intrusive, since most languages use spaces to separate tokens anyways.
    – jmite
    May 10, 2013 at 17:12
  • 1
    @jmite Can you show a couple of examples of what you have in mind?
    – egreg
    May 10, 2013 at 17:35

1 Answer 1

17

The conversion of two consecutive newlines to a \par token comes from TeX's parser and so all formats of TeX (plain, LaTeX, ConTeXt) observe it too.

Note that \par gobbles all whitespace until the next non-whitespace token, so three or more consecutive newlines have the same effect as two: one new paragraph. So if you want to have three blank lines before every \section and four before every \chapter you won't get multiple blank paragraphs.

The usual way to avoid unintentional whitespace is to use comment characters (%). A comment character ignores all whitespace until the end of the line. So lines that start with comment characters insert no whitespace.

Look
%
%
ma,
%
%
no
%
new
%
paragraphs!

sample code output

The only spaces in the above come from the newlines. If you added comments at the end of the rest of the lines you would have no whitespace at all!

Look%
%
%
ma,%
%
%
no%
%
white%
%
spaces!

sample code output

2
  • 1
    This certainly works, and in all reality is what I will probably do. It just seems hacky and awkward, despite being the widespread solution.
    – jmite
    May 10, 2013 at 17:13
  • @jmite: the only place I find it difficult is in macro programming, where a newline betwee opening brace and replacement text can introduce extra space. Someday we'll all be uising expl3 syntax for macros, though, and from what I understand all white space is ignored there. :) May 10, 2013 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .