Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbconvert: Latex template refactor #4112

Merged
merged 98 commits into from
Sep 23, 2013
Merged

Conversation

jdfreder
Copy link
Member

I'd like as much input from everyone as possible. It's a good time to make sure feature X won't be too hard to implement in the future.

Goals

  • Minimize future pull request for latex style changes
  • Separate working parts of the templates
  • Best effort to de-obfuscate the latex

Motivation

Design

Conditional inheritance is used select an output style. This may seem strange, but it is required to allow inheriting output templates to override media blocks and those blocks to be used by the output style. It also is a nice way of circumventing the need to require a cell style template per output template.

drawing

Features

  • 4 cell styles
    • python
    • ipython
    • black & white python
    • black & white ipython
  • 2 output templates
    • report
    • article

python cell style

python_colored


ipython cell style

ipython_colored


black & white python cell style

bw_python_colored


black & white ipython cell style

bw_ipython_colored

@ellisonbg
Copy link
Member

Did some in person review:

  • Move pygments definitions to the cell styles that needs them.
  • See if we really need alltt and/or fancyvrb?
  • Create Jinja2 blocks for title, author, date and abstract
  • Use inch margins all around
  • Use same name for draw_prompt macro in different styles
  • Sphinx release/version should be removed
  • Strip down the Sphinx preprocessor

@ellisonbg
Copy link
Member

Cell styles that we want to support:

  • Simple
  • Notebook
    • If we can simplify by getting rid of the colored/bordered box, we might
      be able to get rid of the fancy mdframed stuff and its problems
  • Python prompt version
    • B&W
    • Pygment colored
  • IPython prompt version
    • B&W
    • Pygment colored
    • How to handle Out[] prompts?

@jdfreder
Copy link
Member Author

jdfreder commented Sep 4, 2013

Updated description, rebased, and ready to test/review.

@jakobgager
Copy link
Contributor

The preview images look awesome! I hope to find some time in the near future to test this!

@jdfreder
Copy link
Member Author

jdfreder commented Sep 4, 2013

Thanks @jakobgager 😄

@jdfreder
Copy link
Member Author

jdfreder commented Sep 4, 2013

From in person review with @ellisonbg :

  • Add abstract to base
  • s/Book/Report
  • Remove continuation prompts
  • Blue/red color scheme for IPython
  • Change default for all templates to IPython

@jdfreder
Copy link
Member Author

jdfreder commented Sep 4, 2013

Also post review, added a bibliography block.

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

I updated the screenshots in the description to match the altered output for the ipython & bw ipython styles

@minrk
Copy link
Member

minrk commented Sep 5, 2013

from

nbconvert --to latex notebooks/Part\ 5\ -\ Rich\ Display\ System --post pdf

I get

[4 <./Part 5 - Rich Display System_files/Part 5 - Rich Display System_28_0.jpeg
>] [5]

! Package amsmath Error: \begin{aligned} allowed only in math mode.

See the amsmath package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.632 \nabla
             \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathb...

? 
! Emergency stop.

