pythonpython-3.xlatextexpweave

Python Pweave to LaTeX


I am trying to get Pweave to generate a LaTeX file in a form other than verbatim so that I can add a few features to the doc (logo, footnotes etc...).
So far as much as I love Pweave for the ease of use and convenience, I have been unable to do so.

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin pweave.version is '0.25'

Anyone would have a lead please?

Example of code (all in Python Pweave, for illustration purpose):

#' let's print
[print (i) for i in range(10)]

#' let's plot
#' we import the modules
import matplotlib.pyplot as plt
import numpy as np

#' we set the var x and y
x = np.arange(1,10,1)
y = x**2

#' we plot!
plt.plot(x,y, color= 'red')
plt.show()

Thanks!


Solution

  • I created to examples source files from your code base: one is a verbatim based output and the other is using the Minted package for syntax highlighting, so that you see the difference. The only difference lies only in the addition of \usepackage{minted} among the other packages in the source code.

    Using verbatim: test_pweave_verbatim.texw

    \documentclass[a4paper,11pt,final]{article}
    \usepackage{fancyvrb, color, graphicx, hyperref, amsmath, url}
    \usepackage{palatino}
    \usepackage[a4paper,text={16.5cm,25.2cm},centering]{geometry}
    
    \hypersetup
    {   pdfauthor = {Name Surname},
      pdftitle={Simple test with Python and Matplotlib},
      colorlinks=TRUE,
      linkcolor=black,
      citecolor=blue,
      urlcolor=blue
    }
    
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{1.2ex}
    
    
    
    \title{Simple test with Python and Matplotlib}
    \author{Name Surname}
    \date{12nd December 2016}
    
    \begin{document}
    \maketitle
    
    \section{Introduction}
    
    Just a simple example!
    
    
    Plot stuff.
    
    <<caption="Test!">>=
    #' let's print
    [print (i) for i in range(10)]
    
    #' let's plot
    #' we import the modules
    import matplotlib.pyplot as plt
    import numpy as np
    #' we set the var x and y
    x = np.arange(1,10,1)
    y = x**2
    
    #' we plot!
    plt.plot(x,y, color= 'red')
    plt.show()
    @
    
    \section{End}
    
    A simple end.
    
    \end{document}
    

    Using Minted for syntax highlighting: test_pweave_minted.texw

    \documentclass[a4paper,11pt,final]{article}
    \usepackage{fancyvrb, color, graphicx, hyperref, amsmath, url}
    \usepackage{minted}
    \usepackage{palatino}
    \usepackage[a4paper,text={16.5cm,25.2cm},centering]{geometry}
    
    \hypersetup
    {   pdfauthor = {Name Surname},
      pdftitle={Simple test with Python and Matplotlib},
      colorlinks=TRUE,
      linkcolor=black,
      citecolor=blue,
      urlcolor=blue
    }
    
    \setlength{\parindent}{0pt}
    \setlength{\parskip}{1.2ex}
    
    
    
    \title{Simple test with Python and Matplotlib}
    \author{Name Surname}
    \date{12nd December 2016}
    
    \begin{document}
    \maketitle
    
    \section{Introduction}
    
    Just a simple example!
    
    
    Plot stuff.
    
    <<caption="Test!">>=
    #' let's print
    [print (i) for i in range(10)]
    
    #' let's plot
    #' we import the modules
    import matplotlib.pyplot as plt
    import numpy as np
    #' we set the var x and y
    x = np.arange(1,10,1)
    y = x**2
    
    #' we plot!
    plt.plot(x,y, color= 'red')
    plt.show()
    @
    
    \section{End}
    
    A simple end.
    
    \end{document}
    

    Now, use the following commands to generate the pdf files:

    1. Verbatim

      • pweave -f tex test_pweave_verbatim.texw
      • pdflatex test_pweave_verbatim.tex
    2. Minted

      • pweave -f texminted test_pweave_minted.texw
      • pdflatex -shell-escape test_pweave_minted.tex

    Tested in OSX 10.11.4 using Python 2.7.10 and Pweave 0.25.