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: Export flavors & PDF writer (ipy dev meeting) #3784

Merged
merged 30 commits into from Jul 27, 2013

Conversation

jdfreder
Copy link
Member

  • Lightweight subclasses reduced in quantity

  • Added post processors

  • --format param is now --to

  • --post PDF flag added which creates and uses the new (introduced in this PR) PDFPostProcessor

    See the following excerpt from help:
    
    You can specify the export format with `--to`.
    Options include {0}
    
    > ipython nbconvert --to latex mynotebook.ipnynb
    
    Both HTML and LaTeX support multiple output templates. LaTeX includes
    'basic', 'book', and 'article'.  HTML includes 'basic' and 'full'.  You 
    can specify the flavor of the format used.
    
    > ipython nbconvert --to html --template reveal mynotebook.ipnynb
    
    You can also pipe the output to stdout, rather than a file
    
    > ipython nbconvert mynotebook.ipynb --stdout
    
    A post-processor can be used to compile a PDF
    
    > ipython nbconvert mynotebook.ipynb --to latex --post PDF
    

See requirements listed in dev meeting hackpad:
https://hackpad.com/IPython-Summer-2013-Development-Meeting-D1UR23usGnA

@jhamrick
Copy link
Contributor

There was some discussion about referring to reveal as just "slides" or "presentation", e.g.:

> ipython nbconvert --to html --flavor slides mynotebook.ipnynb

It's essentially the same idea as not mentioning sphinx with the LaTeX book/article flavor. Is that something we still want to do?

@minrk
Copy link
Member

minrk commented Jul 25, 2013

I think it was also considered that reveal would be --to slides --flavor reveal. It remains unclear to me what is best.

@jdfreder
Copy link
Member Author

@jhamrick I talked to @ellisonbg about that a couple minutes ago, he prefered --to html --flavor reveal.

Personally I prefer --to html --flavor slides

I decided against --to slides or --to slides --flavor reveal because slides really isn't a data format, where all the other choices are.

@jdfreder
Copy link
Member Author

We should talk about it again... I'll bring it up when I show this stuff working

@jdfreder
Copy link
Member Author

minutes = hours*

@damianavila
Copy link
Member

I agree with @minrk... I prefer --to slides --flavor reveal because if the ipython team is interesting I can do:

--to slides --flavor impress
or
--to slides --flavor deck
or
--to slides --flavor flowtime

all other slideshows libraries I want to add in the future ;-)

@damianavila
Copy link
Member

if not inside IPython core, if I release this flavors as extension, I would be great to have a sintaxis as --to slides --flavor whatever ;-)

@jdfreder
Copy link
Member Author

I guess data format isn't what I should have been thinking about, since the whole reason for the subclasses is the ability to configure based on that particular format... I'll change it to slides, one minute...

@jhamrick
Copy link
Contributor

@damianavila I guess the question is, does IPython want to have just one type of HTML slides/presentation that it natively supports, or many? There is also going to be the option to use --template to specify a specific jinja template (e.g. --template impress.tpl). I would lean more towards having just one default type of slides in the IPython core, and if you want to use something beyond that, specify a specific template. My guess would be that someone who just wants to create a presentation and doesn't really care what the backend is would be confused by the various options. I suppose if we had --to slides then that could just have a reasonable default.

@jdfreder You mean change it to --to slides? If support for beamer slides ever got added, would that then go under --to slides --flavor beamer or --to latex --flavor slides?

@jdfreder
Copy link
Member Author

yes, and the first of the two

@jhamrick
Copy link
Contributor

Hmm, ok. It could be a bit confusing because beamer is LaTeX (and presumably --to slides --flavor beamer would output a .tex file -- as would all the --to latex conversions). Maybe there isn't really a good solution though; it's a tradeoff between how obvious the flags are and how many options/flavors can be supported.

@jakobgager
Copy link
Contributor

I also agree with @minrk. In the end the outcome should be what matters and a presentation is something complete different than a webpage! In this context LaTeX Beamer would be an extreme case of an presentation, even though a tex file.

@damianavila deck looks awesome!

@damianavila
Copy link
Member

@jhamrick probably IPython will support one type of HTML slides/presentations at the core (@minrk @fperez @ellisonbg @Carreau thoughs?) ... but the proposed syntax (--to slides --flavor whatever) will help me (and others) to bring another kind of HTML slides as extensions.
About custom templating... there will be the possibility to add you own template, in that case something like --to slides --flavor whatever --template=custom_tpl will be easy to understand and gives you the possibility of multiple outputs for the same "flavor"...

@damianavila
Copy link
Member

@jakobgager yes, all this js libraries are very powerful, just I need some more time to make them available... they are in my todo list (a very large one... hehe).

@jdfreder
Copy link
Member Author

