因此,我尝试编写几行代码来向新生解释在哪里可以找到不同的文件和目录。由于班级名称每年都会更改,因此我设置了一个,\newcommand
以便可以同时更改文档中的每个班级名称。这是我的文档的样子:
\documentclass[11pt]{paper}
\usepackage[formats]{listings}
\usepackage{hyperref, xcolor, graphicx}
\lstnewenvironment{lst} %Code-environment
{\lstset{basicstyle=\ttfamily\color{magenta},escapechar={§}}}{}
\newcommand{\class}{g2014048} %Classname
\begin{document}
\begin{lst}
$ cd /proj/§\class§
\end{lst}
\end{document}
当渲染成看起来.pdf
不错时,所有内容都在一行上:
$ cd /proj/g2014048
但是当我稍后htlatex
在终端中使用 -command 创建.html
每个“ \class
”时,如果出现以下情况,则会提前换行:
$ cd /项目/
g2014048
因为它是一行代码,所以我.html
也希望它是这样。我该怎么做?
答案1
这显然是tex4ht
列表支持中的一个错误。查看生成的代码时,你会看到:
<!--l. 13--><pre class="listings"><span
class="cmtt-10x-x-109"> </span><br /><span class="label"><a
id="x1-2r1"></a></span><span
class="cmtt-10x-x-109">$</span><span
class="cmtt-10x-x-109"> </span><span
class="cmtt-10x-x-109">cd</span><span
class="cmtt-10x-x-109"> </span><span
class="cmtt-10x-x-109">/</span><span
class="cmtt-10x-x-109">proj</span><span
class="cmtt-10x-x-109">/</span></pre><!--l. 14--><pre class="listings"><span
class="cmtt-10x-x-109">g2014048</span></pre><!--l. 14--><pre class="listings">
<span
class="cmtt-10x-x-109"> </span><br /><span class="label"><a
id="x1-3r2"></a></span></pre>
从此代码中可以明显看出,转义到 LaTeX 导致插入结束标记并开始新<pre>
元素。转义代码后也发生了同样的情况,因此现在<pre>
使用了三个元素而不是一个,并且视觉结果是虚线。
通过检查listings
源代码及其tex4ht
配置,似乎用于tex4ht
插入标签重新定义的宏不仅用于列表环境的开始和结束,而且有时也用于环境内部,例如转义的 LaTeX 代码的情况。
我修改了tex4ht
listings 的配置文件,listings.4ht
因此标签应该只插入到 listings 环境的实际开头和结尾。这需要使用真实样本进行一些测试,然后我们应该在tex4ht
错误数据库中报告此问题:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% listings.4ht 2014-06-16-21:04 %
% Copyright (C) 2001--2009 Eitan M. Gurari %
% 2009--2014 TeX Users Group %
% %
% This work may be distributed and/or modified under the %
% conditions of the LaTeX Project Public License, either %
% version 1.3c of this license or (at your option) any %
% later version. The latest version of this license is %
% in %
% http://www.latex-project.org/lppl.txt %
% and version 1.3c or later is part of all distributions %
% of LaTeX version 2005/12/01 or later. %
% %
% This work has the LPPL maintenance status "maintained".%
% %
% This Current Maintainer of this work %
% is the TeX4ht Project <[email protected]>. %
% %
% If you modify this program your changing its signature %
% with a directive of the following form will be %
% appreciated. %
% \message{signature} %
% %
% [email protected] %
% http://www.tug.org/tex4ht %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\immediate\write-1{version 2014-06-16-21:04}
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\newif\iflstnest
\append:defII\lst@EnterMode{%
\iflstnest\typeout{lstnest true}\else\typeout{lstnest false}
\ifx \lsthk:EveryLine\:UnDef
\let\lsthk:EveryLine\lsthk@EveryLine
\fi
\ifx \lsthk:EveryLine\lsthk@EveryLine
\pend:def\lsthk@EveryLine{\c:listings
\def\dd:listings{\d:listings\let\dd:listings\empty}}%
\fi
\append:def\lsthk@EveryPar{\dd:listings}%
\edef\:xtemp{Listing mode:\the\lst@mode}
\expandafter\typeout\expandafter{\:xtemp}%
\a:listings\fi\bgroup
\Configure{$}{}{}{}%
\aftergroup\lst:EnterMode}
\def\lst:EnterMode{\iflstnest\else\b:listings\fi\egroup\typeout{linsings end}}
\NewConfigure{listings}{4}
\let\dd:listings=\empty
\append:defI\lst@Init{\csname a:listings-init\endcsname\typeout{listings init}\global\lstnesttrue}
\pend:def\lst@DeInit{\csname b:listings-init\endcsname\typeout{listings init end}\global\lstnestfalse}
\NewConfigure{listings-init}{2}
\lst@AddToHook{TextStyle}{%
\Configure{listings}{}{}{}{}%
\a:lstinline \bgroup \aftergroup\b:lstinline\aftergroup\egroup
}
\NewConfigure{lstinline}{2}
\pend:defI\lst@MakeCaption{%
\let\lst:addcontentsline\addcontentsline
\def\addcontentsline{\gHAdvance\TitleCount by 1
\lst:addcontentsline}%
}
\append:defI\lst@MakeCaption{%
\let\addcontentsline\lst:addcontentsline
}
\def\lst@NewLine{%
\ifx\lst@OutputBox\@gobble\else \the\everypar \fi
\global\advance\lst@newlines\m@ne
\lst@newlinetrue
}%
\def\lst@InputListing#1{%
\begingroup
\lsthk@PreSet \gdef\lst@intname{#1}%
\expandafter\lstset\expandafter{\lst@set}%
\lsthk@DisplayStyle
\catcode\active=\active
\a:lstinputlisting \lst@Init\relax \let\lst@gobble\z@
\lst@SkipToFirst
\lst@ifprint \def\lst@next{\input{#1}}%
\else \let\lst@next\@empty \fi
\lst@next \lst@DeInit
\b:lstinputlisting
\endgroup}
\NewConfigure{lstinputlisting}{2}
\def\lst@Kern#1{%
\setbox\z@\hbox{{\lst@currstyle{\kern#1}}}%
\global\advance\lst@currlwidth \wd\z@
\tmp:dim=#1 \let\:tempc=\empty
\loop \ifdim \tmp:dim>\a:lst@Kern
\advance \tmp:dim by -\a:lst@Kern
\advance \tmp:dim by -\b:lst@Kern
\append:def\:tempc{\:nbsp}%
\repeat
\setbox\z@\hbox{{\lst@currstyle{\:tempc}}}%
\lst@OutputBox\z@}
\NewConfigure{lst@Kern}{2}
\Configure{lst@Kern}{0.499em}{0.1em}
\def\lst@outputspace{\:nbsp}
\HLet\lst@frameInit=\empty
\HLet\lst@frameExit=\empty
\Hinput{listings}
\endinput
您的例子现在看起来不错:
<!--l. 13--><pre class="listings"><span
class="cmtt-10x-x-109"> </span><br /><span class="label"><a
id="x1-2r1"></a></span><span
class="cmtt-10x-x-109">$</span><span
class="cmtt-10x-x-109"> </span><span
class="cmtt-10x-x-109">cd</span><span
class="cmtt-10x-x-109"> </span><span
class="cmtt-10x-x-109">/</span><span
class="cmtt-10x-x-109">proj</span><span
class="cmtt-10x-x-109">/</span><span
class="cmtt-10x-x-109">g2014048</span>
<a
id="x1-3r2"></a></pre>