4

Should I make it a habit to use spaces instead of tabs when indenting? Casual use of tabs didn't cause problems but so far I experienced a few niche cases where using tabs leads to unexpected behavior. Upon debugging and extensive research I realize that it is because of some esoteric stuff that makes it seem insisting on using tabs not worth it.

psmears
  • 141
  • 6
    Can you be more specific? I almost always use real tabs, and never ran into problems. LaTeX should treat all forms of whitespace equally, too. – Ingmar Nov 08 '22 at 06:47
  • 1
    Welcome to TeX.SX! In order to better understand your question, please post an example where tabs lead to unexpected results and maybe explain more why you think that this is. In general, tabs should not break LaTeX code. – Jasper Habicht Nov 08 '22 at 08:38
  • 1
    For what it's worth, the LaTeX3 style guide for contributors mentions that "tabs should not be used for introducing white space". This is not a general style recommendation for all code written in LaTeX though, it is specific for people developing the core L3 packages. – Marijn Nov 08 '22 at 08:43
  • I personally avoid making this style choice by not indenting at all, for example a table-tabular combination or a frame-itemize-minted structure in Beamer are flat in my code. I indent only when it may get confusing, like a double or triple nested enumerate or something. – Marijn Nov 08 '22 at 08:52
  • Yes some package writers don't handle this case e.g. https://tex.stackexchange.com/questions/508001/keyboard-tab-character-in-argument-v-xparse/508103#508103. But this generally applies to everything, packages may have bugs where package authors does not use the feature. – user202729 Nov 08 '22 at 17:21
  • 2
  • By the way what are the cases where you get error? Might worth mention what you have researched and figured out. – user202729 Nov 08 '22 at 17:26

2 Answers2

7

By default, tabs and spaces (characters 9 and 32) have catcode 10, so at the start of a line (and after control sequences) they are ignored, and elsewhere they always make a space token (32), never a tab.

So you can indent with tab or space; both are ignored.

David Carlisle
  • 757,742
2

Welcome to TeX.SX! If you are talking about the layout of input file, Tab or Space may make some difference. However, when you compile your file, any combination of tabs and spaces reduces to precisely one space. (Of course, the size of space depends upon where does it occur, e.g. inter-word spaces are smaller than inter-sentence spaces.)

  • 1
    for indentation, as asked in the question, spaces and tabs are at the start of a line, so are ignored, they do not make one space. – David Carlisle Nov 08 '22 at 12:31