Currently with the following command of my .ipynb file:
$ 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
With IPython 2.1, I got the latex file that are formatted with the standard classical style:
My questions are:
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?
Like the OP, I'm not very happy with
IPython 2
output fromnbconvert
. Since the converter no longer uses the Sphinx documentclass or the Sphinx preprocessing system, you can't use theSphinxTransformer
calls on the nbconverter line.The Rude-and-Crude Way
Drop
--post PDF
sonbconvert
creates just the.tex
file. Then, edit the.tex
file to make it prettier. Then, runpdflatex
on it a few times.To make yourself the author, add a line like the following right after the
\title
line in the he.tex
file:You can find nice templates to help you make output look like what you want at
latextemplates.com
.The Root-User's Way
Another approach is to roll a new template, starting with the ones in
.../IPython/nbconvert/templates/latex
. As the root user, add anarticle1.tplx
file next toarticle.tplx
andreport.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.Usage:
nbconvert --to latex yourNotebook.ipynb --template article1 --to PDF
Solving this problem is a real pain-in-the-butt. I also liked the iPython 0.x and 1.x styling. If you must have it, here's how you can do it.
Folks mentioned that you can create your own template. Well, iPython 1.x had perfectly good templates, so let's use them. I'm going to assume you have root on your machine, because we're going to hack our iPython's templates/latex directory.
Now, the next step is to apply a patch to sphinx.tplx.
Cut and paste the above code to create the patch file. Then you can apply it with:
We're not done yet. Those templates need some support.
We'll do this back in the directory where the notebook you want to convert lives. We're going to create two python files. The first (I called it oldschool.py) does the preprocessing necessary to use the older templates. It is mostly scraped out of version 1.x iPython's nbconvert/transformers/sphinx.py and hacked to be a modern Preprocessor:
The last file is easy ({config.py}).
Now, at the command line, you can do:
If you want to use basic (aka, {the old_latex_basic.tplx} file), you'll have to hack in the the main block of code we added to sphinx.tplx (the portion between the % MEF NEW NEW MEF comments).
You probably have to either select a different template, or build your own. Try e.g. adding the
--template book
argument to yournbconvert
command.Since IPython 2 doesn't have the
book
template anymore, you'll probably need to roll your own.