Defining a two part environment using minted and listings











up vote
1
down vote

favorite












I am writing some programming instructions for students, and I am trying to format the code so that it looks like the cell input/output structure of a Jupyter or Google Colab notebook. So I want it to look something like



enter image description here



So far I've been using the minted package to get the code because I like its automatic syntax highlighting and the listings package because it looks like the output of a notebook.



documentclass[11pt]{amsart}

usepackage[framemethod=tikz]{mdframed} %%to make a framed environment

usepackage{listings}
usepackage{minted}


usemintedstyle{xcode}

definecolor{light-gray}{rgb}{0.789035,0.789035,0.789035}
setminted{bgcolor=light-gray}


lstset{frame=b,
language=Python,
aboveskip=-2mm,
belowskip=3mm,
columns=flexible,
basicstyle={smallttfamily}
}

newminted{py}{linenos=true,
autogobble,
python3=true,
obeytabs=true,
tabsize=3,
frame=none,
framesep=10pt}


begin{document}


begin{pycode}
print("Hello world!")
end{pycode}
begin{lstlisting}
Hello world!
end{lstlisting}

end{document}


This looks good for the most part, except when LaTeX does weird things with spreading the vertical spacing out on a page, it separates the minted environment from the listings environment vertically. I would like to combine these into one environment to force them to stay together.



I know that I can combine environments together like



newenvironment{doubleproof}{
newcommand{nextpart}{end{proof} begin{proof}}
begin{proof}}{end{proof}}


so that



begin{doubleproof}
First proof
nextpart
Second proof
end{doubleproof}


produces



enter image description here



However, when I try defining



newenvironment{cell}{
newcommand{nextpart}{end{pycode}begin{lstlisting}}
begin{pycode}}{end{lstlistings}}


and using it in a similar way, I get an error. Is there a way to get this to work, or another solution to formatting my output like this? Thanks in advance!










share|improve this question







