假设我myclass
在 Matlab 中编写了一个具有许多属性和方法的类,现在我想显示
- 它最重要的属性(
foo
和bar
), - 其最重要的方法的标题(
myclass
和baz
)以及 - 他们的文件和
- 一行概括所有步骤。
哪种方式最能表明原始源代码中遗漏了一些行,就像这里的第 6、11 和 15 行一样?
电流输出
平均能量损失
\begin{filecontents*}{\jobname.m}
classdef myclass
% MYCLASS A very good class.
properties
foo
bar
... and many more.
end
methods
function mc = myclass(foo, bar)
% MYCLASS Construct an instance of this class.
... check for allowed input, accept input.
end
function baz(mc)
% BAZ Does something great.
... print info.
end
end
end
\end{filecontents*}
\documentclass{beamer}
\usepackage{listings}
\lstset{
language=matlab,
numbers=left,
basicstyle=\footnotesize,
keywordstyle=\bfseries\color{blue!75!black},
commentstyle=\color{green!50!black},
morecomment=[l]{...},
morekeywords={classdef,methods,properties},
deletekeywords={bar},
}
\begin{document}
\begin{frame}[fragile]{See my code}
\lstinputlisting{\jobname.m}
\end{frame}
\end{document}
答案1
一种方法是定义转义字符并使用它来突出显示省略的文本。例如,添加到lsset
escapechar={|},
然后使用
|\color{red}... check for allowed input, accept input.|
\begin{filecontents*}[overwrite]{\jobname.m}
classdef myclass
% MYCLASS A very good class.
properties
foo
bar
|\color{red}... and many more.|
end
methods
function mc = myclass(foo, bar)
% MYCLASS Construct an instance of this class.
|\color{red}... check for allowed input, accept input.|
end
function baz(mc)
% BAZ Does something great.
... print info.
end
end
end
\end{filecontents*}
\documentclass{beamer}
\usepackage{listings}
\lstset{
language=matlab,
numbers=left,
basicstyle=\footnotesize,
keywordstyle=\bfseries\color{blue!75!black},
commentstyle=\color{green!50!black},
escapechar={|}, % added <<<<<<<<<<
morekeywords={classdef,methods,properties},
deletekeywords={bar},
}
\begin{document}
\begin{frame}[fragile]{See my code}
\lstinputlisting{\jobname.m}
\end{frame}
\end{document}
\begin{filecontents*}[overwrite]{\jobname.m}
classdef myclass
% MYCLASS A very good class.
properties
foo
bar
|\color{red}... and many more.|
end
methods
function mc = myclass(foo, bar)
% MYCLASS Construct an instance of this class.
|\begin{minipage}{\linewidth}
\color{red}... check for allowed input, accept input. \\
more lines of code \\
more lines of code\\
more lines of code
\end{minipage}|
end
function baz(mc)
% BAZ Does something great.
... print info.
end
end
end
\end{filecontents*}