-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
Tabulation characters from files which get inserted using literalinclude end up "as is" both in the .html and in the .tex file produced by the respective builders.
In the PDF they get converted to 8 spaces, independently of their location.
This is in contrast with viewing the HTML where at least with my Firefox the rendering uses tab stops every 8 characters. Note though that I have found no tab-size setting for <pre> in the CSS files (when building the MWE below) so this may be browser dependent. Indeed, I am ignorant if there is a universal convention that in absence of tab-size, tab stops inside <pre> are every 8 characters.
Important: here we do not use :tab-width: option. If using that option tabs are converted to spaces both with LaTeX and HTML and the outputs match one another with tab stops matching the option (only tested with :tab-width: 8).
How to Reproduce
.. literalinclude:: filewithtabs.txt
with filewithtabs.txt being
============================
LINUX KERNEL MEMORY BARRIERS
============================
hello where are little tabs gone?
PDF output:
HTML:
Environment Information
Platform: darwin; (macOS-15.7.2-arm64-arm-64bit-Mach-O)
Python version: 3.13.3 (v3.13.3:6280bb54784, Apr 8 2025, 10:47:54) [Clang 15.0.0 (clang-1500.3.9.4)])
Python implementation: CPython
Sphinx version: 8.3.0+/5d0ad1686
Docutils version: 0.22.4b1.dev
Jinja2 version: 3.1.6
Pygments version: 2.19.1
Sphinx extensions
Additional context
Tested with Docutils 0.22.3 and 0.21.2.
This issue was originally reported at #13656 (comment) by @akiyks.
Note that as work-around it is enough to add :tab-width: 8 option to the literalinclude directive. Then the .tex file (and also .html) will contain only spaces, matching tab-stops at each multiple of 8 characters.