From b09ea978611c1d0008fa76602ffa251ca1cb33c3 2013-02-21 18:05:32 From: Jonathan Frederic Date: 2013-02-21 18:05:32 Subject: [PATCH] Got both of the main template formats from sphinx rendering. Todo: [ ] Fill with NB data [ ] Move latex around and make use of latex base --- diff --git a/README.rst b/README.rst index 3cc826f..2f48e0c 100644 --- a/README.rst +++ b/README.rst @@ -1,20 +1,14 @@ ================================================================ - nbconvert: conversion utilities for the IPython notebook format + nbconvert Sphinx-Latex Jinja2 templates ================================================================ Overview ======== nbconvert provides command line utilities to convert to and from IPython -notebooks and standard formats: - -- ReST -- Markdown -- HTML -- PDF -- Python script - -As these tools mature, these utilities will be merged into IPython. +notebooks and standard formats. However, the latex formatting leaves +something to be desired. This repository contains a port of the beautiful +and popular Sphinx latex styles for nbconvert. Requirements ============ @@ -25,9 +19,4 @@ Sphinx-Latex: see http://jimmyg.org/blog/2009/sphinx-pdf-generation-with-latex.html -Running Tests -============= - -Using nbconvert -=============== diff --git a/templates/tex/latex_base.tplx b/templates/tex/latex_base.tplx index 901384f..cb9a667 100644 --- a/templates/tex/latex_base.tplx +++ b/templates/tex/latex_base.tplx @@ -67,9 +67,11 @@ it introduces a new line - +((= +%Doesn't work on my machine yet. TODO: Fix this. ((* block markdowncell scoped *))((( cell.source | markdown2latex ))) ((* endblock markdowncell *)) +=)) ((* block headingcell scoped *)) \section{((( cell.source)))} @@ -85,10 +87,18 @@ unknown type (((cell.type))) -((* block body *))\begin{document} -((( super() ))) -\end{document} -((* endblock*)) +((* block body *)) + + ((* block bodyBegin *)) + \begin{document} + ((* endblock bodyBegin *)) + + ((( super() ))) + + ((* block bodyEnd *)) + \end{document} + ((* endblock bodyEnd *)) +((* endblock body *)) ((* block header *)) %% This file was auto-generated by IPython. diff --git a/templates/tex/latex_sphinx_base.tplx b/templates/tex/latex_sphinx_base.tplx index 618986d..1ad9bd6 100644 --- a/templates/tex/latex_sphinx_base.tplx +++ b/templates/tex/latex_sphinx_base.tplx @@ -10,51 +10,119 @@ ((*- extends 'latex_base.tplx' -*)) -((============================================================================ - Header, overrides base - ==========================================================================)) +% Header, overrides base ((* block header *)) + + % Make sure that the sphinx doc style knows who it inherits from. + \def\sphinxdocclass{(((parentdocumentclass)))} + + % Declare the document class + \documentclass[letterpaper,10pt,english]{templates/tex/sphinx(((documentclass)))} + + % Imports + \usepackage[utf8]{inputenc} + \DeclareUnicodeCharacter{00A0}{\\nobreakspace} + \usepackage[T1]{fontenc} + \usepackage{babel} + \usepackage{times} + \usepackage{import} + \usepackage[Bjarne]{templates/tex/fncychap} + \usepackage{longtable} + \usepackage{templates/tex/sphinx} + \usepackage{multirow} + + % Document level variables + \title{((( nb.metadata.name )))} + \date{\today} + \release{} + \author{Unknown Author} + \newcommand{\sphinxlogo}{} + \renewcommand{\releasename}{Release} + \makeindex + + + ((* block sphinxheader *))((* endblock sphinxheader *)) -%\newcommand{\sphinxlogo}{} - -%% Generated by Sphinx (not really.) -\def\sphinxdocclass{((* block documentclass *))sphinxmanual((* endblock documentclass *))} -\documentclass[letterpaper,10pt,english]{report} -\usepackage[utf8]{inputenc} %(inputenc)s -\DeclareUnicodeCharacter{00A0}{\\nobreakspace} %(utf8extra)s -\usepackage[T1]{fontenc} %(fontenc)s -\usepackage{babel} %(babel)s -\usepackage{times} %(fontpkg)s -\usepackage{import} -\usepackage[Bjarne]{templates/tex/fncychap} -%\usepackage[Bjarne]{} %(fncychap)s -\usepackage{longtable} %(longtable)s -\usepackage{templates/tex/sphinx} -\usepackage{multirow} - -%"" (preamble)s - -\title{((( nb.metadata.name )))} %(title)s} -\date{} %(date)s} -\release{} %(release)s} -\author{} %(author)s} -\newcommand{\sphinxlogo}{} %(logo)s} -\renewcommand{\releasename}{Release} %(releasename)s} -\makeindex %(makeindex)s - -((* block sphinxstyle *))((* endblock sphinxstyle *)) ((* endblock header *)) -((* block body *)) -\begin{document} -%(shorthandoff)s -\maketitle -\tableofcontents %(tableofcontents)s +% Body +((* block bodyBegin *)) -\renewcommand{\indexname}{%(indexname)s} -\printindex %(printindex)s -\end{document} -((* endblock body *)) + % Start of the document + \begin{document} + \maketitle + \tableofcontents +((* endblock bodyBegin *)) +((* block bodyEnd *)) + + \renewcommand{\indexname}{Index} + \printindex + \end{document} +((* endblock bodyEnd *)) + +% Footer ((* block footer *)) ((* endblock footer *)) + +((*- block any_cell scoped -*)) + ((( cell.source))) + ((*- if cell.type in ['code'] -*)) + + ((*- block codecell scoped -*)) + ((*- block input_group -*)) + ((*- block in_prompt -*))((*- endblock in_prompt -*)) + ((*- block input -*))((*- endblock input -*)) + ((*- endblock input_group -*)) + ((*- if cell.outputs -*)) + ((*- block output_group -*)) + ((*- block output_prompt -*))((*- endblock output_prompt -*)) + ((*- block outputs -*)) + ((*- for output in cell.outputs -*)) + ((*- if output.output_type in ['pyout'] -*)) + ((*- block pyout scoped -*))((*- endblock pyout -*)) + ((*- elif output.output_type in ['stream'] -*)) + ((*- block stream scoped -*)) + ((*- if output.stream in ['stdout'] -*)) + ((*- block stream_stdout scoped -*)) + ((*- endblock stream_stdout -*)) + ((*- elif output.stream in ['stderr'] -*)) + ((*- block stream_stderr scoped -*)) + ((*- endblock stream_stderr -*)) + ((*- endif -*)) + ((*- endblock stream -*)) + ((*- elif output.output_type in ['display_data'] -*)) + ((*- block display_data scoped -*)) + ((*- block data_priority scoped -*)) + ((*- endblock data_priority -*)) + ((*- endblock display_data -*)) + ((*- elif output.output_type in ['pyerr'] -*)) + ((*- block pyerr scoped -*)) + ((*- for line in output.traceback -*)) + ((*- block traceback_line scoped -*))((*- endblock traceback_line -*)) + ((*- endfor -*)) + ((*- endblock pyerr -*)) + ((*- endif -*)) + ((*- endfor -*)) + ((*- endblock outputs -*)) + ((*- endblock output_group -*)) + ((*- endif -*)) + ((*- endblock codecell -*)) + ((*- elif cell.type in ['markdown'] -*)) + + ((*- block markdowncell scoped-*)) + ((*- endblock markdowncell -*)) + ((*- elif cell.type in ['heading'] -*)) + + ((*- block headingcell scoped-*)) + ((*- endblock headingcell -*)) + ((*- elif cell.type in ['raw'] -*)) + + ((*- block rawcell scoped-*)) + ((*- endblock rawcell -*)) + ((*- else -*)) + + ((*- block unknowncell scoped-*)) + ((*- endblock unknowncell -*)) + ((*- endif -*)) +((*- endblock any_cell -*)) diff --git a/templates/tex/latex_sphinx_howto.tplx b/templates/tex/latex_sphinx_howto.tplx index e1b75a7..174cd71 100644 --- a/templates/tex/latex_sphinx_howto.tplx +++ b/templates/tex/latex_sphinx_howto.tplx @@ -10,7 +10,7 @@ ((*- extends 'latex_sphinx_base.tplx' -*)) -((* block documentclass *))sphinxhowto((* endblock documentclass *)) -((* block sphinxstyle *))((* include 'sphinxhowto.cls' *))((* endblock sphinxstyle *)) +((* set parentdocumentclass = 'article' *)) +((* set documentclass = 'howto' *)) diff --git a/templates/tex/latex_sphinx_manual.tplx b/templates/tex/latex_sphinx_manual.tplx index a63bfaf..d9e0c5e 100644 --- a/templates/tex/latex_sphinx_manual.tplx +++ b/templates/tex/latex_sphinx_manual.tplx @@ -10,5 +10,5 @@ ((*- extends 'latex_sphinx_base.tplx' -*)) -((* block documentclass *))sphinxmanual((* endblock documentclass *)) -((* block sphinxstyle *))((* include 'sphinxmanual.cls' *))((* endblock sphinxstyle *)) +((* set parentdocumentclass = 'report' *)) +((* set documentclass = 'manual' *)) diff --git a/templates/tex/sphinxmanual.cls b/templates/tex/sphinxmanual.cls index 07fce3d..a04cea5 100644 --- a/templates/tex/sphinxmanual.cls +++ b/templates/tex/sphinxmanual.cls @@ -79,7 +79,7 @@ % Catch the end of the {abstract} environment, but here make sure the abstract % is followed by a blank page if the 'openright' option is used. - +% \let\py@OldEndAbstract=\endabstract \renewcommand{\endabstract}{ \if@openright @@ -117,7 +117,7 @@ % This is needed to get the width of the section # area wide enough in the % library reference. Doing it here keeps it the same for all the manuals. - +% \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.6em}} \renewcommand*\l@subsection{\@dottedtocline{2}{4.1em}{3.5em}}