I was working on my own document template for the first time and I came up with a question that I couldn't find the answer online.

I was writing spaces between elements (see example beneath) but I realized I didn't know whether it could break anything or if it was considered bad practice for some reason. My compiler didn't mind but that was only a single line, it might react otherwise for other commands.

% What I want to write
\documentclass[12 pt, letterpaper, fleqn] {article}

% What I normally see when searching online

Is there any of the spaces that I included that should never be there for some reason and is there any that doesn't matter at all?

  • No, there is no problem with spaces in this context (they are ignored), as they will be with \usepackage options. But in other contexts (like macros in the document) the spaces may or may not be ignored. Also, when defining macros, spaces that you don't want can creep into the definition, since the end of a line is treated as a space. See What is the use of percent signs (%) at the end of lines?. – Alan Munn May 18 '19 at 23:17
  • So, best practice would be to avoid spaces outside of \documentclass and \usepackage options? – PierreLuc May 18 '19 at 23:31
  • @PierreLuc in general spaces are like letters you need them to separate words, so they should be avoided in places where a letter should be avoided as it would produce typeset output \fbox{ a } is not the same as \fbox{a} just as x a x is not the same as xax, but which is correct only the author can know. – David Carlisle May 18 '19 at 23:42
  • Oh, that makes a lot of sense, thank you! – PierreLuc May 18 '19 at 23:45

The space after (or before) commas are ignored by design, and is shared by any similar comma list in latex. The fact that you can have ignored spaces within an option name like 12 pt or let terpa per is an unfortunate side effect of the technique used to ignore spaces around commas and is not generally true of comma separated arguments (eg those of \includegraphics) and should not be assumed to always hold for \documentclass.


\documentclass[12 pt, letterpaper, fleqn] {article}

is bad style but

               12pt , letterpaper,
              ] {article}

is fine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.