jupyter / jupyter/nbconvert-examples

Template using listings.sty and more

Open
#20 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
176
Forks
78
PR merge metrics
No merged PRs in 30d

Description

Hi,

I've made some LaTeX templates that uses the listings.sty package for code display rather than the default fancyvrb.sty. I like this because it renders better on the final PDF and allows quite a bit of control via relatively simple customisation.

Maybe it could be useful to others as well

The template also does a few other things. Here's a list of changes relative to the `base.tplx` template

- Code and output typeset using listings.sty
- If an MD cell has the metadata attribute `purehtml` then use PanDoc to convert the content (assumed pure HTML) into LaTeX
- If an MD cell has the metadata attribute `toc`, replace the content of the cell with `\tableofcontents`. The macro `\contentname` is set according to `nb.metadata.toc.title_cell` if set.
- If an MD cell has the metadata attribute `pyref` then set the macro `\nextcaption` to the PanDoc converted content of the cell. The next listing will use the macro as the caption.

The files are

- `minebase.tplx` (for lack of better name) - Base template
- `minearticle.tplx` article class specialisation of the above
- `minereport.tplx` report class specialisation of the above

The code isn't great - it's my first go at doing templates for nbconvert - but I think a good starting point. Another caveat is that if one uses non ASCII characters in the code parts or section headings, then one _must_ use XeLaTeX (plain LaTeX and PDFLaTeX _never_ interprets multibyte characters as single characters, which then causes headaches).

I attach the files mentioned above, plus a Demo notebook and the notebook converted to LaTeX and rendered to PDF. I've put the templates and notebook in a ZIP archive. The PDF is as-is

- [Template.pdf](https://github.com/jupyter/nbconvert-examples/files/2664917/Template.pdf)
- [minetempl.zip](https://github.com/jupyter/nbconvert-examples/files/2664922/minetempl.zip)

Yours,

Christian

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing the attached minetempl.zip, including minebase.tplx, minearticle.tplx, minereport.tplx, and the demo notebook. Compare the templates with the existing base.tplx approach and inspect the supplied LaTeX and PDF outputs. Done means determining whether these listings.sty-based templates are suitable as an example contribution and documenting or integrating them accordingly.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, latex
Domain
documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.