Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
FEAT: Support for Individual PDF (requires sphinxcontrib-jupyter=0.5.…
Browse files Browse the repository at this point in the history
…0) (#701)

* added configuration for pdf latex

* add configuration for upcoming pdf compilation from sphinxcontrib-jupyter

* update authors

* spacing between texts

* add exclude document patterns for pdf construction

* add urlpath to conf.py

* remove redundant  command

* added conf variables and removed duplicate make command

* jupyterpdf builder to use BUILDDIR

* fix merge conflict

* template and makefile changes

* tpl with caption correction

* bib include and template path update

* title in theme to handle non ascii characters

* Update about_lectures.rst (#739)

* removed latin
  • Loading branch information
mmcky authored and arnavs committed Oct 4, 2019
1 parent d1a215b commit 3b8f871
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
_build/
_build_website/
_build_coverage/
_build_pdf/
dask-worker-space/
.DS_Store
**/.ipynb_checkpoints/
Expand Down
22 changes: 22 additions & 0 deletions Makefile
Expand Up @@ -9,6 +9,7 @@ SOURCEDIR = source/rst
BUILDDIR = _build
BUILDWEBSITE = _build/website
BUILDCOVERAGE = _build/coverage
BUILDPDF = _build/pdf
FILES =

# Put it first so that "make" without argument is like "make help".
Expand Down Expand Up @@ -38,6 +39,11 @@ clean-coverage:
clean-website:
rm -rf $(BUILDWEBSITE)

clean-pdf:
rm -rf $(BUILDDIR)/jupyterpdf

clean-constructor-pdf:
rm -rf $(BUILDPDF)
coverage:
ifneq ($(strip $(parallel)),)
@$(SPHINXBUILD) -M jupyter "$(SOURCEDIR)" "$(BUILDCOVERAGE)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_make_coverage=1 -D jupyter_execute_notebooks=1 -D jupyter_drop_tests=0 -D jupyter_ignore_skip_test=0 -D jupyter_template_coverage_file_path="error_report_template.html" -D jupyter_number_workers=$(parallel)
Expand All @@ -53,6 +59,22 @@ else
@$(SPHINXBUILD) -M jupyter "$(SOURCEDIR)" "$(BUILDWEBSITE)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_make_site=1 -D jupyter_generate_html=1 -D jupyter_download_nb=1 -D jupyter_execute_notebooks=1 -D jupyter_target_html=1 -D jupyter_download_nb_image_urlpath="https://s3-ap-southeast-2.amazonaws.com/julia.quantecon.org/_static/" -D jupyter_images_markdown=0 -D jupyter_html_template="julia-html.tpl" -D jupyter_download_nb_urlpath="https://julia.quantecon.org/" -D jupyter_coverage_dir=$(BUILDCOVERAGE)
endif

pdf:
ifneq ($(strip $(parallel)),)
@$(SPHINXBUILD) -M jupyterpdf "$(SOURCEDIR)" "$(BUILDDIR)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_latex_template="latex.tpl" -D jupyter_images_markdown=1 -D jupyter_execute_notebooks=1 -D jupyter_target_pdf=1 -D jupyter_number_workers=$(parallel)

else
@$(SPHINXBUILD) -M jupyterpdf "$(SOURCEDIR)" "$(BUILDDIR)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_latex_template="latex.tpl" -D jupyter_images_markdown=1 -D jupyter_execute_notebooks=1 -D jupyter_target_pdf=1
endif

constructor-pdf:
ifneq ($(strip $(parallel)),)
@$(SPHINXBUILD) -M jupyter "$(SOURCEDIR)" "$(BUILDPDF)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_images_markdown=1 -D jupyter_execute_notebooks=1 -D jupyter_number_workers=$(parallel)

else
@$(SPHINXBUILD) -M jupyter "$(SOURCEDIR)" "$(BUILDPDF)" $(FILES) $(SPHINXOPTS) $(O) -D jupyter_images_markdown=1 -D jupyter_execute_notebooks=1
endif

notebooks:
make jupyter

Expand Down
18 changes: 17 additions & 1 deletion conf.py
Expand Up @@ -438,6 +438,9 @@
# html template specific to your website needs
jupyter_html_template = None

# latex template specific to your website needs
jupyter_latex_template = ""

#make website
jupyter_make_site = False

Expand All @@ -463,4 +466,17 @@
'tools_and_techniques': []
}

jupyter_download_nb_execute=True
jupyter_download_nb_execute=True

### pdf options
jupyter_pdf_logo = "_static/img/qe-menubar-logo.png"

jupyter_bib_file = "_static/quant-econ"

jupyter_pdf_author = "Jesse Perla, Thomas J. Sargent and John Stachurski"

# Exclude Document Patterns for PDF Construction
jupyter_pdf_excludepatterns = ["404", "index", "references"]

# Set urlpath for html links in documents
jupyter_pdf_urlpath = "https://lectures.quantecon.org/jl/"
264 changes: 264 additions & 0 deletions theme/templates/latex.tpl
@@ -0,0 +1,264 @@
((*- extends 'article.tplx' -*))

% See http://blog.juliusschulz.de/blog/ultimate-ipython-notebook#templates
% for some useful tips

%===============================================================================
% Document class
%===============================================================================

((* block docclass *))
\documentclass[11pt, twoside, a4paper]{article}
((* endblock docclass *))

%===============================================================================
% Packages
%===============================================================================

((* block packages *))
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage[breakable]{tcolorbox}
% We will generate all images so they have a width \maxwidth. This means
% that they will get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics

% propose delete%
% Ensure that by default, figures have no caption (until we provide a
% proper Figure object with a Caption API and a way to capture that
% in the conversion process - todo).
% \usepackage{caption}
% \DeclareCaptionLabelFormat{empty}{}
%\captionsetup{format=empty,aboveskip=0pt,belowskip=0pt}
% end - propose delete%

% float figure settings%
\usepackage{float}
\floatplacement{figure}{H} % used to force figures for placement in text


\usepackage{adjustbox} % Used to constrain images to a maximum size
\usepackage{xcolor} % Allow colors to be defined
\usepackage{enumerate} % Needed for markdown enumerations to work
\usepackage{geometry} % Used to adjust the document margins
\usepackage{amsmath} % Equations
\usepackage{amssymb} % Equations
\usepackage{textcomp} % defines textquotesingle
% Hack from http://tex.stackexchange.com/a/47451/13684:
\AtBeginDocument{%
\def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code
}
\usepackage{upquote} % Upright quotes for verbatim code
\usepackage{eurosym} % defines \euro
\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support
\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document
\usepackage{fancyvrb} % verbatim replacement that allows latex
\usepackage{grffile} % extends the file name processing of package graphics
% to support a larger range
% The hyperref package gives us a pdf with properly built
% internal navigation ('pdf bookmarks' for the table of contents,
% internal cross-reference links, web links for URLs, etc.)
\usepackage{hyperref}
\usepackage{longtable} % longtable support required by pandoc >1.10
\usepackage{booktabs} % table support for pandoc > 1.12.2
\usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment)
\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout)
% normalem makes italics be italics, not underlines
\usepackage{braket}
\usepackage{mathrsfs}
\usepackage{natbib}
\usepackage[document]{ragged2e}
\usepackage{fontspec, unicode-math}
\usepackage{xunicode}
\usepackage[greek,english]{babel}
\setmonofont{LiberationMono}
\newcommand{\argmax}{\operatornamewithlimits{argmax}}
\newcommand{\argmin}{\operatornamewithlimits{argmin}}
\DeclareMathOperator{\col}{col}
\setlength{\parskip}{1.5ex plus0.5ex minus0.5ex}
\setlength{\parindent}{0pt}