New contributor




Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    1
    down vote

    favorite












    I am writing some programming instructions for students, and I am trying to format the code so that it looks like the cell input/output structure of a Jupyter or Google Colab notebook. So I want it to look something like



    enter image description here



    So far I've been using the minted package to get the code because I like its automatic syntax highlighting and the listings package because it looks like the output of a notebook.



    documentclass[11pt]{amsart}

    usepackage[framemethod=tikz]{mdframed} %%to make a framed environment

    usepackage{listings}
    usepackage{minted}


    usemintedstyle{xcode}

    definecolor{light-gray}{rgb}{0.789035,0.789035,0.789035}
    setminted{bgcolor=light-gray}


    lstset{frame=b,
    language=Python,
    aboveskip=-2mm,
    belowskip=3mm,
    columns=flexible,
    basicstyle={smallttfamily}
    }

    newminted{py}{linenos=true,
    autogobble,
    python3=true,
    obeytabs=true,
    tabsize=3,
    frame=none,
    framesep=10pt}


    begin{document}


    begin{pycode}
    print("Hello world!")
    end{pycode}
    begin{lstlisting}
    Hello world!
    end{lstlisting}

    end{document}


    This looks good for the most part, except when LaTeX does weird things with spreading the vertical spacing out on a page, it separates the minted environment from the listings environment vertically. I would like to combine these into one environment to force them to stay together.



    I know that I can combine environments together like



    newenvironment{doubleproof}{
    newcommand{nextpart}{end{proof} begin{proof}}
    begin{proof}}{end{proof}}


    so that



    begin{doubleproof}
    First proof
    nextpart
    Second proof
    end{doubleproof}


    produces



    enter image description here



    However, when I try defining



    newenvironment{cell}{
    newcommand{nextpart}{end{pycode}begin{lstlisting}}
    begin{pycode}}{end{lstlistings}}


    and using it in a similar way, I get an error. Is there a way to get this to work, or another solution to formatting my output like this? Thanks in advance!










    share|improve this question







    New contributor




    Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am writing some programming instructions for students, and I am trying to format the code so that it looks like the cell input/output structure of a Jupyter or Google Colab notebook. So I want it to look something like



      enter image description here



      So far I've been using the minted package to get the code because I like its automatic syntax highlighting and the listings package because it looks like the output of a notebook.



      documentclass[11pt]{amsart}

      usepackage[framemethod=tikz]{mdframed} %%to make a framed environment

      usepackage{listings}
      usepackage{minted}


      usemintedstyle{xcode}

      definecolor{light-gray}{rgb}{0.789035,0.789035,0.789035}
      setminted{bgcolor=light-gray}


      lstset{frame=b,
      language=Python,
      aboveskip=-2mm,
      belowskip=3mm,
      columns=flexible,
      basicstyle={smallttfamily}
      }

      newminted{py}{linenos=true,
      autogobble,
      python3=true,
      obeytabs=true,
      tabsize=3,
      frame=none,
      framesep=10pt}


      begin{document}


      begin{pycode}
      print("Hello world!")
      end{pycode}
      begin{lstlisting}
      Hello world!
      end{lstlisting}

      end{document}


      This looks good for the most part, except when LaTeX does weird things with spreading the vertical spacing out on a page, it separates the minted environment from the listings environment vertically. I would like to combine these into one environment to force them to stay together.



      I know that I can combine environments together like



      newenvironment{doubleproof}{
      newcommand{nextpart}{end{proof} begin{proof}}
      begin{proof}}{end{proof}}


      so that



      begin{doubleproof}
      First proof
      nextpart
      Second proof
      end{doubleproof}


      produces



      enter image description here



      However, when I try defining



      newenvironment{cell}{
      newcommand{nextpart}{end{pycode}begin{lstlisting}}
      begin{pycode}}{end{lstlistings}}


      and using it in a similar way, I get an error. Is there a way to get this to work, or another solution to formatting my output like this? Thanks in advance!










      share|improve this question







      New contributor




      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am writing some programming instructions for students, and I am trying to format the code so that it looks like the cell input/output structure of a Jupyter or Google Colab notebook. So I want it to look something like



      enter image description here



      So far I've been using the minted package to get the code because I like its automatic syntax highlighting and the listings package because it looks like the output of a notebook.



      documentclass[11pt]{amsart}

      usepackage[framemethod=tikz]{mdframed} %%to make a framed environment

      usepackage{listings}
      usepackage{minted}


      usemintedstyle{xcode}

      definecolor{light-gray}{rgb}{0.789035,0.789035,0.789035}
      setminted{bgcolor=light-gray}


      lstset{frame=b,
      language=Python,
      aboveskip=-2mm,
      belowskip=3mm,
      columns=flexible,
      basicstyle={smallttfamily}
      }

      newminted{py}{linenos=true,
      autogobble,
      python3=true,
      obeytabs=true,
      tabsize=3,
      frame=none,
      framesep=10pt}


      begin{document}


      begin{pycode}
      print("Hello world!")
      end{pycode}
      begin{lstlisting}
      Hello world!
      end{lstlisting}

      end{document}


      This looks good for the most part, except when LaTeX does weird things with spreading the vertical spacing out on a page, it separates the minted environment from the listings environment vertically. I would like to combine these into one environment to force them to stay together.



      I know that I can combine environments together like



      newenvironment{doubleproof}{
      newcommand{nextpart}{end{proof} begin{proof}}
      begin{proof}}{end{proof}}


      so that



      begin{doubleproof}
      First proof
      nextpart
      Second proof
      end{doubleproof}


      produces



      enter image description here



      However, when I try defining



      newenvironment{cell}{
      newcommand{nextpart}{end{pycode}begin{lstlisting}}
      begin{pycode}}{end{lstlistings}}


      and using it in a similar way, I get an error. Is there a way to get this to work, or another solution to formatting my output like this? Thanks in advance!







      listings minted






      share|improve this question







      New contributor




      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 hour ago









      Mark Hughes

      61




      61




      New contributor




      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Mark Hughes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



























          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          Mark Hughes is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464782%2fdefining-a-two-part-environment-using-minted-and-listings%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Mark Hughes is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          Mark Hughes is a new contributor. Be nice, and check out our Code of Conduct.













          Mark Hughes is a new contributor. Be nice, and check out our Code of Conduct.












          Mark Hughes is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f464782%2fdefining-a-two-part-environment-using-minted-and-listings%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista