这真的很烦人。出于某种原因,tex4ht 在使用 minted 时会在列表中的每一行左侧添加一个额外的空格。这不会发生在 listings 或 verbatim 中。只有 minted 才会发生。如果你认为这不是什么大问题,那么它实际上是一个巨大的处理。这使得将代码从 HTML 复制粘贴到编辑器变得很困难,因为结果总是会偏移一个空格,因此必须手动重新调整代码。
我在尝试的所有环境中都看到了这个额外的空间。在表格中,在独立块中。这不会发生在列表中,也不会在使用 pdflatex 时发生。因此问题出在 tex4ht 或对 tex4ht 的包 minted 支持上。我展示了 MWE 和 HTML 输出以及用于运行 MWE 的命令。我使用的是 TL 2015。
\documentclass[11pt]{article}%ext
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %DO NOT USE WITH LUALATEX, only with pdflatex
\usepackage{color}
\usepackage{minted}
\usepackage{upquote} %to fix string quotes
\setlength\parindent{0pt}
\begin{document}
\begin{minted}[linenos=false,fontfamily=tt,frame=leftline,
showspaces=false,stripall=true,xleftmargin=0pt]{matlab}
clear all; close all;
t = 0:0.05:50;
s = tf('s');
sys = 1/(s^2+0.2*s+1);
\end{minted}
\end{document}
以下是 HTML 输出
以下是我复制列表时发生的屏幕截图。请注意选择中的额外空格
以下是生成的 HTML 源列表
<?xml version="1.0" encoding="iso-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head><title></title>
<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" />
</head><body
>
<div class="fancyvrb" id="fancyvrb1"><a
id="x1-7r1"></a><span
class="ectt-1095"> </span><span
class="ectt-1095"> clear</span><span
class="ectt-1095"> all;</span><span
class="ectt-1095"> close</span><span
class="ectt-1095"> all;</span><br class="fancyvrb" /><a
id="x1-9r2"></a><span
class="ectt-1095"> </span><span
class="ectt-1095"> t</span><span
class="ectt-1095"> </span><span
class="ectt-1095"> </span><span
class="ectt-1095"> =</span><span
class="ectt-1095"> </span><span id="textcolor1"><span
class="ectt-1095">0</span></span><span
class="ectt-1095">:</span><span id="textcolor2"><span
class="ectt-1095">0.05</span></span><span
class="ectt-1095">:</span><span id="textcolor3"><span
class="ectt-1095">50</span></span><span
class="ectt-1095">;</span><br class="fancyvrb" /><a
id="x1-11r3"></a><span
class="ectt-1095"> </span><span
class="ectt-1095"> s</span><span
class="ectt-1095"> </span><span
class="ectt-1095"> </span><span
class="ectt-1095"> =</span><span
class="ectt-1095"> tf(</span><span id="textcolor4"><span
class="tctt-1095">'</span><span
class="ectt-1095">s</span><span
class="tctt-1095">'</span></span><span
class="ectt-1095">);</span><br class="fancyvrb" /><a
id="x1-13r4"></a><span
class="ectt-1095"> </span><span
class="ectt-1095"> sys</span><span
class="ectt-1095"> =</span><span
class="ectt-1095"> </span><span id="textcolor5"><span
class="ectt-1095">1</span></span><span id="textcolor6"><span
class="ectt-1095">/</span></span><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">*</span></span><span
class="ectt-1095">s</span><span id="textcolor11"><span
class="ectt-1095">+</span></span><span id="textcolor12"><span
class="ectt-1095">1</span></span><span
class="ectt-1095">);</span></div>
</body></html>
这发生在 Firefox 和 Chrome 上。它会#x00A0
在每行列表的开头添加一个non-breaking space
。
这是 pdf 输出
要使用 htlatex 编译 MWE:
htlatex foo.tex "" "" "" -shell-escape
如果出现缺少 pygments 的错误,则安装它的命令是
sudo apt-get install python-pygments
或者
sudo pip install --upgrade pygments
我现在拥有的版本是
pygmentize -V
Pygments version 2.1.3, (c) 2006-2015 by Georg Brandl.
使用 make4ht 进行编译
make4ht foo.tex "--shell-escape"
使用 pdflatex 进行编译
pdflatex --shell-escape foo.tex
以下是文件列表
*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)
fontenc.sty
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)
foo.w18
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
_minted-foo/default.pygstyle
upquote.sty 2012/04/19 v1.3 upright-quote and grave-accent glyphs in verbat
im
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
supp-pdf.mkii
_minted-foo/default-pyg-prefix.pygstyle
_minted-foo/8B1797CACBEAE0182873B791A4E19C297F3EB64B19343B31CD11188E85C1F8D3.py
gtex
ts1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions
***********
问题是:如何删除铸造列表中每行开头的多余空格?
带有列表的相同示例不存在此问题。以下是带有列表的 MWE 以证明这一点:
\documentclass[11pt]{article}%ext
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex
\usepackage{matlab-prettifier}
\lstset{
style = Matlab-editor,
basicstyle=\ttfamily\normalsize,
breaklines = false,
escapechar = `,
mlshowsectionrules = true,frame=leftline
}
\usepackage{upquote} %to fix string quotes
\setlength\parindent{0pt}
\begin{document}
\begin{lstlisting}
clear all; close all;
t = 0:0.05:50;
s = tf('s');
sys = 1/(s^2+0.2*s+1);
\end{lstlisting}
\end{document}
tex4ht 不显示 HTML 中的框架(可能是另一个错误),但我可以看到不增加了额外的空间,看看生成的 HTML,我可以从网页复制粘贴代码,粘贴到文本编辑器中时,代码全部左对齐。我希望 minted listing 也能发生同样的事情。
在填写错误报告之前,我想看看这是否是 tex4ht 中的错误,因为我现在不确定。
Linux 上的 TL 2015。
答案1
我有相同版本的 minted,但是
<div class="lstlisting" id="listing-1"><span class="label"><a
id="x1-2r1"></a></span><span
class="ectt-1095">clear</span><span
class="ectt-1095"> </span><span
class="ectt-1095">all</span><span
class="ectt-1095">;</span><span
class="ectt-1095"> </span><span
class="ectt-1095">close</span><span
class="ectt-1095"> </span><span
class="ectt-1095">all</span><span
class="ectt-1095">;</span><span
class="ectt-1095"> </span><br />
注意,clear 之前缺少 nbsp。
可能相关的是 pygmentize 版本
$ pygmentize -V
Pygments version 2.0.2, (c) 2006-2014 by Georg Brandl.