This is really annoying. For some reason, tex4ht adds an extra space to the left of each line in the listing when using minted. This does not happen with listings or verbatim. Only with minted. If you think this is not a big deal, it is actually a huge deal. This makes it hard to copy-paste the code from the HTML to the editor, since the results is always shifted by one space, and one has to readjust the code manually.

I see this extra space in all environments I tried. In table, in standalone block. This does not happen with listings and does not happen when using pdflatex. So the issue is with tex4ht or package minted support for tex4ht. I show MWE and the HTML output and the commands used to run the MWE. I am using TL 2015.

\usepackage[utf8]{inputenc} %DO NOT USE WITH LUALATEX, only with pdflatex
\usepackage{upquote} %to fix string quotes

clear all; close all;
t   = 0:0.05:50;
s   = tf('s');
sys = 1/(s^2+0.2*s+1);

Here is the HTML output

Mathematica graphics

Here is screen shot showing what happens when I copy the listing. Notice the extra space in the selection

Mathematica graphics

Here is the HTML source listing generated

<?xml version="1.0" encoding="iso-8859-1" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="http://www.w3.org/1999/xhtml"  
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- xhtml,html --> 
<meta name="src" content="foo.tex" /> 
<meta name="date" content="2016-05-24 16:38:00" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
<div class="fancyvrb" id="fancyvrb1"><a 
class="ectt-1095">&#x00A0;all;</span><br class="fancyvrb" /><a 
class="ectt-1095">&#x00A0;</span><span id="textcolor1"><span 
class="ectt-1095">:</span><span id="textcolor2"><span 
class="ectt-1095">:</span><span id="textcolor3"><span 
class="ectt-1095">;</span><br class="fancyvrb" /><a 
class="ectt-1095">&#x00A0;tf(</span><span id="textcolor4"><span 
class="ectt-1095">);</span><br class="fancyvrb" /><a 
class="ectt-1095">&#x00A0;</span><span id="textcolor5"><span 
class="ectt-1095">1</span></span><span id="textcolor6"><span 
class="ectt-1095">(s^</span><span id="textcolor7"><span 
class="ectt-1095">2</span></span><span id="textcolor8"><span 
class="ectt-1095">+</span></span><span id="textcolor9"><span 
class="ectt-1095">0.2</span></span><span id="textcolor10"><span 
class="ectt-1095">s</span><span id="textcolor11"><span 
class="ectt-1095">+</span></span><span id="textcolor12"><span 

This happens on Firefox and Chrome. It adds #x00A0 at start of each listing line, which is a non-breaking space.

Here is the pdf output

Mathematica graphics

To compile the MWE with htlatex:

   htlatex foo.tex "" "" "" -shell-escape

If you get an error missing pygments, the command to install it is either

sudo apt-get install python-pygments


 sudo pip install --upgrade pygments

The version I have now is

  pygmentize -V
  Pygments version 2.1.3, (c) 2006-2015 by Georg Brandl.

To compile with make4ht

  make4ht foo.tex "--shell-escape"

To compile with pdflatex

 pdflatex --shell-escape foo.tex

Here is the file listing

 *File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size11.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
   t1enc.def    2005/09/27 v1.99g Standard LaTeX file
inputenc.sty    2015/03/17 v1.2c Input encoding file
    utf8.def    2015/09/07 v1.1p UTF-8 support for inputenc
   t1enc.dfu    2015/09/07 v1.1p UTF-8 support for inputenc
  ot1enc.dfu    2015/09/07 v1.1p UTF-8 support for inputenc
  omsenc.dfu    2015/09/07 v1.1p UTF-8 support for inputenc
   color.sty    2014/10/28 v1.1a Standard LaTeX Color (DPC)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  minted.sty    2015/09/09 v2.1 Yet another Pygments shim for LaTeX
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
fancyvrb.sty    2008/02/07
   float.sty    2001/11/08 v1.3d Float enhancements (AL)
  ifthen.sty    2014/09/29 v1.1c Standard LaTeX ifthen package (DPC)
    calc.sty    2014/10/28 v4.3 Infix arithmetic (KKT,FJ)
ifplatform.sty    2010/10/22 v0.4 Testing for the operating system
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
catchfile.sty    2011/03/01 v1.6 Catch the contents of a file (HO)
etoolbox.sty    2015/08/02 v2.2a e-TeX tools for LaTeX (JAW)
 xstring.sty    2013/10/13  v1.7c  String manipulations (C Tellechea)
  lineno.sty    2005/11/02 line numbers on paragraphs v4.41
  t1cmtt.fd    2014/09/29 v2.5h Standard LaTeX font definitions
 upquote.sty    2012/04/19 v1.3 upright-quote and grave-accent glyphs in verbat
textcomp.sty    2005/09/27 v1.99g Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
  ts1enc.dfu    2015/09/07 v1.1p UTF-8 support for inputenc
  ts1cmr.fd    2014/09/29 v2.5h Standard LaTeX font definitions
 ts1cmtt.fd    2014/09/29 v2.5h Standard LaTeX font definitions

The question is: How to remove the extra space at start of each line in minted listing?

Same example with listings do not have this problem. Here is MWE with listings to proof this:

\usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex

  style              = Matlab-editor,
  breaklines         = false,
  escapechar         = `,
  mlshowsectionrules = true,frame=leftline

\usepackage{upquote} %to fix string quotes
clear all; close all;
t   = 0:0.05:50;
s   = tf('s');
sys = 1/(s^2+0.2*s+1);

tex4ht does not show frames in HTML (may be another bug), but I can see that there is no extra space added looking at the HTML generated, I can copy paste the code from the web page ok, and it is all left aligned when pasted into the text editor. I want the same thing to happen with minted listing as well.

I wanted to see if this a bug in tex4ht before I fill a bug report, as I am not sure now.

TL 2015 on Linux.

  • I just ran make4ht and get no space, there is a css left border but no space in the html file and selecting the block just selects the text flush left Commented May 24, 2016 at 21:33
  • see firefox rendering the html, note the extent of the highlighted area when I select the block does not include the left margin here Commented May 24, 2016 at 21:35
  • 1
    tex4ht doesn't contain any configurations for minted at all, it seems that minted itself inserts two non breaking spaces before each identifier. They are collapsed except at beginning of the line.
    – michal.h21
    Commented May 25, 2016 at 10:45

1 Answer 1


I have same version of minted but get

<div class="lstlisting" id="listing-1"><span class="label"><a 
class="ectt-1095">&#x00A0;</span><br />

note lack of nbsp before clear.

possibly relevant is pygmentize version

$ pygmentize -V
Pygments version 2.0.2, (c) 2006-2014 by Georg Brandl.
  • Thanks. I did install pygmentize now myself. It has older version 1.6. I'll see how to get the newer version. I did use apt-get install python-pygments to install it, which should install the latest version. I'll see what I can do and will update if I can upgrade it.
    – Nasser
    Commented May 24, 2016 at 22:02
  • I am afraid that did not fix it. I upgraded actually to 2.1.3 (using pip) and recompiled, and still see the extra space. pygmentize -V gives Pygments version 2.1.3, (c) 2006-2015 by Georg Brandl. and which pygmentize gives /usr/local/bin/pygmentize may be it is python itself? I have 2.7.6 on my Linux mint., Not 3. This is by default. If you have other ideas to try, will be happy to.
    – Nasser
    Commented May 24, 2016 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .