本文介绍了通过IPython Notebook转换更改PDF-Latex输出的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前使用以下命令:

$ 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

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

With IPython 2.1, I got the latex file that are formatted with the standard classical style:

我的问题是:


  1. 我应该怎样做才能从ipython命令获得以下风格?

  1. What should I do so that I can get the following style, right from ipython command?

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

Why the above command doesn't enable the author to appear?


推荐答案

与OP一样,我对 nbconvert IPython 2 输出不满意。由于转换器不再使用Sphinx文档类或Sphinx预处理系统,因此您无法在nbconverter行上使用 SphinxTransformer 调用。

Like the OP, I'm not very happy with IPython 2 output from nbconvert. Since the converter no longer uses the Sphinx documentclass or the Sphinx preprocessing system, you can't use the SphinxTransformer calls on the nbconverter line.

Drop - 发布PDF 所以 nbconvert 只创建 .tex 文件。然后,编辑 .tex 文件以使其更漂亮。然后,在其上运行 pdflatex 几次。

Drop --post PDF so nbconvert creates just the .tex file. Then, edit the .tex file to make it prettier. Then, run pdflatex on it a few times.

为了让自己成为作者,在他的 \title 行之后添加如下所示的行 .tex 档案:

To make yourself the author, add a line like the following right after the \title line in the he .tex file:

\author{Never Saint}

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

You can find nice templates to help you make output look like what you want at latextemplates.com.

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

Another approach is to roll a new template, starting with the ones in .../IPython/nbconvert/templates/latex. As the root user, add an article1.tplx file next to article.tplx and report.tplx. The following version creates a different output style that I personally find useful. The "margins" block produces front matter for LaTex, and the "predoc" block produces commands and text that are inserted at the start of the document. I blank out the "maketitle" block so there's no title page. Delete my empty "maketitle" block if you want to have a title page with an author and a date.

用法: nbconvert - 乳胶yourNotebook.ipynb - 模板第1条 - 到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 *))

这篇关于通过IPython Notebook转换更改PDF-Latex输出的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 04:37