💾 Archived View for gemi.dev › gemlog › 2023-06-22-preformatted-tabs.gmi captured on 2023-07-10 at 13:34:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

Don't use Tabs with Preformatted text in Gemtext

2023-06-22 | #weird | @Acidus

You can't depend on how tabs will be rendered in preformatted text blocks. You probably shouldn't use tabs in your preformatted text blocks. You should convert tabs into spaces and use that in preformatted text blocks in Gemtext.

Tabs and Spaces

A tab is a single character, ASCII code 9. Text programs are free to decide how to render a tab. Historically, on computers, tabs were rendered as 8 whitespace characters (ASCII code 32). More modern programs allow you to change this, or default to another number like 4.

Gemipedia: Tab Key

Different Gemini clients render tabs differently:

Amfora using 4 characters when rendering a tab

Lagrange using 8 characters when rendering a tab

In general Different programs will do different things:

cat using 8 characters when rendering a tab

TextMate using 4 characters when rendering a tab

While some clients allow you to configure tab width, including Lagrange, the default may be different than what you think, and this pushes the problem on the user to solve.

If you want to see how different clients behave, I have a test page you can use:

Tabs and Spaces test page

If you leave tabs in your preformatted text, it isn't really preformatted anymore, since you don't know how it will be rendered. Just use spaces instead.

Mixing Tabs and Spaces

Problems also come when you mix tabs and spaces. This seems easy to avoid. Just use 1 or the other. But I found that TextMate, the GUI editor I use on my Mac, can do this without you noticing:

    I wrote this with 4 spaces at the start
	To get to this line, I clicked enter. However, the start of this line is a single tab character
     I wrote this with 5 spaces at the start
	 To get to this line, I clicked enter. However, the start of this line is 1 tab and 1 space.

This output looks normal in my editor, but this mix of spaces and tabs causing things that look lined up to be rendered strangely, as shown in the images above. The shear diversity of programs out there means this happens in other places too.

Turns out there is a setting in TextMate to control this behavior, but the default is to do this. A better solution may be to configure your text editor to replace tabs with the appropriate number of spaces automatically. Turns out your can do this in TextMate, and I assume other editors too:

img/tabs-configure.png

I've added a note about tabs and preformatted text to my Gemini Weirdness page as well:

Oddities with Gemini, Gemtext, and Geminispace

Friends don't let friend use tabs in preformatted text. Friends don't let friends use 8 character tabs either, but that's a fight for another day 😂.