% renew commands %
% Set max figure width to be 80% of text width, for now hardcoded.
\renewcommand{\includegraphics}[1]{\begin{center}\Oldincludegraphics[width=.8\maxwidth]{#1}\end{center}}
\renewcommand \caption [2][]{} % removes captions from all figures
((* endblock packages *))

% Colors for the hyperref package
\definecolor{urlcolor}{rgb}{0,.145,.698}
\definecolor{linkcolor}{rgb}{.71,0.21,0.01}
\definecolor{citecolor}{rgb}{.12,.54,.11}

% ANSI colors
\definecolor{ansi-black}{HTML}{3E424D}
\definecolor{ansi-black-intense}{HTML}{282C36}
\definecolor{ansi-red}{HTML}{E75C58}
\definecolor{ansi-red-intense}{HTML}{B22B31}
\definecolor{ansi-green}{HTML}{00A250}
\definecolor{ansi-green-intense}{HTML}{007427}
\definecolor{ansi-yellow}{HTML}{DDB62B}
\definecolor{ansi-yellow-intense}{HTML}{B27D12}
\definecolor{ansi-blue}{HTML}{208FFB}
\definecolor{ansi-blue-intense}{HTML}{0065CA}
\definecolor{ansi-magenta}{HTML}{D160C4}
\definecolor{ansi-magenta-intense}{HTML}{A03196}
\definecolor{ansi-cyan}{HTML}{60C6C8}
\definecolor{ansi-cyan-intense}{HTML}{258F8F}
\definecolor{ansi-white}{HTML}{C5C1B4}
\definecolor{ansi-white-intense}{HTML}{A1A6B2}
\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF}
\definecolor{ansi-default-inverse-bg}{HTML}{000000}


% commands and environments needed by pandoc snippets
% extracted from the output of `pandoc -s`
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}}
\newcommand{\RegionMarkerTok}[1]{{#1}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}}
\newcommand{\NormalTok}[1]{{#1}}

% Additional commands for more recent versions of Pandoc
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}}
\newcommand{\ImportTok}[1]{{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}}
\newcommand{\BuiltInTok}[1]{{#1}}
\newcommand{\ExtensionTok}[1]{{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}}


% Define a nice break command that doesn't care if a line doesn't already
% exist.
\def\br{\hspace*{\fill} \\* }
% Math Jax compatibility definitions
\def\gt{>}
\def\lt{<}
\let\Oldtex\TeX
\let\Oldlatex\LaTeX
\renewcommand{\TeX}{\textrm{\Oldtex}}
\renewcommand{\LaTeX}{\textrm{\Oldlatex}

%===============================================================================
% Title Page
%===============================================================================

((* block maketitle *))

\title{((( nb.metadata.get("latex_metadata", {}).get("title", "") | escape_latex )))}

((*- if nb.metadata.get("latex_metadata", {}).get("author", ""): -*))
\author{((( nb.metadata["latex_metadata"]["author"] )))}
((*- endif *))

((*- if nb.metadata.get("latex_metadata", {}).get("affiliation", ""): -*))
\affiliation{((( nb.metadata["latex_metadata"]["affiliation"] )))}
((*- endif *))

\date{\today}
\maketitle

((*- if nb.metadata.get("latex_metadata", {}).get("logo", ""): -*))
\begin{center}
\adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{((( nb.metadata["latex_metadata"]["logo"] )))}
\end{center}
((*- endif -*))

((* endblock maketitle *))


%===============================================================================
% Input
%===============================================================================

% Input cells can be hidden using the "Hide input" and "Hide input all"
% nbextensions (which set the hide_input metadata flags)

((* block input scoped *))
((( cell.metadata.get("hide_input", "") )))
((*- if cell.metadata.hide_input or nb.metadata.hide_input or cell.metadata.get("hide_input", ""): -*))
((*- else -*))
((( custom_add_prompt(cell.source | wrap_text(88) | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor') )))
((*- endif *))
((* endblock input *))


%===============================================================================
% Output
%===============================================================================

((* block output_group -*))
((*- if cell.metadata.hide_output: -*))
((*- else -*))
((( super() )))
((*- endif -*))
((* endblock output_group *))

% Display stream ouput with coloring
((* block stream *))
\begin{Verbatim}[commandchars=\\\{\}, fontsize=\scriptsize]
((( output.text | wrap_text(86) | escape_latex | ansi2latex )))
\end{Verbatim}
((* endblock stream *))

%==============================================================================
% Define macro custom_add_prompt() (derived from add_prompt() macro in style_ipython.tplx)
%==============================================================================

((* macro custom_add_prompt(text, cell, prompt, prompt_color) -*))
((*- if cell.execution_count is defined -*))
((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
((*- else -*))
((*- set execution_count = " " -*))
((*- endif -*))
((*- set indention = " " * (execution_count | length + 7) -*))
\begin{Verbatim}[commandchars=\\\{\}, fontsize=\scriptsize]
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
\end{Verbatim}
((*- endmacro *))

%==============================================================================
% Bibliography
%==============================================================================

% Insert citations in markdown as e.g.
% <cite data-cite="DevoretS2013">[DevoretS2013]</cite>
% requires file references.bib in current directory (or the file set as "bib" in the latex_metadata)


((* block bibliography *))
((*- if nb.metadata.get("latex_metadata", {}).get("bib_include", ""): -*))
% Add a bibliography block to the postdoc
\bibliographystyle{plain}
\bibliography{((( nb.metadata.get("latex_metadata", {}).get("bib", "quant-econ") )))}
((*- endif -*))
((* endblock bibliography *))

0 comments on commit 3b8f871

Please sign in to comment.