What is a Tab Character?
A tab character (typically symbolized \t
) is a character of text typed by pressing the Tab key in text editors that support it. A tab character is similar to a space character in that it doesn't have a glyph. Instead, when a tab character is found in text, a certain amount of horizontal space is added to the line, which can vary according to which column of text the tab character was found at.
In its simplest usage, the tab character is inserted at the start of a line to add indentation to the line. If the tab size is 8 columns, for example, a single tab character will have the width of 8 space characters in a monospaced font. I'm not sure how large it will be on other fonts.
If a tab character is inserted in the MIDDLE of a line, it has the function of tabulation, i.e. of creating tables. That's probably why it's called a tab character in first place. For example, if the tab size is 8 columns, and the tab is found at column 12, the tab character will have the width of 4 spaces. That's because its purpose is to align the text. Imagine the text is a grid and there is 1 vertical line every 8 characters. So we have a line at the start, a line at the 8th character, and a line at the 16th character. The purpose of the tab is to "round up" to this next vertical line. This means the tab character's width can be anywhere from 1 to 8 columns in this case.
Making Tabs Visible
In source code editors, it's often possible to make spaces and tabs, which are normally invisible, visible.
The reason for this is that, although most programming languages have insignificant whitespace, there are some languages like Python where whitespaces matter, and mixing tabs and spaces, or having a wrong number of spaces, or tabs, creates problems.
Leave a Reply