Windows 10 will reach EOS (end of support) on October 14, 2025. For more information, see this article.

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

How to control rendering of tab character in a TXT file?

  • 7 replies
  • 3 have this problem
  • 37 views
  • Last reply by OldNerd

more options

When I browse a TXT file, the tab character is rendered so as to look much like 8 spaces. Is there a way to control the apparent number of spaces in the rendering? Yes, I know that things like

               pre { tab-size: 4 }

in CSS3 would control that number in the rendering of HTML elements, but I want similar control for a TXT file.

When I browse a TXT file, the tab character is rendered so as to look much like 8 spaces. Is there a way to control the apparent number of spaces in the rendering? Yes, I know that things like pre { tab-size: 4 } in CSS3 would control that number in the rendering of HTML elements, but I want similar control for a TXT file.

Chosen solution

Or if you want to use CSS, this bookmarklet will insert the style rule into the page:

javascript:var r="pre{-moz-tab-size:4;}"; var s=document.createElement("style"); s.type="text/css"; s.appendChild(document.createTextNode(r)); document.body.appendChild(s); void 0;

(Note that at least for now, you need the -moz- prefix on tab-size in Firefox.)

Read this answer in context 👍 1

All Replies (7)

more options

The only way to achieve this would be to open the text file in the Scratchpad.

Then you can control the tab width via the devtools.editor.tabsize pref on the about:config page.

more options

Thank U, cor-el. Unfortunately, my reason for wanting to control the apparent size of tab characters when browsing TXT is that I want control how they print when I print what I am browsing. I fired up Scratchpad and found that it ignores Ctrl-P and has no [Print] button anywhere.

I grew up in a hard-copy world, and I still sometimes like to read my code on paper. I like Editra for editing, but not for printing. I had tentatively decided to switch to hard tabs for indentation, but then I realized that printing from Notepad would stick me with tab characters that look 8 spaces wide, as would printing from Firefox. Bleh.

Maybe I should work out a hack for temporarily populating a pre element in HTML with whatever code I want to print.

more options

It is likely that there are other editors that allow to set the tab width.

more options

You can set in Firefox to use which program to use for viewing the page source:

I case of problems you can test the path with this code in the Browser Console (Firefox/Tools > Web Developer; Ctrl+Shift+J)

viewSourceAppPath = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch)
.getComplexValue("view_source.editor.path",Components.interfaces.nsIFile);
viewSourceAppPath.path;

more options

If the tabs are not used for positioning but just indenting, you could run a replace of each tab character with 4 spaces using a bookmarklet:

javascript:void(document.body.innerHTML = document.body.innerHTML.replace(/\t/g, "    "));
more options

Chosen Solution

Or if you want to use CSS, this bookmarklet will insert the style rule into the page:

javascript:var r="pre{-moz-tab-size:4;}"; var s=document.createElement("style"); s.type="text/css"; s.appendChild(document.createTextNode(r)); document.body.appendChild(s); void 0;

(Note that at least for now, you need the -moz- prefix on tab-size in Firefox.)

more options

Many thanks to jscher2000 for the CSS bookmarklet, which solves my specific problem and can be generalized to do many other things. Thanks also to cor-el and jscher2000 for other helpful comments. I may well want to change the editor used to view page source some time in the future.

Let me clear up a possible misunderstanding. Editra, my current favorite editor, does allow setting the tab width and choosing between hard and soft tabs. Altho very customizable in most respects, Editra will not let me set margins or headers/footers when printing. So I have been printing from Notepad and have gotten used to not having line numbers in printouts. By printing code as TXT browsed by Firefox and applying the CSS bookmarklet, I will get even more control over headers/footers, as well as the ability to print hard tabs of width other than 8.