我想制作一个带间隔的列表,如下所示:
\begin[firstline=5, lastline=10]{lstlisting}
<inkscape-extension>
<_name>Export to TikZ path</_name>
<id>net.texample.tools.svg.export_tikz.effect</id>
<dependency type="executable" location="extensions">tikz_export.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">simplepath.py</dependency>
<dependency type="executable" location="extensions">simplestyle.py</dependency>
<param name="codeoutput" type="optiongroup" _gui-text="Output">
<_option value="standalone">Stand alone</_option>
<_option value="codeonly">Only path code</_option>
<_option value="figonly">Tikzpicture</_option>
</param>
<param name="texmode" type="optiongroup" _gui-text="Text interpretation mode">
<_option value="escape">Escape special TeX chars</_option>
<_option value="raw">Raw TeX</_option>
<_option value="math">Math</_option>
</param>
<param name="crop" type="boolean" _gui-text="Crop">false</param>
<param name="clipboard" type="boolean" _gui-text="Export to clipboard">false</param>
<param name="wrap" type="boolean" _gui-text="Wrap paths">true</param>
<param name="indent" type="boolean" _gui-text="Indent groups">true</param>
<param name="output" type="string" _gui-text="Output filename">none</param>
<param name="verbose" type="boolean" _gui-text="Verbose output">false</param>
<effect needs-live-preview="false" >
<object-type>all</object-type>
<effects-menu>
<submenu _name="Export"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">tikz_export.py</command>
</script>
</inkscape-extension>
\end{lstlisting}
您将获得从 5 到 10 的行代码,但是如何获取具有间隔的行代码:firstline = 1、xxline = 4-7、xyline = 15-26 和 lastline = 33,如下所示:
\begin[firstline=1, xxline=4-7, xyline=15-26, lastline=33]{lstlisting}
\end{lstlisting}
输出如下:
<inkscape-extension>
<dependency type="executable" location="extensions">tikz_export.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">simplepath.py</dependency>
<dependency type="executable" location="extensions">simplestyle.py</dependency>
<_option value="raw">Raw TeX</_option>
<_option value="math">Math</_option>
</param>
<param name="crop" type="boolean" _gui-text="Crop">false</param>
<param name="clipboard" type="boolean" _gui-text="Export to clipboard">false</param>
<param name="wrap" type="boolean" _gui-text="Wrap paths">true</param>
<param name="indent" type="boolean" _gui-text="Indent groups">true</param>
<param name="output" type="string" _gui-text="Output filename">none</param>
<param name="verbose" type="boolean" _gui-text="Verbose output">false</param>
<effect needs-live-preview="false" >
<object-type>all</object-type>
<effects-menu>
</inkscape-extension>
答案1
该listings
软件包提供了linerange
此类操作的选项。
要显示第 1 行、第 5-10 行、第 15-16 行和第 33 行,请使用以下代码:
\documentclass{article}
\usepackage[left=1cm,right=1cm]{geometry}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[linerange={1-1,5-10,15-26,33-33}]
<inkscape-extension>
<_name>Export to TikZ path</_name>
<id>net.texample.tools.svg.export_tikz.effect</id>
<dependency type="executable" location="extensions">tikz_export.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>
<dependency type="executable" location="extensions">simplepath.py</dependency>
<dependency type="executable" location="extensions">simplestyle.py</dependency>
<param name="codeoutput" type="optiongroup" _gui-text="Output">
<_option value="standalone">Stand alone</_option>
<_option value="codeonly">Only path code</_option>
<_option value="figonly">Tikzpicture</_option>
</param>
<param name="texmode" type="optiongroup" _gui-text="Text interpretation mode">
<_option value="escape">Escape special TeX chars</_option>
<_option value="raw">Raw TeX</_option>
<_option value="math">Math</_option>
</param>
<param name="crop" type="boolean" _gui-text="Crop">false</param>
<param name="clipboard" type="boolean" _gui-text="Export to clipboard">false</param>
<param name="wrap" type="boolean" _gui-text="Wrap paths">true</param>
<param name="indent" type="boolean" _gui-text="Indent groups">true</param>
<param name="output" type="string" _gui-text="Output filename">none</param>
<param name="verbose" type="boolean" _gui-text="Verbose output">false</param>
<effect needs-live-preview="false" >
<object-type>all</object-type>
<effects-menu>
<submenu _name="Export"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">tikz_export.py</command>
</script>
</inkscape-extension>
\end{lstlisting}
\end{document}