需要在Xsim环境中插入Minted,基本代码如下:
\documentclass{book}
\usepackage{xcolor}
\usepackage{minted}
\usepackage[verbose]{xsim}%paquete de ejercicios mejorado
\usepackage{musixtex}
\begin{document}
\chapter{Chapter One}
Chapter one.
\begin{exercise}
Exercise description.
\end{exercise}
\begin{solution}
Solution:
\begin{minted}{python}
def serie_armonica(fundamental, limite):
p1 = pitch.Pitch(fundamental)
serie_armonica("C2", 16)
\end{minted}
\end{solution}
\printsolutionstype[chapter=1]{exercise}
\chapter{Chapter Two}
Chapter two.
\end{document}
由于某种原因,行:\printsolutionstype[chapter=1]{exercise} 提示错误:LaTeX 错误:\begin{document} 由 \end{minted} 结束。
答案1
解决的代码如下:
\documentclass{book}
\usepackage{xcolor}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}
\usepackage{minted}
\usepackage[verbose]{xsim}%paquete de ejercicios mejorado
\usepackage{musixtex}
\newmintedfile[mipycode]{python}{
bgcolor=mintedbackground,
breaklines=true,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=4,
obeytabs=false,
mathescape=false
samepage=false, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
}
\begin{document}
\chapter{Chapter One}
Chapter one.
\begin{exercise}
Exercise description.
\end{exercise}
\begin{solution}
Solution:
\mipycode{Ejercicio_1.1.py}
\end{solution}
\printsolutionstype[chapter=1]{exercise}
\chapter{Chapter Two}
Chapter two.
\end{document}
其中Ejercicio_1.1.py如下:
def serie_armonica(fundamental, limite):
p1 = pitch.Pitch(fundamental)
armonicos=[]
i=1
while i <= limite:
armonicos.append(p1.getHarmonic(i))
i+= 1
j=1
for k in armonicos:
print("Armónico ",j,":",k.unicodeNameWithOctave,':', k.frequency, "->", k)
j+= 1
serie_armonica("C2", 16)