我有一个修改的环境查找名为 的列表mylisting
。我想知道如何包含要在环境中使用的文件的路径mylisting
?
这是我目前拥有的代码:
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{xcolor}
\tcbuselibrary{listings,skins}
\usepackage{filecontents}
\begin{filecontents*}{HOG_test.m}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write('Case insensitive ');
WritE('Pascal keywords.');
\end{filecontents*}
\usepackage[numbered,framed,autolinebreaks,useliterate]{matlab-prettifier}
\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
%language=Matlab,
style=Matlab-editor,
basicstyle=\ttfamily\small,
numbersep=25pt,
frame=none
}
\newtcblisting{mylisting}[2][]{
arc=0pt, outer arc=0pt,
listing only,
colback=blue!10,
colbacktitle=blue!75!black,
listing style=mystyle,
title=#2,
#1
}
\begin{document}
\begin{mylisting}[hbox,enhanced,drop shadow]{Accuracy Calculation}
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
%% Save data to be used in pgfplots
switch nn
case 1
fileID = fopen('PCA_KNN1.dat','w');
case 2
fileID = fopen('PCA_KNN2.dat','w');
end
\end{mylisting}
\begin{mylisting}[hbox,enhanced,drop shadow]{Accuracy Calculation}
% How to get "HOG_test.m" code to appear in the mylisting???
\end{mylisting}]
\lstinputlisting{HOG_test.m}
\end{document}
答案1
您通过命令 定义了新环境\newtcblisting
。
该命令不是来自 listings 包。它来自 tcolorbox 包。
因此还可以利用 tcolorbox 包提供的其他功能/宏:
不要\lstinputlisting
使用 listing 包中的 -command,而要使用\tcbinputlisting
tcolorbox 包中的 -command 来显示存储在外部文件中的代码。
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{xcolor}
\tcbuselibrary{listings,skins}
\usepackage{filecontents}
\begin{filecontents*}{HOG_test.m}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write('Case insensitive ');
WritE('Pascal keywords.');
\end{filecontents*}
\usepackage[numbered,framed,autolinebreaks,useliterate]{matlab-prettifier}
\lstdefinestyle{mystyle}{%
numbers=left,
numberstyle=\small,
numbersep=8pt,
%language=Matlab,
style=Matlab-editor,
basicstyle=\ttfamily\small,
numbersep=25pt,
frame=none
}
\newtcblisting{mylisting}[2][]{%
arc=0pt, outer arc=0pt,
listing only,
colback=blue!10,
colbacktitle=blue!75!black,
listing style=mystyle,
title=#2,
#1
}
\begin{document}
\begin{mylisting}[hbox,enhanced,drop shadow]{Accuracy Calculation}
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
%% Save data to be used in pgfplots
switch nn
case 1
fileID = fopen('PCA_KNN1.dat','w');
case 2
fileID = fopen('PCA_KNN2.dat','w');
end
\end{mylisting}
\tcbinputlisting{%
arc=0pt,
outer arc=0pt,
listing only,
colback=blue!10,
colbacktitle=blue!75!black,
listing style=mystyle,
title=Accuracy Calculation,
hbox,
enhanced,
drop shadow,
listing file=HOG_test.m
}
\end{document}