通过IPython Notebook转换更改PDF-Latex输出的样式

nev*_*int 7 python pdf latex type-conversion ipython

目前使用我的.ipynb文件的以下命令:

$ ipython nbconvert --to latex --post PDF Untitled1.ipynb --SphinxTransformer.author="John Doe"
[NbConvertApp] Using existing profile dir: u'/Users/me-macmini/.ipython/profile_default'
[NbConvertApp] Converting notebook Untitled1.ipynb to latex
[NbConvertApp] Support files will be in Untitled1_files/
[NbConvertApp] Loaded template article.tplx
[NbConvertApp] Writing 12876 bytes to Untitled1.tex
[NbConvertApp] Building PDF
[NbConvertApp] Running pdflatex 3 times: [u'pdflatex', u'Untitled1.tex']
[NbConvertApp] Running bibtex 1 time: [u'bibtex', u'Untitled1']
[NbConvertApp] WARNING | bibtex had problems, most likely because there were no citations
[NbConvertApp] Removing temporary LaTeX files
[NbConvertApp] PDF successfully created
Run Code Online (Sandbox Code Playgroud)

使用IPython 2.1,我得到了使用标准经典样式格式化的乳胶文件:

在此输入图像描述

我的问题是:

  1. 我该怎么做才能从ipython命令获得以下样式? 在此输入图像描述

  2. 为什么以上命令不能使作者出现?

Fra*_*k M 6

和OP一样,我对IPython 2输出不太满意nbconvert.由于转换器不再使用Sphinx文档类或Sphinx预处理系统,因此无法使用SphinxTransformernbconverter行上的调用.

粗鲁和粗鲁的方式

删除--post PDF所以nbconvert只创建.tex文件.然后,编辑.tex文件使其更漂亮.然后,运行pdflatex几次.

要使自己成为作者,请\title在he .tex文件中的行后面添加如下所示的行:

\author{Never Saint}
Run Code Online (Sandbox Code Playgroud)

你可以找到漂亮的模板来帮助你使输出看起来像你想要的latextemplates.com.

Root用户的方式

另一种方法是滚动一个新模板,从中开始.../IPython/nbconvert/templates/latex.作为root用户,article1.tplxarticle.tplx和旁边添加一个文件report.tplx.以下版本创建了一种我认为有用的不同输出样式."边距"块为LaTex生成前端内容,"predoc"块生成在文档开头插入的命令和文本.我删掉了"maketitle"块,所以没有标题页.如果您想要一个包含作者和日期的标题页,请删除我的空"maketitle"块.

用法: nbconvert --to latex yourNotebook.ipynb --template article1 --to PDF

% Default to the notebook output style
((* if not cell_style is defined *))
    ((* set cell_style = 'style_ipython.tplx' *))
((* endif *))

% Inherit from the specified cell style.
((* extends cell_style *))


%===============================================================================
% Latex article1, based on Article 
%===============================================================================

((* block docclass *))
\documentclass{article}
((* endblock docclass *))
((* block margins *))
\usepackage{blindtext}
\usepackage{mathptmx}% Times Roman font
\usepackage[scaled=.90]{helvet}
\usepackage{xcolor}
\usepackage{titlesec}
\titleformat{\title}[display]
  {\normalfont\sffamily\huge\bfseries\color{blue}}
  {\titlename}{20pt}{\Huge}
\titleformat{\section}
  {\normalfont\sffamily\Large\bfseries\color{darkgray}}
  {\subsection}{1em}{} 
\titleformat{\subsection}
  {\normalfont\sffamily\Large\bfseries\color{darkgray}}
  {\thesubsection}{1em}{} 
\parindent=0pt
\parskip=6pt
((* endblock margins *))

((* block predoc *))
\begin{document}

\pagestyle{plain}
\thispagestyle{plain}
\pagenumbering{arabic}
\setcounter{page}{5}
\lfoot{\copyright 2014}

This document is composed as an
\href{http://ipython.org/notebook.html}{IPython} notebook. The printed
version of this document was generated from the \texttt{IPython}
notebook, using the \texttt{ipython nbconvert} utility to generate a
\texttt{Latex} document. 
((* block maketitle *))((* endblock maketitle *))
((* block author *))\author{Put Your Name Here}((* endblock author *))
((* endblock predoc *))
Run Code Online (Sandbox Code Playgroud)


Rol*_*ith 0

您可能必须选择不同的模板,或者构建自己的模板。尝试将参数添加--template book到您的nbconvert命令中。

由于 IPython 2 不再提供book模板,因此您可能需要自己推出模板。