Hey all, I change it so --to slides works and defaults to reveal flavor. In the future the default flavor may change, but explicitly exporting to --to slides --flavor reveal will always export to reveal.

@jhamrick
Copy link
Contributor

@jakobgager Yeah, fair enough.

@damianavila I think the idea with templates was that they would be instead of a flavor, rather than in addition to. The analogy Fernando used I believe was that you can order e.g. a hawaiian pizza (flavor), but if you want a hawaiian pizza with spinach you need to just give the restaurant a new recipe of ham+pineapple+spinach (template).

@jdfreder
Copy link
Member Author

@jhamrick exactly, that said, --template still works... I think I forgot to mention that. --template overrides --flavor

@damianavila
Copy link
Member

@jdfreder thx for the clarification...

@jhamrick you are right, I was thinking in other sort of structure without reading the code ;-)

@jdfreder
Copy link
Member Author

--template now includes the functionality of --flavor. --flavor was removed.

  • ipython nbconvert --to latex --pdf
  • ipython nbconvert --to latex --template book --pdf
  • ipython nbconvert --to latex --template latex_book --pdf
  • ipython nbconvert --to latex --template latex_book.tplx --pdf

should all work...

@jdfreder
Copy link
Member Author

Don't merge yet

@damianavila
Copy link
Member

One thing it is not clear to me... what about the location of the custom template file? I mean, if I wrote a custom template and I want to use it doing ipython nbconvert --to latex --template my_template, where I have to locate my_template? Inside the templates folder of the IPython installation? or how I pass this location to the FileSystemLoader in an easy way?

@Carreau
Copy link
Member

Carreau commented Jul 26, 2013

where I have to locate my_template? Inside the templates folder of the IPython installation?

This will work. There is also IIRC the possibility to add custom search locations.

or how I pass this location to the FileSystemLoader in an easy way?

the worth that can happend is you have to instanciate a loader in your config file:

from jinja import FilesystemLoader

c.IDontRemember.extra_loader = [FilesystemLoader('my/path')]

Advantages are you don't even need to use a template file, you could use a dict loader, or a mondodb loader...

it is slightly more complicated that just giving a path, but nbconvert is still a tech preview, and I thing we are already trying to over-engenier it.

@damianavila
Copy link
Member

There is also IIRC the possibility to add custom search locations.

Overwriting this one? https://github.com/jdfreder/ipython/blob/98ef91d1c49a185ff508bb31ba014465b1249df3/IPython/nbconvert/exporters/exporter.py#L111

instanciate a loader in your config file:

Oh, I missed that point, you can add extra_loaders... great!

it is slightly more complicated that just giving a path

Yeah, maybe in the future we can provide the UI at the command line add your custom template.

@Carreau
Copy link
Member

Carreau commented Jul 26, 2013

Overwriting this one?

No, because it does not have config=True, but the one 2 lines above yes, and it will take precedence.

Yeah, maybe in the future we can provide the UI at the command line add your custom template.

You mean template path because you can specify template from CL. actually you can even write a myconfig.py and just do ipython nbconvert --config=myconfig.py and "it works".

@damianavila
Copy link
Member

You mean template path

Yes, I was talking about the path, sorry to not be clear enough.

@damianavila
Copy link
Member

No, because it does not have config=True, but the one 2 lines above yes, and it will take precedence.

Great... thanks!

@jdfreder
Copy link
Member Author

@damianavila You should be able to put it in your cwd once my other PR gets merged ( #3752 )... It seems to be not moving anywhere though

Also, template_file (alias --template), behaves both as the flavor (a shortcut for template name) and the template . See the following snipped from Exporter.py, lines 206-209

try_names = [self.template_file + self.template_extension,
    self.template_file,
    module_name + '_' + self.template_file + self.template_extension,
    module_name + self.template_extension]

@damianavila
Copy link
Member

@jdfreder Thanks for the info about cwd... I did not know about that PR... I have to look deeper before asking ;-)

@jdfreder
Copy link
Member Author

Just rebased, adding @ivanov 's switch to the new tests...
Ready for code review

@damianavila
Copy link
Member

I am reading this in detail... I will report any doubts soon...

@minrk
Copy link
Member

minrk commented Jul 26, 2013

now needs rebase

@jdfreder
Copy link
Member Author

Just rebased

