列出线范围标记有时无法被识别

列出线范围标记有时无法被识别

我正在使用该命令记录几个大型 XSLT 脚本\lstinputlisting。我在脚本中设置了处理指令,以标记要记录的适当大小的代码块,大多数情况下每个块 10-20 行,格式如下

<?doc val1?>

<?doc val2?>

(等等;有几十个这样的)并包括选项rangeprefix=\<?doc\ ,rangesuffix=?\>,linerange=val1-val2

在第一个代码块(正确)完成后,它会停止识别 PI 模式,只是将脚本的其余部分包含到文件末尾,甚至显示它应该识别的 PI。

这些脚本不是我写的,我无意在这里发布,但在我尝试构建 MWE 之前,我想知道是否有人遇到过这个问题。它似乎只发生在较大的文件上(当前有问题的文件是 92KB 和 2330 行)。

pdflatex 版本 3.14159265-2.6-1.40.16 和 XeLaTeX 版本 3.14159265-2.6-0.99992 均发生这种情况,均与 LaTeX <2016/02/01> 和 listings.sty 1.6 (2015/06/04) 有关

编辑于 2018-11-27

这是 MWE(现在使用 cpdoc 而不是 doc 作为 PI 名称):

\documentclass{article}
\usepackage{listings}
\begin{document}
\section{Start}

\lstinputlisting[language=XSLT,
  rangeprefix=\<?cpdoc\ ,rangesuffix=?\>,
  linerange=start-components,includerangemarker=false,
  showlines=false]{sitemap.xmap}

\section{Components}

\lstinputlisting[language=XSLT,
  rangeprefix=\<?cpdoc\ ,rangesuffix=?\>,
  linerange=components-generators,includerangemarker=false,
  showlines=false]{sitemap.xmap}

\end{document}

sitemap.xmap这是与之配套的文件。

<?cpdoc start?>
<?xml version="1.0" encoding="UTF-8"?><!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><!--+
    | This is the 'heart' of Cocoon. The sitemap maps URI space to
    | resources. It consists basicaly of two parts: components and
    | pipelines. Pipelines are made out of components. There is such a
    | vast number of components available that it would be impossible to
    | describe them here, please refer to the accompanying
    | documentation. For specific components, have a look also at the
    | javadocs for them. Most pipelines are present to demonstrate some
    | feature or technique, often they are explained in more detail in
    | the accompanying documentation. The sitemaps which come with each
    | sample and each block will help to explain.
    |
    | CVS $Id: sitemap.xmap 477161 2006-11-20 12:25:52Z jeremy $
    +--><map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<?cpdoc components?>
<!-- ======================= Components ================================ -->

  <map:components>

  <!--+
      | All pipelines consist at least of two components: a generator, that
      | produces the content, and a serialiser, that delivers the content to
      | the client.
      |
      | More precisely: a generator generates SAX events and a serializer
      | consumes these events and produces a byte stream.
      |
      | Some things to note here: each generator has a unique name, this
      | name is mapped to a java class, one name is declared as the default
      | generator. Each generator may have additional configurations as
      | child elements.
      |
      | Additional attributes are targeted at the component manager. The optional
      | "label" attribute is relevant for the view concept below. The optional
      | "logger" attribute defines the logging category where messages produced
      | by a component should go. If there's no "logger" attribute, the category
      | used is the one defined for the "sitemap" component in cocoon.xconf.
      |
      | We have chosen in this sitemap to use a different logging category
      | for each component, which allows fine-grained classification of log
      | messages. But you are free to use any category you want.
      |
      | It is possible to have the same java class declared as different
      | generators by using different names. No configuration options are
      | shared between these instances, however.
      |
      | All components follow this scheme.
      +-->
<?cpdoc generators?>
  <map:generators default="file">
    <map:generator label="content" logger="sitemap.generator.file" name="file" pool-max="${file-generator.pool-max}" src="org.apache.cocoon.generation.FileGenerator"/>
  </map:generators>

</map:sitemap>

输出的 PDF 如下所示(第 1 页为 JPG):您可以看到“组件”的 PI 包含在输出中,而不是被识别为边界输出 PDF 的第 1 页的 JPG

答案1

不是一个真正的解决方案,但对于注释来说太长了。看起来好像从标记后面的行开始的注释将列表放在了轨道之外。如果我将此注释向下移动一行,或在标记后添加一个空行,它就会再次起作用。如果使用,它也会起作用includerangemarker=true。我建议给作者写一份错误报告。

\documentclass{article}
\usepackage{listings}
\begin{document}
\section{Work}

\lstinputlisting[language=XSLT,
  rangeprefix={<?cpdoc\ },rangesuffix={?>},
  linerange=startB-componentsB,includerangemarker=false,
  showlines=false]{sitemap.xml}

\section{Work}

\lstinputlisting[language=XSLT,
  rangeprefix={<?cpdoc\ },rangesuffix={?>},
  linerange=startC-componentsC,includerangemarker=false,
  showlines=false]{sitemap.xml}

\section{Fail}
\lstinputlisting[language=XSLT,
  rangeprefix={<?cpdoc\ },rangesuffix={?>},
  linerange=start-components,includerangemarker=false,
  showlines=false]{sitemap.xml}

\end{document}

使用此sitemap.xml:

<?cpdoc start?>
<?xml version="1.0" encoding="UTF-8"?><!--
  Licensed to the Apache Software Foundation (ASF) under one or more
-->
<?cpdoc components?>

<?cpdoc startB?>
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
-->
<?cpdoc componentsB?>


<?cpdoc startC?>

<?xml version="1.0" encoding="UTF-8"?><!--
  Licensed to the Apache Software Foundation (ASF) under one or more
-->
<?cpdoc componentsC?>

在此处输入图片描述

该问题可以简化为使用带有方面 html 的标签:

\documentclass{article}
\usepackage{listings}

\lstdefinelanguage{XMLNEW}{tag=**[s]<>}[html]%

\begin{document}
\section{Fail}
\lstinputlisting[language=XMLNEW,
  rangeprefix={<?cpdoc\ },rangesuffix={?>},
  linerange=start-components,includerangemarker=false,
  showlines=false]{sitemap.xml}

\end{document}

相关内容