为了使用 listings 包显示命令行 GAP 会话,我需要区分输入和输出。我尝试通过在每个输出行前面添加一个标记来实现这一点,这样这些行就可以被自定义,例如moredelim
。
现在,是否还可以编辑列表编号?理想情况下,我想重新定义,\thelstnumber
以便默认的“输入”行被编号,“输出”行前面有一个固定字符,例如“>”。
这是默认行为:
结果\renewcommand*\thelstnumber{>}
是这样的:
这是我想要的行为:
梅威瑟:
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
%code style
\lstset{basicstyle=\fontfamily{cmtt}\selectfont,
numbers=left,numberstyle=\fontfamily{cmtt}\selectfont\color{red}}
\lstdefinelanguage{GAP}{moredelim=[il][\itshape]{>}}
%OVERWRITES ALL NUMBERS TO '>'
\renewcommand*\thelstnumber{>}
%WANTED EFFECT
%\renewcommand*\thelstnumber{
% IF (FIRST CHARACTER OF LINE IS '>') THEN ('>')
% ELSE (normal numbering)
%}
%--------------------------------------------------------
\begin{document}
\begin{lstlisting}[language=GAP]
U := (1,3,8,6)(2,5,7,4)(9,33,25,17)(10,34,26,18)(11,35,27,19);
L := (9,11,16,14)(10,13,15,12)(1,17,41,40)(4,20,44,37)(6,22,46,35);
F := (17,19,24,22)(18,21,23,20)(6,25,43,16)(7,28,42,13)(8,30,41,11);
R := (25,27,32,30)(26,29,31,28)(3,38,43,19)(5,36,45,21)(8,33,48,24);
B := (33,35,40,38)(34,37,39,36)(3,9,46,32)(2,12,47,29)(1,14,48,27);
D := (41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40);
cube := Group(U,L,F,R,B,D);
Size( cube );
>43252003274489856000
Collected(Factors(Size(cube)));
>[ [ 2, 27 ], [ 3, 14 ], [ 5, 3 ], [ 7, 2 ], [ 11, 1 ] ]
\end{lstlisting}
\end{document}