I try to define an environment called "codeaux" printing a piece of python code inside a mdframed environment. After that my aim will be to redefine "codeaux" in a pyconsole version (pyblock/verbatim for student notes, and pyconsole for teacher notes).

I tried the following solution, but it doesn't work and I don't know why.

\documentclass[a4paper,8pt,table]{book}
\usepackage{color}
\usepackage{tikz,tikzpagenodes,tkz-tab}
\usepackage{tikzsymbols}
    \usetikzlibrary{shadows,matrix,arrows,decorations.pathmorphing,snakes,arrows,shapes,plotmarks,shapes.geometric,decorations.markings,positioning,calc}
\usepackage{pythontex}

\usepackage[usetwoside=false]{mdframed}

\newenvironment{code}{%
\begin{mdframed}[linecolor=green,innerrightmargin=30pt,innerleftmargin=30pt,backgroundcolor=white,skipabove=10pt,skipbelow=10pt,roundcorner=5pt,splitbottomskip=6pt,splittopskip=12pt]
}{%
\end{mdframed}
}
\newenvironment{codeaux}{\begin{code}
\begin{pyblock}[][numbers=left]
}
{\end{pyblock}
\end{code}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\begin{code}
\begin{pyverbatim}[][numbers=left]
type(42)
type(2.5)
type('Bonjour')
\end{pyverbatim}
\end{code}


\begin{pyblock}
type(42)
type(2.5)
type('Bonjour')
\end{pyblock}

\begin{codeaux}
type(42)
type(2.5)
type('Bonjour') 
\end{codeaux}


\end{document}
  • You probably need \VerbatimEnvironment. See tex.stackexchange.com/a/171712/10742. – G. Poore Oct 12 at 23:16
  • If I use pyblock instead of pyverbatim, codeaux returns also an error. My goal is to use pythontex. We can't call pyblock inside an environment ? – jowe_19 19 hours ago
  • Using pyblock works fine for me. If you can't get it working, consider either updating this question with your current code, or asking a new question. – G. Poore 12 hours ago
  • My question is updated. – jowe_19 9 hours ago

You need \VerbatimEnvironment at the beginning of any environment for verbatim content that is based on fancyvrb, which includes all PythonTeX environments that typeset code.

\newenvironment{codeaux}{\VerbatimEnvironment\begin{code}
\begin{pyblock}[][numbers=left]
}
{\end{pyblock}
\end{code}
}

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.