How can we Define our own Simple Environment for Source Code?












1














Inside of our document we wish to define a new environment for blocks of source code



newenvironment{srcblock}%
% Define the environment


Later, we will use the environment:



begin{srcblock} % use the environment
% source code here
end{srcblock}


We seek the following behavior:




  • Each line in a src code block is numbered

  • The font used for a src code block is monospaced

  • A border is drawn around a code code block, much like fbox does

  • Each code block "floats" to a position so that it will fit all on one page.










share|improve this question







New contributor




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




















  • What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
    – Werner
    3 hours ago










  • Did you already check the listings package? This should be straight-forward with it. Just read the manual.
    – Martin Scharrer
    3 hours ago
















1














Inside of our document we wish to define a new environment for blocks of source code



newenvironment{srcblock}%
% Define the environment


Later, we will use the environment:



begin{srcblock} % use the environment
% source code here
end{srcblock}


We seek the following behavior:




  • Each line in a src code block is numbered

  • The font used for a src code block is monospaced

  • A border is drawn around a code code block, much like fbox does

  • Each code block "floats" to a position so that it will fit all on one page.










share|improve this question







New contributor




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




















  • What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
    – Werner
    3 hours ago










  • Did you already check the listings package? This should be straight-forward with it. Just read the manual.
    – Martin Scharrer
    3 hours ago














1












1








1







Inside of our document we wish to define a new environment for blocks of source code



newenvironment{srcblock}%
% Define the environment


Later, we will use the environment:



begin{srcblock} % use the environment
% source code here
end{srcblock}


We seek the following behavior:




  • Each line in a src code block is numbered

  • The font used for a src code block is monospaced

  • A border is drawn around a code code block, much like fbox does

  • Each code block "floats" to a position so that it will fit all on one page.










share|improve this question







New contributor




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











Inside of our document we wish to define a new environment for blocks of source code



newenvironment{srcblock}%
% Define the environment


Later, we will use the environment:



begin{srcblock} % use the environment
% source code here
end{srcblock}


We seek the following behavior:




  • Each line in a src code block is numbered

  • The font used for a src code block is monospaced

  • A border is drawn around a code code block, much like fbox does

  • Each code block "floats" to a position so that it will fit all on one page.







environments sourcecode fbox






share|improve this question







New contributor




IdleCustard 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




IdleCustard 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




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









asked 4 hours ago









IdleCustardIdleCustard

561




561




New contributor




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





New contributor





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






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












  • What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
    – Werner
    3 hours ago










  • Did you already check the listings package? This should be straight-forward with it. Just read the manual.
    – Martin Scharrer
    3 hours ago


















  • What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
    – Werner
    3 hours ago










  • Did you already check the listings package? This should be straight-forward with it. Just read the manual.
    – Martin Scharrer
    3 hours ago
















What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
– Werner
3 hours ago




What will srcblock contain in terms of characters? verbatim-like content, perhaps (symbols like #, _, $, ^, ...)?
– Werner
3 hours ago












Did you already check the listings package? This should be straight-forward with it. Just read the manual.
– Martin Scharrer
3 hours ago




Did you already check the listings package? This should be straight-forward with it. Just read the manual.
– Martin Scharrer
3 hours ago










2 Answers
2






active

oldest

votes


















1














Variation on my answer here: Seemingly trivial: verbatim, newenvironment, and colorbox. It requires a small modification to my verbatimbox package.



documentclass{article}
usepackage{xcolor,caption,lipsum}
usepackage{verbatimbox}
makeatletter
newenvironment{cverbbox}[5]{%
setcounter{VerbboxLineNo}{0}%
defverbatim@processline{%
% THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
% PRINTED OPTIONAL MATERIAL
{addtocounter{VerbboxLineNo}{1}%
#1setbox0=hbox{#1theverbatim@line}%
hsize=wd0 theverbatim@linepar}}%
@minipagetrue%
@tempswatrue%
globaledefsv@name{@macro@name{#2}}%
globaledefcverbboxColor{#4}%
globaledefcverbboxFColor{#5}%
@ifundefined{sv@name content}{%
expandafternewsaveboxexpandafter{csnamesv@name contentendcsname}%
}%
expandafterglobalexpandafteredefcsnamesv@nameendcsname{usebox{%
csnamesv@name contentendcsname}}%
setbox0=vboxbgroupcolor{#3} verbatim
}
{%
endverbatim%
unskipsetbox0=lastbox %
egroup%
setbox1=hbox{%
colorbox{cverbboxColor}{box0}}%
globalsbox{csnamesv@name contentendcsname}%
{fboxsep=fboxrulecolorbox{cverbboxFColor}{box1}}%
}
makeatother
fboxrule=1ptfboxsep=3ptrelax
begin{document}
lipsum[1]
begin{figure*}[ht]
begin{cverbbox}[textcolor{black}{scriptsizetheVerbboxLineNo~~}]{mycvbox}{red!80}{blue!10}{cyan}
verbatim <Text>
Here
%$#@&^* macros
xa
end{cverbbox}
centerline{mycvbox}
caption*{My code chunk}
end{figure*}
lipsum[2]
end{document}


enter image description here






share|improve this answer





























    1














    This approach is not a simple environment but a standard minted environment nested in you own float environment. Not exactly the asked but:




    Each line in a src code block is numbered (optionally)



    The font used for a src code block is monospaced (and syntax highlited)



    A border is drawn around a code code block, much like fbox does (with top caption inside using stdcaption, for a botom caption outside the box use caption*)



    Each code block "floats" to a position (concretely to top of a new page) so that it will fit all on one page.




    mwe



    documentclass[a6paper]{article}
    usepackage[margin=1cm, paperheight=5in,paperwidth=5in]{geometry}
    pagestyle{empty}
    usepackage{lipsum}
    letstdcaptioncaption
    setcounter{totalnumber}{1}
    usepackage{minted}
    usepackage{float}
    floatstyle{boxed}
    newfloat{fancycode}{t}{loa}
    floatname{fancycode}{LaTeX code}

    begin{document}


    begin{fancycode}
    stdcaption[Basic Structure]{The basic structure of a LaTeX document.}
    begin{minted}[linenos,bgcolor=orange!05]{latex}
    documentclass{article}
    begin{document}
    end{document}
    end{minted}
    end{fancycode}

    begin{fancycode}
    stdcaption[Preamble]{The LaTeX preamble to do a texttt{fancycode}.}
    begin{minted}[linenos,bgcolor=cyan!10]{latex}
    usepackage{minted}
    usepackage{float}
    floatstyle{boxed}
    newfloat{fancycode}{t}{loa}
    floatname{fancycode}{LaTeX code}
    end{minted}
    end{fancycode}

    lipsum[1-2]

    listof{fancycode}{Code examples}

    end{document}





    share|improve this answer





















      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',
      autoActivateHeartbeat: false,
      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
      });


      }
      });






      IdleCustard 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%2f469041%2fhow-can-we-define-our-own-simple-environment-for-source-code%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Variation on my answer here: Seemingly trivial: verbatim, newenvironment, and colorbox. It requires a small modification to my verbatimbox package.



      documentclass{article}
      usepackage{xcolor,caption,lipsum}
      usepackage{verbatimbox}
      makeatletter
      newenvironment{cverbbox}[5]{%
      setcounter{VerbboxLineNo}{0}%
      defverbatim@processline{%
      % THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
      % PRINTED OPTIONAL MATERIAL
      {addtocounter{VerbboxLineNo}{1}%
      #1setbox0=hbox{#1theverbatim@line}%
      hsize=wd0 theverbatim@linepar}}%
      @minipagetrue%
      @tempswatrue%
      globaledefsv@name{@macro@name{#2}}%
      globaledefcverbboxColor{#4}%
      globaledefcverbboxFColor{#5}%
      @ifundefined{sv@name content}{%
      expandafternewsaveboxexpandafter{csnamesv@name contentendcsname}%
      }%
      expandafterglobalexpandafteredefcsnamesv@nameendcsname{usebox{%
      csnamesv@name contentendcsname}}%
      setbox0=vboxbgroupcolor{#3} verbatim
      }
      {%
      endverbatim%
      unskipsetbox0=lastbox %
      egroup%
      setbox1=hbox{%
      colorbox{cverbboxColor}{box0}}%
      globalsbox{csnamesv@name contentendcsname}%
      {fboxsep=fboxrulecolorbox{cverbboxFColor}{box1}}%
      }
      makeatother
      fboxrule=1ptfboxsep=3ptrelax
      begin{document}
      lipsum[1]
      begin{figure*}[ht]
      begin{cverbbox}[textcolor{black}{scriptsizetheVerbboxLineNo~~}]{mycvbox}{red!80}{blue!10}{cyan}
      verbatim <Text>
      Here
      %$#@&^* macros
      xa
      end{cverbbox}
      centerline{mycvbox}
      caption*{My code chunk}
      end{figure*}
      lipsum[2]
      end{document}


      enter image description here






      share|improve this answer


























        1














        Variation on my answer here: Seemingly trivial: verbatim, newenvironment, and colorbox. It requires a small modification to my verbatimbox package.



        documentclass{article}
        usepackage{xcolor,caption,lipsum}
        usepackage{verbatimbox}
        makeatletter
        newenvironment{cverbbox}[5]{%
        setcounter{VerbboxLineNo}{0}%
        defverbatim@processline{%
        % THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
        % PRINTED OPTIONAL MATERIAL
        {addtocounter{VerbboxLineNo}{1}%
        #1setbox0=hbox{#1theverbatim@line}%
        hsize=wd0 theverbatim@linepar}}%
        @minipagetrue%
        @tempswatrue%
        globaledefsv@name{@macro@name{#2}}%
        globaledefcverbboxColor{#4}%
        globaledefcverbboxFColor{#5}%
        @ifundefined{sv@name content}{%
        expandafternewsaveboxexpandafter{csnamesv@name contentendcsname}%
        }%
        expandafterglobalexpandafteredefcsnamesv@nameendcsname{usebox{%
        csnamesv@name contentendcsname}}%
        setbox0=vboxbgroupcolor{#3} verbatim
        }
        {%
        endverbatim%
        unskipsetbox0=lastbox %
        egroup%
        setbox1=hbox{%
        colorbox{cverbboxColor}{box0}}%
        globalsbox{csnamesv@name contentendcsname}%
        {fboxsep=fboxrulecolorbox{cverbboxFColor}{box1}}%
        }
        makeatother
        fboxrule=1ptfboxsep=3ptrelax
        begin{document}
        lipsum[1]
        begin{figure*}[ht]
        begin{cverbbox}[textcolor{black}{scriptsizetheVerbboxLineNo~~}]{mycvbox}{red!80}{blue!10}{cyan}
        verbatim <Text>
        Here
        %$#@&^* macros
        xa
        end{cverbbox}
        centerline{mycvbox}
        caption*{My code chunk}
        end{figure*}
        lipsum[2]
        end{document}


        enter image description here






        share|improve this answer
























          1












          1








          1






          Variation on my answer here: Seemingly trivial: verbatim, newenvironment, and colorbox. It requires a small modification to my verbatimbox package.



          documentclass{article}
          usepackage{xcolor,caption,lipsum}
          usepackage{verbatimbox}
          makeatletter
          newenvironment{cverbbox}[5]{%
          setcounter{VerbboxLineNo}{0}%
          defverbatim@processline{%
          % THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
          % PRINTED OPTIONAL MATERIAL
          {addtocounter{VerbboxLineNo}{1}%
          #1setbox0=hbox{#1theverbatim@line}%
          hsize=wd0 theverbatim@linepar}}%
          @minipagetrue%
          @tempswatrue%
          globaledefsv@name{@macro@name{#2}}%
          globaledefcverbboxColor{#4}%
          globaledefcverbboxFColor{#5}%
          @ifundefined{sv@name content}{%
          expandafternewsaveboxexpandafter{csnamesv@name contentendcsname}%
          }%
          expandafterglobalexpandafteredefcsnamesv@nameendcsname{usebox{%
          csnamesv@name contentendcsname}}%
          setbox0=vboxbgroupcolor{#3} verbatim
          }
          {%
          endverbatim%
          unskipsetbox0=lastbox %
          egroup%
          setbox1=hbox{%
          colorbox{cverbboxColor}{box0}}%
          globalsbox{csnamesv@name contentendcsname}%
          {fboxsep=fboxrulecolorbox{cverbboxFColor}{box1}}%
          }
          makeatother
          fboxrule=1ptfboxsep=3ptrelax
          begin{document}
          lipsum[1]
          begin{figure*}[ht]
          begin{cverbbox}[textcolor{black}{scriptsizetheVerbboxLineNo~~}]{mycvbox}{red!80}{blue!10}{cyan}
          verbatim <Text>
          Here
          %$#@&^* macros
          xa
          end{cverbbox}
          centerline{mycvbox}
          caption*{My code chunk}
          end{figure*}
          lipsum[2]
          end{document}


          enter image description here






          share|improve this answer












          Variation on my answer here: Seemingly trivial: verbatim, newenvironment, and colorbox. It requires a small modification to my verbatimbox package.



          documentclass{article}
          usepackage{xcolor,caption,lipsum}
          usepackage{verbatimbox}
          makeatletter
          newenvironment{cverbbox}[5]{%
          setcounter{VerbboxLineNo}{0}%
          defverbatim@processline{%
          % THE FIRST #1 ACCOUNTS FOR NON-PRINTING COMMANDS; THE SECOND #1 IS FOR
          % PRINTED OPTIONAL MATERIAL
          {addtocounter{VerbboxLineNo}{1}%
          #1setbox0=hbox{#1theverbatim@line}%
          hsize=wd0 theverbatim@linepar}}%
          @minipagetrue%
          @tempswatrue%
          globaledefsv@name{@macro@name{#2}}%
          globaledefcverbboxColor{#4}%
          globaledefcverbboxFColor{#5}%
          @ifundefined{sv@name content}{%
          expandafternewsaveboxexpandafter{csnamesv@name contentendcsname}%
          }%
          expandafterglobalexpandafteredefcsnamesv@nameendcsname{usebox{%
          csnamesv@name contentendcsname}}%
          setbox0=vboxbgroupcolor{#3} verbatim
          }
          {%
          endverbatim%
          unskipsetbox0=lastbox %
          egroup%
          setbox1=hbox{%
          colorbox{cverbboxColor}{box0}}%
          globalsbox{csnamesv@name contentendcsname}%
          {fboxsep=fboxrulecolorbox{cverbboxFColor}{box1}}%
          }
          makeatother
          fboxrule=1ptfboxsep=3ptrelax
          begin{document}
          lipsum[1]
          begin{figure*}[ht]
          begin{cverbbox}[textcolor{black}{scriptsizetheVerbboxLineNo~~}]{mycvbox}{red!80}{blue!10}{cyan}
          verbatim <Text>
          Here
          %$#@&^* macros
          xa
          end{cverbbox}
          centerline{mycvbox}
          caption*{My code chunk}
          end{figure*}
          lipsum[2]
          end{document}


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 3 hours ago









          Steven B. SegletesSteven B. Segletes

          153k9193400




          153k9193400























              1














              This approach is not a simple environment but a standard minted environment nested in you own float environment. Not exactly the asked but:




              Each line in a src code block is numbered (optionally)



              The font used for a src code block is monospaced (and syntax highlited)



              A border is drawn around a code code block, much like fbox does (with top caption inside using stdcaption, for a botom caption outside the box use caption*)



              Each code block "floats" to a position (concretely to top of a new page) so that it will fit all on one page.




              mwe



              documentclass[a6paper]{article}
              usepackage[margin=1cm, paperheight=5in,paperwidth=5in]{geometry}
              pagestyle{empty}
              usepackage{lipsum}
              letstdcaptioncaption
              setcounter{totalnumber}{1}
              usepackage{minted}
              usepackage{float}
              floatstyle{boxed}
              newfloat{fancycode}{t}{loa}
              floatname{fancycode}{LaTeX code}

              begin{document}


              begin{fancycode}
              stdcaption[Basic Structure]{The basic structure of a LaTeX document.}
              begin{minted}[linenos,bgcolor=orange!05]{latex}
              documentclass{article}
              begin{document}
              end{document}
              end{minted}
              end{fancycode}

              begin{fancycode}
              stdcaption[Preamble]{The LaTeX preamble to do a texttt{fancycode}.}
              begin{minted}[linenos,bgcolor=cyan!10]{latex}
              usepackage{minted}
              usepackage{float}
              floatstyle{boxed}
              newfloat{fancycode}{t}{loa}
              floatname{fancycode}{LaTeX code}
              end{minted}
              end{fancycode}

              lipsum[1-2]

              listof{fancycode}{Code examples}

              end{document}





              share|improve this answer


























                1














                This approach is not a simple environment but a standard minted environment nested in you own float environment. Not exactly the asked but:




                Each line in a src code block is numbered (optionally)



                The font used for a src code block is monospaced (and syntax highlited)



                A border is drawn around a code code block, much like fbox does (with top caption inside using stdcaption, for a botom caption outside the box use caption*)



                Each code block "floats" to a position (concretely to top of a new page) so that it will fit all on one page.




                mwe



                documentclass[a6paper]{article}
                usepackage[margin=1cm, paperheight=5in,paperwidth=5in]{geometry}
                pagestyle{empty}
                usepackage{lipsum}
                letstdcaptioncaption
                setcounter{totalnumber}{1}
                usepackage{minted}
                usepackage{float}
                floatstyle{boxed}
                newfloat{fancycode}{t}{loa}
                floatname{fancycode}{LaTeX code}

                begin{document}


                begin{fancycode}
                stdcaption[Basic Structure]{The basic structure of a LaTeX document.}
                begin{minted}[linenos,bgcolor=orange!05]{latex}
                documentclass{article}
                begin{document}
                end{document}
                end{minted}
                end{fancycode}

                begin{fancycode}
                stdcaption[Preamble]{The LaTeX preamble to do a texttt{fancycode}.}
                begin{minted}[linenos,bgcolor=cyan!10]{latex}
                usepackage{minted}
                usepackage{float}
                floatstyle{boxed}
                newfloat{fancycode}{t}{loa}
                floatname{fancycode}{LaTeX code}
                end{minted}
                end{fancycode}

                lipsum[1-2]

                listof{fancycode}{Code examples}

                end{document}





                share|improve this answer
























                  1












                  1








                  1






                  This approach is not a simple environment but a standard minted environment nested in you own float environment. Not exactly the asked but:




                  Each line in a src code block is numbered (optionally)



                  The font used for a src code block is monospaced (and syntax highlited)



                  A border is drawn around a code code block, much like fbox does (with top caption inside using stdcaption, for a botom caption outside the box use caption*)



                  Each code block "floats" to a position (concretely to top of a new page) so that it will fit all on one page.




                  mwe



                  documentclass[a6paper]{article}
                  usepackage[margin=1cm, paperheight=5in,paperwidth=5in]{geometry}
                  pagestyle{empty}
                  usepackage{lipsum}
                  letstdcaptioncaption
                  setcounter{totalnumber}{1}
                  usepackage{minted}
                  usepackage{float}
                  floatstyle{boxed}
                  newfloat{fancycode}{t}{loa}
                  floatname{fancycode}{LaTeX code}

                  begin{document}


                  begin{fancycode}
                  stdcaption[Basic Structure]{The basic structure of a LaTeX document.}
                  begin{minted}[linenos,bgcolor=orange!05]{latex}
                  documentclass{article}
                  begin{document}
                  end{document}
                  end{minted}
                  end{fancycode}

                  begin{fancycode}
                  stdcaption[Preamble]{The LaTeX preamble to do a texttt{fancycode}.}
                  begin{minted}[linenos,bgcolor=cyan!10]{latex}
                  usepackage{minted}
                  usepackage{float}
                  floatstyle{boxed}
                  newfloat{fancycode}{t}{loa}
                  floatname{fancycode}{LaTeX code}
                  end{minted}
                  end{fancycode}

                  lipsum[1-2]

                  listof{fancycode}{Code examples}

                  end{document}





                  share|improve this answer












                  This approach is not a simple environment but a standard minted environment nested in you own float environment. Not exactly the asked but:




                  Each line in a src code block is numbered (optionally)



                  The font used for a src code block is monospaced (and syntax highlited)



                  A border is drawn around a code code block, much like fbox does (with top caption inside using stdcaption, for a botom caption outside the box use caption*)



                  Each code block "floats" to a position (concretely to top of a new page) so that it will fit all on one page.




                  mwe



                  documentclass[a6paper]{article}
                  usepackage[margin=1cm, paperheight=5in,paperwidth=5in]{geometry}
                  pagestyle{empty}
                  usepackage{lipsum}
                  letstdcaptioncaption
                  setcounter{totalnumber}{1}
                  usepackage{minted}
                  usepackage{float}
                  floatstyle{boxed}
                  newfloat{fancycode}{t}{loa}
                  floatname{fancycode}{LaTeX code}

                  begin{document}


                  begin{fancycode}
                  stdcaption[Basic Structure]{The basic structure of a LaTeX document.}
                  begin{minted}[linenos,bgcolor=orange!05]{latex}
                  documentclass{article}
                  begin{document}
                  end{document}
                  end{minted}
                  end{fancycode}

                  begin{fancycode}
                  stdcaption[Preamble]{The LaTeX preamble to do a texttt{fancycode}.}
                  begin{minted}[linenos,bgcolor=cyan!10]{latex}
                  usepackage{minted}
                  usepackage{float}
                  floatstyle{boxed}
                  newfloat{fancycode}{t}{loa}
                  floatname{fancycode}{LaTeX code}
                  end{minted}
                  end{fancycode}

                  lipsum[1-2]

                  listof{fancycode}{Code examples}

                  end{document}






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 hours ago









                  FranFran

                  51.6k6113175




                  51.6k6113175






















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










                      draft saved

                      draft discarded


















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













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












                      IdleCustard 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%2f469041%2fhow-can-we-define-our-own-simple-environment-for-source-code%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