我想将 tcolorbox(或实际上是 定义的 lstlisting \newtcblisting
)放入脚注中。因此,类似下面的内容(无法编译)
\documentclass{article}
\usepackage{matlab-prettifier}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\newtcblisting[]{tlisting}[1][]{
listing only,
listing options={
style=Matlab-editor,
}
}
\begin{document}
Some Text\footnote{Some Text: %
\begin{tlisting}
code
\end{tlisting}
}
\end{document}
答案1
您可以tcolorbox
在脚注中插入“其中包含 Matlab 代码”。
为了列出代码,我找到了两个选项。请参阅答案在文档中排版 matlab 代码
在这两种情况下,您都可以使用 直接从某处包含外部 m 文件\lstinputlisting{/SOMEPATH/FILENAME.M}
。
(1)使用M-code LaTeX Package
来自下载包 m-code
使用此代码(参见 https://tex.stackexchange.com/a/78393/161015)
\documentclass{article}
%% See https://tex.stackexchange.com/a/78393/161015
%% https://www.mathworks.com/matlabcentral/fileexchange/8015-m-code-latex-package
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
% default font
\def\lstbasicfont{\sffamily\footnotesize}
\usepackage{tcolorbox}
\begin{filecontents*}[overwrite]{sample.m}
for i = 1:3
if i >= 5 && a ~= b % literate programming replacement
disp('cool'); % comment with some §\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$§
end
[:,ind] = max(vec);
x_last = x(1,end) - 1;
v(end);
really really long really really long really really long really really long really really long line % blaaaaaaaa
ylabel('Voltage (µV)');
end
\end{filecontents*}
\begin{document}
See as example\footnote{mcode: %
\begin{tcolorbox}[colback=blue!2]
\lstinputlisting{sample.m}%
\end{tcolorbox}
}
\end{document}
(2)使用包matlab-prettifier
:
这是代码:(见https://tex.stackexchange.com/a/158816/161015)
\documentclass{article}
\usepackage[T1]{fontenc}
%% See https://tex.stackexchange.com/a/158816/161015
\usepackage[numbered,framed]{matlab-prettifier}
\usepackage{tcolorbox}
\begin{filecontents*}[overwrite]{sample.m}
for i = 1:3
if i >= 5 && a ~= b % literate programming replacement
disp('cool'); % comment with some §\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$§
end
[:,ind] = max(vec);
x_last = x(1,end) - 1;
v(end);
really really long really really long really really long really really long really really long line % blaaaaaaaa
ylabel('Voltage (µV)');
end
\end{filecontents*}
\let\ph\mlplaceholder
\lstMakeShortInline"
\lstset{
style = Matlab-editor,
basicstyle = \mlttfamily,
escapechar = ",
mlshowsectionrules = true,
numberstyle=\tiny,
}
\begin{document}
See as example\footnote{matlab-prettifier: %
\begin{tcolorbox}[colback=blue!2,boxsep=20pt,top=-10pt,bottom=-15pt]
\lstinputlisting{sample.m}%
\end{tcolorbox}
}
\end{document}
% comment with some §\mcommentfont\LaTeX in it: $\mcommentfont\pi x^2$§
注意第 3 行和
Voltage (µV)
第 9 行的输出不同