1

我试图让Pweave以逐字以外的形式生成 LaTeX 文件,以便我可以向文档添加一些功能(徽标、脚注等......)。
就我喜欢 Pweave 的易用性和便利性而言,我一直无法做到。

darwin pweave 上的 Python 3.5.2(v3.5.2:4def2a2901a5,2016 年 6 月 26 日,10:47:25)[GCC 4.2.1(Apple Inc. build 5666)(点 3)]。版本是“0.25”

请问有没有人要领?

代码示例(全部在 Python Pweave 中,用于说明目的):

#' 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()

谢谢!

4

1 回答 1

2

我从您的代码库创建了示例源文件:一个是基于逐字的输出,另一个是使用 Minted 包进行语法突出显示,以便您看到差异。唯一的区别仅在于在源代码中的其他包中添加了 \usepackage{minted}。

逐字使用: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}

使用 Minted 进行语法高亮: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}

现在,使用以下命令生成 pdf 文件:

  1. 逐字

    • pweave -f tex test_pweave_verbatim.texw
    • pdflatex test_pweave_verbatim.tex
  2. 铸造的

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

使用 Python 2.7.10 和 Pweave 0.25 在 OSX 10.11.4 中测试。

于 2016-12-12T01:36:59.607 回答