0

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}
jowe_19
  • 939
  • You probably need \VerbatimEnvironment. See https://tex.stackexchange.com/a/171712/10742. – G. Poore Oct 12 '18 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 Oct 15 '18 at 06:53
  • 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 Oct 15 '18 at 13:55
  • My question is updated. – jowe_19 Oct 15 '18 at 16:33

1 Answers1

4

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}
}
G. Poore
  • 12,417