"""
# Generate Pygments definitions for Latex
resources["latex"] = {}
resources["latex"]["pygment_definitions"] = LatexFormatter().get_style_defs()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pygments

@minrk
Copy link
Member

minrk commented Sep 5, 2013

in general, when creating a bunch of files of a given class, prefix seems better than suffix (style_ipython rather than ipython_style)

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

prefix seems better than suffix

Good tip, I've uploaded the changes

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

! Package amsmath Error: \begin{aligned} allowed only in math mode.

Sounds like the funky logic I wrote to fix the $$ tag spacing on math (https://github.com/ipython/ipython/blob/master/IPython/nbconvert/filters/latex.py#L66) is failing, could you paste a small portion of the tex around that line (632) please?

@jakobgager
Copy link
Contributor

Funny issue. The first time I run pdflatex, latex complains about a missing language definition, and missing tikz.
However, when I run again this error disappears, even after deletion of all related files?

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

even after deletion of all related files?

Really? That is very very strange, haven't heard of anything like that so far. The new pdf post processor logic (that @ellisonbg wrote, which was just merged into master a couple days ago and has been rebased into this PR) should clean ALL of the temporary files between runs for you.

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

It should also automatically run pdflatex 3 times... I think it may abort if it encounters a critical failure, which may be a problem.. Maybe it should only abort on pdflatex failures after the final execution of pdflatex?

@jakobgager
Copy link
Contributor

The following notebook converted fine with ipython 1.0.0 but results in an latex error using your branch:
http://nbviewer.ipython.org/c295019818fc09b669a4
Issue is due to In[4]

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

Thanks @jakobgager I'll take a look right now

@jakobgager
Copy link
Contributor

Regarding the funny issue, it is quite tricky to reproduce the error. However I managed again (rename + switching from-and-to virtualenv) the error was

[NbConvertApp] Converting notebook Dir_List.ipynb to latex
[NbConvertApp] Support files will be in Dir_List_files/
[NbConvertApp] Loaded template latex_article.tplx
[NbConvertApp] Writing 6493 bytes to Dir_List.tex
(stream_Test)jakob@jakob-ThinkPad:~/Projekte/ipython$ pdflatex Dir_List
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
 restricted \write18 enabled.
entering extended mode
(./Dir_List.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
...
   I removed some lines here
...
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty))

Package hyperref Message: Driver (autodetected): hpdftex.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))
(./Dir_List.aux

! Package babel Error: You haven't loaded the option english yet.

See the babel package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.19 \select@language{english}

? 
! Undefined control sequence.
l.23 \pgfsyspdfmark
                    {pgfid1}{7815060}{36203544}
? 

IIRC there was something similar with older versions, so it might not related to this at all.
Will investigate further.

@jakobgager
Copy link
Contributor

Btw. the I used the default calls for both issues nbconvert --to latex foo.ipynb

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

l.23 \pgfsyspdfmark {pgfid1}{7815060}{36203544}

I used to get this error when I used the old simple cell style, left some of the temp files in the directory, and then tried to use the notebook cell style. The problem was that the temporary files didn't have the dependencies necessary to run the more complex tex. Still all the temporary files should be removed with the changes to the pdf post processor.... Not sure why you are seeing this

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

@jakobgager there was a missing escape_latex in the base, I just added it, please give a second whirl when you get a chance

@jdfreder
Copy link
Member Author

jdfreder commented Sep 5, 2013

It fixes the problem with your notebook on my machine.

@jakobgager
Copy link
Contributor

Works also on my machine. I just wonder if the Output of In4 should get some linebreaks?

@jdfreder
Copy link
Member Author

jdfreder commented Sep 6, 2013

It probably should, if it's not too complicated, #3959

((* elif cell.level == 6 -*))
((* block h6 -*))\\*\textit((* endblock h6 -*))
((*- endif -*))
{((( cell.source | citation2latex | escape_latex )))}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Remove line breaks

@jdfreder
Copy link
Member Author

@ellisonbg and @minrk , changes made after our video conversation on Friday and rebased against master.

@@ -15,26 +15,9 @@
#-----------------------------------------------------------------------------

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this file to nbconvert-examples with the rest of the sphinx template stuff.

@ellisonbg
Copy link
Member

Overall this looks good, I had a few small comments inline. Lets make sure that the removed cell styles and sphinx stuff gets move over to nbconvert-examples.

@ellisonbg
Copy link
Member

OK Travis is passing and everything looks good, merging.

ellisonbg added a commit that referenced this pull request Sep 23, 2013
nbconvert: Latex template refactor
@ellisonbg ellisonbg merged commit 04d60b8 into ipython:master Sep 23, 2013
@jdfreder jdfreder deleted the texrefact branch November 14, 2013 17:27
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
nbconvert: Latex template refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vertical offsets in LaTeX output for nbconvert
4 participants