1

It is needed to insert a Minted inside Xsim environment. The basic code is as follow:

\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}

By some reason, the line: \printsolutionstype[chapter=1]{exercise} prompts an error: LaTeX Error: \begin{document} ended by \end{minted}.

2
  • 1
    minted is a verbatim environment so can't in general be used in the argument of a command (or in an environment that saves its body as a macro for use later) Jul 3 at 15:16
  • 2
    you can probably put the python in separate files and use inputminted Jul 3 at 15:25

1 Answer 1

1

The solved code is as follow:

\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}

Where Ejercicio_1.1.py is as follow:

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .