Count lines of multiple files (Using minted for formatting.) Unicorn Meta Zoo #1: Why another...

How to open locks without disable device?

Has a Nobel Peace laureate ever been accused of war crimes?

finding a tangent line to a parabola

Could Neutrino technically as side-effect, incentivize centralization of the bitcoin network?

Align column where each cell has two decimals with siunitx

Are all CP/M-80 implementations binary compatible?

What is a 'Key' in computer science?

How to avoid introduction cliches

Raising a bilingual kid. When should we introduce the majority language?

How to use @AuraEnabled base class method in Lightning Component?

Seek and ye shall find

Will I lose my paid in full property

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

c++ diamond problem - How to call base method only once

Retract an already submitted recommendation letter (written for an undergrad student)

Is there any hidden 'W' sound after 'comment' in : Comment est-elle?

PIC mathematical operations weird problem

Can you stand up from being prone using Skirmisher outside of your turn?

Israeli soda type drink

Implementing 3DES algorithm in Java: is my code secure?

The art of proof summarizing. Are there known rules, or is it a purely common sense matter?

Married in secret, can marital status in passport be changed at a later date?

What is the ongoing value of the Kanban board to the developers as opposed to management

Passing args from the bash script to the function in the script



Count lines of multiple files (Using minted for formatting.)



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraTikZ's foreach x/y in… the set of running indices being a macroRepeating a block of text until it fills a pageLaTeX minted package: numbering lines does not workResetting line count in dtx filesRemove blank lines in mintedUsing listing with minted gets wrong listoflistingsCorrectly highlighting custom html tags in listingsBreak lines at any character in mintedGlobal settings for mintedUsing minted for assembly codetcolorbox tcblinputlisting unexpected behavior when filenames have spaces and/or underscores












2















I am using minted to show source code in my document like this:



section{Image functions}
inputminted{python}{src/imagefuncs.py}

section{Matrix operations}
inputminted{python}{src/matrices.py}

section{Block operations}
inputminted{python}{src/blocks.py}


and so on for several files. Is there a way to count the number of lines in these files and output a total.



Python pseudo code:



paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
for path in paths:
total += linecount(path)
print(str(total))


Any similar questions I found were for listings and only one file.



Edit: To be clear, I want to do this in latex, the python code is to illustrate.










share|improve this question














bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • you can use python inside tex with the python library. You can check for example this answer.

    – Kpym
    Apr 9 '16 at 15:08
















2















I am using minted to show source code in my document like this:



section{Image functions}
inputminted{python}{src/imagefuncs.py}

section{Matrix operations}
inputminted{python}{src/matrices.py}

section{Block operations}
inputminted{python}{src/blocks.py}


and so on for several files. Is there a way to count the number of lines in these files and output a total.



Python pseudo code:



paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
for path in paths:
total += linecount(path)
print(str(total))


Any similar questions I found were for listings and only one file.



Edit: To be clear, I want to do this in latex, the python code is to illustrate.










share|improve this question














bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • you can use python inside tex with the python library. You can check for example this answer.

    – Kpym
    Apr 9 '16 at 15:08














2












2








2








I am using minted to show source code in my document like this:



section{Image functions}
inputminted{python}{src/imagefuncs.py}

section{Matrix operations}
inputminted{python}{src/matrices.py}

section{Block operations}
inputminted{python}{src/blocks.py}


and so on for several files. Is there a way to count the number of lines in these files and output a total.



Python pseudo code:



paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
for path in paths:
total += linecount(path)
print(str(total))


Any similar questions I found were for listings and only one file.



Edit: To be clear, I want to do this in latex, the python code is to illustrate.










share|improve this question














I am using minted to show source code in my document like this:



section{Image functions}
inputminted{python}{src/imagefuncs.py}

section{Matrix operations}
inputminted{python}{src/matrices.py}

section{Block operations}
inputminted{python}{src/blocks.py}


and so on for several files. Is there a way to count the number of lines in these files and output a total.



Python pseudo code:



paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
for path in paths:
total += linecount(path)
print(str(total))


Any similar questions I found were for listings and only one file.



Edit: To be clear, I want to do this in latex, the python code is to illustrate.







minted loops line-numbering






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 6 '15 at 2:11









olehermanseolehermanse

111




111





bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 22 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • you can use python inside tex with the python library. You can check for example this answer.

    – Kpym
    Apr 9 '16 at 15:08



















  • you can use python inside tex with the python library. You can check for example this answer.

    – Kpym
    Apr 9 '16 at 15:08

















you can use python inside tex with the python library. You can check for example this answer.

– Kpym
Apr 9 '16 at 15:08





you can use python inside tex with the python library. You can check for example this answer.

– Kpym
Apr 9 '16 at 15:08










2 Answers
2






active

oldest

votes


















0














The following code will print the code listing and a line count (global). Please note that this is definitely not the most efficient approach.



linecount



% arara: pdflatex: { shell: 1 }
%!TeX TS-program=arara
documentclass{article}
usepackage[utf8]{inputenc}
usepackage{minted}
usepackage{expl3,xparse}

begin{filecontents*}{test1.py}
paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
for path in paths:
total += linecount(path)
print(str(total))
end{filecontents*}
begin{filecontents*}{test2.py}
paths = ['src.py', 'matrices.py', 'blocks.py']
total = 0
end{filecontents*}

ExplSyntaxOn
int_new:N g__ole_lines_int
cs_new_nopar:Npn __ole_countlines:n #1
{
ior_open:Nn g_tmpa_ior { #1 }
ior_str_map_inline:Nn g_tmpa_ior
{ int_gincr:N g__ole_lines_int }
ior_close:N g_tmpa_ior
}
NewDocumentCommand { inputcode } { m }
{
inputminted { python } { #1 }
__ole_countlines:n { #1 }
}
NewDocumentCommand { showlines } { }
{
int_use:N g__ole_lines_int
}
ExplSyntaxOff

begin{document}
inputcode{test1.py}
showlines
inputcode{test2.py}
showlines
end{document}





share|improve this answer































    0














    You can add a key, which I call addlines to the inputminted commands you want the total number of lines is taken care of.



    begin{filecontents*}{test1.py}
    paths = ['src.py', 'matrices.py', 'blocks.py']
    total = 0
    for path in paths:
    total += linecount(path)
    print(str(total))
    end{filecontents*}

    begin{filecontents*}{test2.py}
    paths = ['src.py', 'matrices.py', 'blocks.py']
    total = 0
    end{filecontents*}

    documentclass{article}
    usepackage[utf8]{inputenc}
    usepackage{minted}
    usepackage{xpatch}

    makeatletter
    define@key{minted@opt@cmd}{addlines}[true]{csname @addlines#1endcsname}
    xpatchcmd{inputminted}
    {endgroup}
    {if@addlinesaddtocounter{totallines}{value{FancyVerbLine}}fiendgroup}
    {}{}
    newifif@addlines
    newcounter{totallines}
    makeatother

    begin{document}

    inputminted[addlines]{python}{test1.py}
    inputminted[addlines]{python}{test2.py}

    The total number of code lines is thetotallines

    end{document}


    enter image description here






    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
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f276902%2fcount-lines-of-multiple-files-using-minted-for-formatting%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









      0














      The following code will print the code listing and a line count (global). Please note that this is definitely not the most efficient approach.



      linecount



      % arara: pdflatex: { shell: 1 }
      %!TeX TS-program=arara
      documentclass{article}
      usepackage[utf8]{inputenc}
      usepackage{minted}
      usepackage{expl3,xparse}

      begin{filecontents*}{test1.py}
      paths = ['src.py', 'matrices.py', 'blocks.py']
      total = 0
      for path in paths:
      total += linecount(path)
      print(str(total))
      end{filecontents*}
      begin{filecontents*}{test2.py}
      paths = ['src.py', 'matrices.py', 'blocks.py']
      total = 0
      end{filecontents*}

      ExplSyntaxOn
      int_new:N g__ole_lines_int
      cs_new_nopar:Npn __ole_countlines:n #1
      {
      ior_open:Nn g_tmpa_ior { #1 }
      ior_str_map_inline:Nn g_tmpa_ior
      { int_gincr:N g__ole_lines_int }
      ior_close:N g_tmpa_ior
      }
      NewDocumentCommand { inputcode } { m }
      {
      inputminted { python } { #1 }
      __ole_countlines:n { #1 }
      }
      NewDocumentCommand { showlines } { }
      {
      int_use:N g__ole_lines_int
      }
      ExplSyntaxOff

      begin{document}
      inputcode{test1.py}
      showlines
      inputcode{test2.py}
      showlines
      end{document}





      share|improve this answer




























        0














        The following code will print the code listing and a line count (global). Please note that this is definitely not the most efficient approach.



        linecount



        % arara: pdflatex: { shell: 1 }
        %!TeX TS-program=arara
        documentclass{article}
        usepackage[utf8]{inputenc}
        usepackage{minted}
        usepackage{expl3,xparse}

        begin{filecontents*}{test1.py}
        paths = ['src.py', 'matrices.py', 'blocks.py']
        total = 0
        for path in paths:
        total += linecount(path)
        print(str(total))
        end{filecontents*}
        begin{filecontents*}{test2.py}
        paths = ['src.py', 'matrices.py', 'blocks.py']
        total = 0
        end{filecontents*}

        ExplSyntaxOn
        int_new:N g__ole_lines_int
        cs_new_nopar:Npn __ole_countlines:n #1
        {
        ior_open:Nn g_tmpa_ior { #1 }
        ior_str_map_inline:Nn g_tmpa_ior
        { int_gincr:N g__ole_lines_int }
        ior_close:N g_tmpa_ior
        }
        NewDocumentCommand { inputcode } { m }
        {
        inputminted { python } { #1 }
        __ole_countlines:n { #1 }
        }
        NewDocumentCommand { showlines } { }
        {
        int_use:N g__ole_lines_int
        }
        ExplSyntaxOff

        begin{document}
        inputcode{test1.py}
        showlines
        inputcode{test2.py}
        showlines
        end{document}





        share|improve this answer


























          0












          0








          0







          The following code will print the code listing and a line count (global). Please note that this is definitely not the most efficient approach.



          linecount



          % arara: pdflatex: { shell: 1 }
          %!TeX TS-program=arara
          documentclass{article}
          usepackage[utf8]{inputenc}
          usepackage{minted}
          usepackage{expl3,xparse}

          begin{filecontents*}{test1.py}
          paths = ['src.py', 'matrices.py', 'blocks.py']
          total = 0
          for path in paths:
          total += linecount(path)
          print(str(total))
          end{filecontents*}
          begin{filecontents*}{test2.py}
          paths = ['src.py', 'matrices.py', 'blocks.py']
          total = 0
          end{filecontents*}

          ExplSyntaxOn
          int_new:N g__ole_lines_int
          cs_new_nopar:Npn __ole_countlines:n #1
          {
          ior_open:Nn g_tmpa_ior { #1 }
          ior_str_map_inline:Nn g_tmpa_ior
          { int_gincr:N g__ole_lines_int }
          ior_close:N g_tmpa_ior
          }
          NewDocumentCommand { inputcode } { m }
          {
          inputminted { python } { #1 }
          __ole_countlines:n { #1 }
          }
          NewDocumentCommand { showlines } { }
          {
          int_use:N g__ole_lines_int
          }
          ExplSyntaxOff

          begin{document}
          inputcode{test1.py}
          showlines
          inputcode{test2.py}
          showlines
          end{document}





          share|improve this answer













          The following code will print the code listing and a line count (global). Please note that this is definitely not the most efficient approach.



          linecount



          % arara: pdflatex: { shell: 1 }
          %!TeX TS-program=arara
          documentclass{article}
          usepackage[utf8]{inputenc}
          usepackage{minted}
          usepackage{expl3,xparse}

          begin{filecontents*}{test1.py}
          paths = ['src.py', 'matrices.py', 'blocks.py']
          total = 0
          for path in paths:
          total += linecount(path)
          print(str(total))
          end{filecontents*}
          begin{filecontents*}{test2.py}
          paths = ['src.py', 'matrices.py', 'blocks.py']
          total = 0
          end{filecontents*}

          ExplSyntaxOn
          int_new:N g__ole_lines_int
          cs_new_nopar:Npn __ole_countlines:n #1
          {
          ior_open:Nn g_tmpa_ior { #1 }
          ior_str_map_inline:Nn g_tmpa_ior
          { int_gincr:N g__ole_lines_int }
          ior_close:N g_tmpa_ior
          }
          NewDocumentCommand { inputcode } { m }
          {
          inputminted { python } { #1 }
          __ole_countlines:n { #1 }
          }
          NewDocumentCommand { showlines } { }
          {
          int_use:N g__ole_lines_int
          }
          ExplSyntaxOff

          begin{document}
          inputcode{test1.py}
          showlines
          inputcode{test2.py}
          showlines
          end{document}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 30 '17 at 16:04









          TeXnicianTeXnician

          26.2k63492




          26.2k63492























              0














              You can add a key, which I call addlines to the inputminted commands you want the total number of lines is taken care of.



              begin{filecontents*}{test1.py}
              paths = ['src.py', 'matrices.py', 'blocks.py']
              total = 0
              for path in paths:
              total += linecount(path)
              print(str(total))
              end{filecontents*}

              begin{filecontents*}{test2.py}
              paths = ['src.py', 'matrices.py', 'blocks.py']
              total = 0
              end{filecontents*}

              documentclass{article}
              usepackage[utf8]{inputenc}
              usepackage{minted}
              usepackage{xpatch}

              makeatletter
              define@key{minted@opt@cmd}{addlines}[true]{csname @addlines#1endcsname}
              xpatchcmd{inputminted}
              {endgroup}
              {if@addlinesaddtocounter{totallines}{value{FancyVerbLine}}fiendgroup}
              {}{}
              newifif@addlines
              newcounter{totallines}
              makeatother

              begin{document}

              inputminted[addlines]{python}{test1.py}
              inputminted[addlines]{python}{test2.py}

              The total number of code lines is thetotallines

              end{document}


              enter image description here






              share|improve this answer




























                0














                You can add a key, which I call addlines to the inputminted commands you want the total number of lines is taken care of.



                begin{filecontents*}{test1.py}
                paths = ['src.py', 'matrices.py', 'blocks.py']
                total = 0
                for path in paths:
                total += linecount(path)
                print(str(total))
                end{filecontents*}

                begin{filecontents*}{test2.py}
                paths = ['src.py', 'matrices.py', 'blocks.py']
                total = 0
                end{filecontents*}

                documentclass{article}
                usepackage[utf8]{inputenc}
                usepackage{minted}
                usepackage{xpatch}

                makeatletter
                define@key{minted@opt@cmd}{addlines}[true]{csname @addlines#1endcsname}
                xpatchcmd{inputminted}
                {endgroup}
                {if@addlinesaddtocounter{totallines}{value{FancyVerbLine}}fiendgroup}
                {}{}
                newifif@addlines
                newcounter{totallines}
                makeatother

                begin{document}

                inputminted[addlines]{python}{test1.py}
                inputminted[addlines]{python}{test2.py}

                The total number of code lines is thetotallines

                end{document}


                enter image description here






                share|improve this answer


























                  0












                  0








                  0







                  You can add a key, which I call addlines to the inputminted commands you want the total number of lines is taken care of.



                  begin{filecontents*}{test1.py}
                  paths = ['src.py', 'matrices.py', 'blocks.py']
                  total = 0
                  for path in paths:
                  total += linecount(path)
                  print(str(total))
                  end{filecontents*}

                  begin{filecontents*}{test2.py}
                  paths = ['src.py', 'matrices.py', 'blocks.py']
                  total = 0
                  end{filecontents*}

                  documentclass{article}
                  usepackage[utf8]{inputenc}
                  usepackage{minted}
                  usepackage{xpatch}

                  makeatletter
                  define@key{minted@opt@cmd}{addlines}[true]{csname @addlines#1endcsname}
                  xpatchcmd{inputminted}
                  {endgroup}
                  {if@addlinesaddtocounter{totallines}{value{FancyVerbLine}}fiendgroup}
                  {}{}
                  newifif@addlines
                  newcounter{totallines}
                  makeatother

                  begin{document}

                  inputminted[addlines]{python}{test1.py}
                  inputminted[addlines]{python}{test2.py}

                  The total number of code lines is thetotallines

                  end{document}


                  enter image description here






                  share|improve this answer













                  You can add a key, which I call addlines to the inputminted commands you want the total number of lines is taken care of.



                  begin{filecontents*}{test1.py}
                  paths = ['src.py', 'matrices.py', 'blocks.py']
                  total = 0
                  for path in paths:
                  total += linecount(path)
                  print(str(total))
                  end{filecontents*}

                  begin{filecontents*}{test2.py}
                  paths = ['src.py', 'matrices.py', 'blocks.py']
                  total = 0
                  end{filecontents*}

                  documentclass{article}
                  usepackage[utf8]{inputenc}
                  usepackage{minted}
                  usepackage{xpatch}

                  makeatletter
                  define@key{minted@opt@cmd}{addlines}[true]{csname @addlines#1endcsname}
                  xpatchcmd{inputminted}
                  {endgroup}
                  {if@addlinesaddtocounter{totallines}{value{FancyVerbLine}}fiendgroup}
                  {}{}
                  newifif@addlines
                  newcounter{totallines}
                  makeatother

                  begin{document}

                  inputminted[addlines]{python}{test1.py}
                  inputminted[addlines]{python}{test2.py}

                  The total number of code lines is thetotallines

                  end{document}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 26 '18 at 23:37









                  egregegreg

                  736k8919353262




                  736k8919353262






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f276902%2fcount-lines-of-multiple-files-using-minted-for-formatting%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

                      El tren de la libertad Índice Antecedentes "Porque yo decido" Desarrollo de la...

                      Puerta de Hutt Referencias Enlaces externos Menú de navegación15°58′00″S 5°42′00″O /...

                      Castillo d'Acher Características Menú de navegación