@@ -1,6 +1,7 @@
"""
Reveal slide show exporter.
Exporter that exports Basic HTML.
Copy link
Member

Choose a reason for hiding this comment

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

Exporter that exports HTML slides.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks

@minrk
Copy link
Member

minrk commented Jul 26, 2013

@ellisonbg and @fperez didn't like that, I'm indifferent. The idea was that --pdf would encourage someone to try --html etc.

Good enough for me.

@@ -83,14 +100,24 @@ def _classes_default(self):

which will convert mynotebook.ipynb to the default format (probably HTML).

You can specify the export format with `--format`.
You can specify the export format with `--to`.
Options include {0}
Copy link
Member

Choose a reason for hiding this comment

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

Options include ?

Copy link
Member

Choose a reason for hiding this comment

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

This gets formatted below

try_names = [self.template_file + self.template_extension,
self.template_file,
module_name + '_' + self.template_file + self.template_extension,
module_name + self.template_extension]
Copy link
Member

Choose a reason for hiding this comment

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

Can you tell me a use case for this last one? maybe I am tired ;-) but I can't figure it out a use case... thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, ipython nbconvert --to rst notebook1.ipynb

Copy link
Member Author

Choose a reason for hiding this comment

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

Or any other format without flavors

Copy link
Member

Choose a reason for hiding this comment

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

This is used for the flavor. When you have a default templates like markdown that don't have flavor like 'markdown_foo.tpl'

Copy link
Member

Choose a reason for hiding this comment

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

OK, thanks to both of you... I was thinking only in "flavored" things... got it!

@damianavila
Copy link
Member

OK, thanks to all for the clarifications... 👍 to merging ;-)

@@ -112,6 +140,7 @@ def _classes_default(self):
help="""Writer class used to write the
results of the conversion""")
writer_aliases = {'FilesWriter': 'IPython.nbconvert.writers.files.FilesWriter',
'PDFWriter': 'IPython.nbconvert.writers.pdf.PDFWriter',
Copy link
Member

Choose a reason for hiding this comment

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

This have to be erased because it is no longer more a writer ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh Thank you so much @damianavila for pointing this out! This may be why the tests failed

Copy link
Member

Choose a reason for hiding this comment

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

You are welcome... now in the morning I'm more attentive ;-)

jdfreder added a commit that referenced this pull request Jul 27, 2013
nbconvert: Export flavors & PDF writer (ipy dev meeting)
@jdfreder jdfreder merged commit a9c0f49 into ipython:master Jul 27, 2013
@Carreau
Copy link
Member

Carreau commented Jul 27, 2013

Yeaaaaah

@damianavila
Copy link
Member

Great!

@jdfreder jdfreder deleted the export_flavors branch March 10, 2014 18:42
@jgoppert
Copy link
Contributor

+1 for beamer slides flavor output. The recent changes to the template nbconvert backend allowed me to hack my own beamer support. It isn't perfect, but works well enough for me.

I'm using the reveal slide metadata info from IPython notebook to guide the latex creation. Also, I'm using the warsaw default theme that makes the section automatically appear at the top of the page so you don't have to worry about titling slides.

This template below/ embedded in the bash script, should serve as a decent latex beamer flavor starting point.

#!/bin/bash
curdir=$(pwd)
if [ $# != 4 ]
then
    echo "usage: $0 author date title notebook"
    exit -1
else
    author=$1
    date=$2
    title=$3
    notebook=$4
fi
rm -rf tmp
mkdir -p tmp
cd tmp
echo """
((*- extends 'base.tplx' -*))

((* block docclass *))
\documentclass{beamer}
\usetheme{Warsaw}
((* endblock docclass *))

((* block margins *))
((* endblock margins *))

((* block title *))
    \title{$title}
((* endblock title *))

((* block date *))
    \date{$date}
((* endblock date *))

((* block author *))
    \author{$author}
((* endblock author *))

((* block packages *))
    ((( super() )))
((* endblock packages *))

% Use reveal.js tags to handle skipping/ new slides etc
((* block any_cell *))
    ((* if cell.metadata.get('slideshow',{}).get('slide_type','-').lower() in ['skip'] *))
    ((* elif cell.metadata.get('slideshow',{}).get('slide_type','-').lower() in ['slide'] *))
        ((* if cell.level == 0 -*))
            \frame{\section
            \frame{
            ((( super() )))
            }
        ((* elif cell.level == 1 -*))
            \section{ ((( cell.source ))) }
            \frame{\sectionpage}
        ((* endif -*))
    ((* elif cell.metadata.get('slideshow',{}).get('slide_type','-').lower() in ['subslide'] *))
        \frame{
        ((( super() )))
        }
    ((* elif cell.metadata.get('slideshow',{}).get('slide_type','-').lower() in ['fragment'] *))
        ((( super() )))
    ((* else *))
        ((( super() )))
    ((* endif *)) 
((* endblock any_cell *))
""" > notebook.tplx
ipython nbconvert --quiet --to=latex \
    --template="notebook.tplx" \
    --post=PDF "$curdir/$notebook"
# vim:ts=4:sw=4:expandtab

mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
nbconvert: Export flavors & PDF writer (ipy dev meeting)
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.

None yet

7 participants