尝试设置以下内容,
\documentclass{tufte-handout}
% Code Formatting Stuff
\usepackage{tcolorbox}
\usepackage{minted}
\tcbuselibrary{minted}
\tcbuselibrary{breakable}
\setminted{style=colorful, tabsize=2}
\newtcblisting{code}{
size=minimal, boxsep=4pt, listing only, breakable,
minted language=python
}
\newenvironment{codemargin}%
{\marginfigure\code}%
{\endcode\endmarginfigure}
\begin{document}
Here\\Is\\Some\\Text
\begin{codemargin}
here
is
some
code
\end{codemargin}
\end{document}
这导致! File ended while scanning use of \next.
\newenviroment{codemargin}{\marginfigure}{\endmarginfigure}
和均可\newenviroment{codemargin}{\code}{\endcode}
用,并且使用
\begin{marginfigure}
\begin{code}
here
is
some
code
\end{code}
\end{marginfigure}
都可以,但将两者放在一起则\newenviroment
不行。我是 TeX 新手,不太了解发生了什么,无法正确诊断这个问题。
答案1
不确定这是否是正确的解决方案,但它似乎有效:
\documentclass{tufte-handout}
% Code Formatting Stuff
\usepackage{tcolorbox}
\tcbuselibrary{minted, breakable}
% print page layout frames, can be commented
\geometry{showframe}
\setminted{style=colorful, tabsize=2}
\newtcblisting{code}{
% option "breakable" is commented because a breakable tcolorbox in
% marginnote is not supported
size=minimal, boxsep=4pt, listing only, %breakable,
minted language=python,
before=\marginfigure, after=\endmarginfigure,
width=\marginparwidth
}
\begin{document}
Here\\Is\\Some\\Text
\begin{code}
here
is
some
code
\end{code}
\end{document}