|
| 1 | +((*- extends 'article.tplx' -*)) |
| 2 | + |
| 3 | +% See http://blog.juliusschulz.de/blog/ultimate-ipython-notebook#templates |
| 4 | +% for some useful tips |
| 5 | + |
| 6 | +%=============================================================================== |
| 7 | +% Document class |
| 8 | +%=============================================================================== |
| 9 | + |
| 10 | +((* block docclass *)) |
| 11 | +\documentclass[11pt, twoside, a4paper]{article} |
| 12 | +((* endblock docclass *)) |
| 13 | + |
| 14 | +%=============================================================================== |
| 15 | +% Packages |
| 16 | +%=============================================================================== |
| 17 | + |
| 18 | +((* block packages *)) |
| 19 | +\usepackage[T1]{fontenc} |
| 20 | +\usepackage{graphicx} |
| 21 | +\usepackage[breakable]{tcolorbox} |
| 22 | +% We will generate all images so they have a width \maxwidth. This means |
| 23 | +% that they will get their normal width if they fit onto the page, but |
| 24 | +% are scaled down if they would overflow the margins. |
| 25 | +\makeatletter |
| 26 | +\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth |
| 27 | +\else\Gin@nat@width\fi} |
| 28 | +\makeatother |
| 29 | +\let\Oldincludegraphics\includegraphics |
| 30 | + |
| 31 | +% propose delete% |
| 32 | +% Ensure that by default, figures have no caption (until we provide a |
| 33 | +% proper Figure object with a Caption API and a way to capture that |
| 34 | +% in the conversion process - todo). |
| 35 | +% \usepackage{caption} |
| 36 | +% \DeclareCaptionLabelFormat{empty}{} |
| 37 | +%\captionsetup{format=empty,aboveskip=0pt,belowskip=0pt} |
| 38 | +% end - propose delete% |
| 39 | + |
| 40 | +% float figure settings% |
| 41 | +\usepackage{float} |
| 42 | +\floatplacement{figure}{H} % used to force figures for placement in text |
| 43 | + |
| 44 | +\usepackage{adjustbox} % Used to constrain images to a maximum size |
| 45 | +\usepackage{xcolor} % Allow colors to be defined |
| 46 | +\usepackage{enumerate} % Needed for markdown enumerations to work |
| 47 | +\usepackage{geometry} % Used to adjust the document margins |
| 48 | +\usepackage{amsmath} % Equations |
| 49 | +\usepackage{amssymb} % Equations |
| 50 | +\usepackage{textcomp} % defines textquotesingle |
| 51 | +% Hack from http://tex.stackexchange.com/a/47451/13684: |
| 52 | +\AtBeginDocument{% |
| 53 | + \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code |
| 54 | +} |
| 55 | +\usepackage{upquote} % Upright quotes for verbatim code |
| 56 | +\usepackage{eurosym} % defines \euro |
| 57 | +\usepackage[mathletters]{ucs} % Extended unicode (utf-8) support |
| 58 | +\usepackage[utf8x]{inputenc} % Allow utf-8 characters in the tex document |
| 59 | +\usepackage{fancyvrb} % verbatim replacement that allows latex |
| 60 | +\usepackage{xcolor} |
| 61 | +\usepackage{listings} |
| 62 | +\lstset{escapeinside={<@}{@>}} |
| 63 | +\usepackage{grffile} % extends the file name processing of package graphics |
| 64 | + % to support a larger range |
| 65 | +% The hyperref package gives us a pdf with properly built |
| 66 | +% internal navigation ('pdf bookmarks' for the table of contents, |
| 67 | +% internal cross-reference links, web links for URLs, etc.) |
| 68 | +\usepackage{hyperref} |
| 69 | +\usepackage{longtable} % longtable support required by pandoc >1.10 |
| 70 | +\usepackage{booktabs} % table support for pandoc > 1.12.2 |
| 71 | +\usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) |
| 72 | +\usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) |
| 73 | + % normalem makes italics be italics, not underlines |
| 74 | +\usepackage{braket} |
| 75 | +\usepackage{mathrsfs} |
| 76 | +\usepackage{natbib} |
| 77 | +\usepackage[document]{ragged2e} |
| 78 | +\usepackage{fontspec, unicode-math} |
| 79 | +\usepackage[greek,english]{babel} |
| 80 | +\usepackage{xunicode} |
| 81 | +\usepackage{letltxmacro} |
| 82 | +\newcommand{\argmax}{\operatornamewithlimits{argmax}} |
| 83 | +\newcommand{\argmin}{\operatornamewithlimits{argmin}} |
| 84 | +\DeclareMathOperator{\col}{col} |
| 85 | +\setlength{\parskip}{1.5ex plus0.5ex minus0.5ex} |
| 86 | +\setlength{\parindent}{0pt} |
| 87 | + |
| 88 | +\usepackage{letltxmacro} |
| 89 | +% https://tex.stackexchange.com/q/88001/5764 |
| 90 | +\LetLtxMacro\oldttfamily\ttfamily |
| 91 | +\DeclareRobustCommand{\ttfamily}{\oldttfamily\csname ttsize\endcsname} |
| 92 | +\newcommand{\setttsize}[1]{\def\ttsize{#1}}% |
| 93 | + |
| 94 | +\DeclareTextFontCommand{\texttt}{\ttfamily} |
| 95 | + |
| 96 | +% Enable Unicode characters in `Out` code-blocks within verbatim |
| 97 | +\usepackage{pmboxdraw} |
| 98 | + |
| 99 | +% renew commands % |
| 100 | +% Set max figure width to be 80% of text width, for now hardcoded. |
| 101 | +\renewcommand{\includegraphics}[1]{\begin{center}\Oldincludegraphics[width=.8\maxwidth]{#1}\end{center}} |
| 102 | +\renewcommand \caption [2][]{} % removes captions from all figures |
| 103 | +\setlist[itemize]{nosep} |
| 104 | + |
| 105 | +% using CMU Serif for greek and latin letters in code blocks and Liberation Mono for rest% |
| 106 | +\setmonofont{Liberation Mono} |
| 107 | +\usepackage[Latin,Greek]{ucharclasses} |
| 108 | +\newfontfamily\substitutefont{CMU Serif} |
| 109 | +\setTransitionsForGreek{\begingroup\substitutefont}{\endgroup} |
| 110 | +((* endblock packages *)) |
| 111 | + |
| 112 | +% Colors for the hyperref package |
| 113 | +\definecolor{urlcolor}{rgb}{0,.145,.698} |
| 114 | +\definecolor{linkcolor}{rgb}{.71,0.21,0.01} |
| 115 | +\definecolor{citecolor}{rgb}{.12,.54,.11} |
| 116 | + |
| 117 | +% ANSI colors |
| 118 | +\definecolor{ansi-black}{HTML}{3E424D} |
| 119 | +\definecolor{ansi-black-intense}{HTML}{282C36} |
| 120 | +\definecolor{ansi-red}{HTML}{E75C58} |
| 121 | +\definecolor{ansi-red-intense}{HTML}{B22B31} |
| 122 | +\definecolor{ansi-green}{HTML}{00A250} |
| 123 | +\definecolor{ansi-green-intense}{HTML}{007427} |
| 124 | +\definecolor{ansi-yellow}{HTML}{DDB62B} |
| 125 | +\definecolor{ansi-yellow-intense}{HTML}{B27D12} |
| 126 | +\definecolor{ansi-blue}{HTML}{208FFB} |
| 127 | +\definecolor{ansi-blue-intense}{HTML}{0065CA} |
| 128 | +\definecolor{ansi-magenta}{HTML}{D160C4} |
| 129 | +\definecolor{ansi-magenta-intense}{HTML}{A03196} |
| 130 | +\definecolor{ansi-cyan}{HTML}{60C6C8} |
| 131 | +\definecolor{ansi-cyan-intense}{HTML}{258F8F} |
| 132 | +\definecolor{ansi-white}{HTML}{C5C1B4} |
| 133 | +\definecolor{ansi-white-intense}{HTML}{A1A6B2} |
| 134 | +\definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} |
| 135 | +\definecolor{ansi-default-inverse-bg}{HTML}{000000} |
| 136 | + |
| 137 | + |
| 138 | +% commands and environments needed by pandoc snippets |
| 139 | +% extracted from the output of `pandoc -s` |
| 140 | +\providecommand{\tightlist}{% |
| 141 | + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} |
| 142 | +\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} |
| 143 | +% Add ',fontsize=\small' for more characters per line |
| 144 | +\newenvironment{Shaded}{}{} |
| 145 | +\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} |
| 146 | +\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} |
| 147 | +\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} |
| 148 | +\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} |
| 149 | +\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} |
| 150 | +\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} |
| 151 | +\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} |
| 152 | +\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} |
| 153 | +\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} |
| 154 | +\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} |
| 155 | +\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} |
| 156 | +\newcommand{\RegionMarkerTok}[1]{{#1}} |
| 157 | +\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} |
| 158 | +\newcommand{\NormalTok}[1]{{#1}} |
| 159 | + |
| 160 | +% Additional commands for more recent versions of Pandoc |
| 161 | +\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} |
| 162 | +\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} |
| 163 | +\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} |
| 164 | +\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} |
| 165 | +\newcommand{\ImportTok}[1]{{#1}} |
| 166 | +\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} |
| 167 | +\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} |
| 168 | +\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} |
| 169 | +\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} |
| 170 | +\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} |
| 171 | +\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} |
| 172 | +\newcommand{\BuiltInTok}[1]{{#1}} |
| 173 | +\newcommand{\ExtensionTok}[1]{{#1}} |
| 174 | +\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} |
| 175 | +\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} |
| 176 | +\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} |
| 177 | +\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} |
| 178 | + |
| 179 | + |
| 180 | +% Define a nice break command that doesn't care if a line doesn't already |
| 181 | +% exist. |
| 182 | +\def\br{\hspace*{\fill} \\* } |
| 183 | +% Math Jax compatibility definitions |
| 184 | +\def\gt{>} |
| 185 | +\def\lt{<} |
| 186 | +\let\Oldtex\TeX |
| 187 | +\let\Oldlatex\LaTeX |
| 188 | +\renewcommand{\TeX}{\textrm{\Oldtex}} |
| 189 | +\renewcommand{\LaTeX}{\textrm{\Oldlatex} |
| 190 | + |
| 191 | +%=============================================================================== |
| 192 | +% Title Page |
| 193 | +%=============================================================================== |
| 194 | + |
| 195 | +((* block maketitle *)) |
| 196 | +\setttsize{\footnotesize} |
| 197 | + |
| 198 | +\title{((( nb.metadata.get("latex_metadata", {}).get("title", "") | escape_latex )))} |
| 199 | + |
| 200 | +((*- if nb.metadata.get("latex_metadata", {}).get("author", ""): -*)) |
| 201 | +\author{((( nb.metadata["latex_metadata"]["author"] )))} |
| 202 | +((*- endif *)) |
| 203 | + |
| 204 | +((*- if nb.metadata.get("latex_metadata", {}).get("affiliation", ""): -*)) |
| 205 | +\affiliation{((( nb.metadata["latex_metadata"]["affiliation"] )))} |
| 206 | +((*- endif *)) |
| 207 | + |
| 208 | +\date{\today} |
| 209 | +\maketitle |
| 210 | + |
| 211 | +((*- if nb.metadata.get("latex_metadata", {}).get("logo", ""): -*)) |
| 212 | +\begin{center} |
| 213 | + \adjustimage{max size={0.6\linewidth}{0.6\paperheight}}{((( nb.metadata["latex_metadata"]["logo"] )))} |
| 214 | +\end{center} |
| 215 | +((*- endif -*)) |
| 216 | + |
| 217 | +% delete-till-here-book % |
| 218 | +((* endblock maketitle *)) |
| 219 | + |
| 220 | + |
| 221 | +%=============================================================================== |
| 222 | +% Input |
| 223 | +%=============================================================================== |
| 224 | + |
| 225 | +% Input cells can be hidden using the "Hide input" and "Hide input all" |
| 226 | +% nbextensions (which set the hide_input metadata flags) |
| 227 | + |
| 228 | +((* block input scoped *)) |
| 229 | +((( cell.metadata.get("hide_input", "") ))) |
| 230 | +((*- if cell.metadata.hide_input or nb.metadata.hide_input or cell.metadata.get("hide_input", ""): -*)) |
| 231 | +((*- else -*)) |
| 232 | + ((( custom_add_prompt(cell.source | wrap_text(88) | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor', 'plain') ))) |
| 233 | +((*- endif *)) |
| 234 | +((* endblock input *)) |
| 235 | + |
| 236 | + |
| 237 | +%=============================================================================== |
| 238 | +% Output |
| 239 | +%=============================================================================== |
| 240 | + |
| 241 | +((* block output_group -*)) |
| 242 | +((*- if cell.metadata.hide_output: -*)) |
| 243 | +((*- else -*)) |
| 244 | + ((( super() ))) |
| 245 | +((*- endif -*)) |
| 246 | +((* endblock output_group *)) |
| 247 | + |
| 248 | +((* block execute_result scoped *)) |
| 249 | + ((*- for type in output.data | filter_data_type -*)) |
| 250 | + ((*- if type in ['text/plain']*)) |
| 251 | + ((( custom_add_prompt(output.data['text/plain'] | wrap_text(88) | escape_latex | ansi2latex, cell, 'Out', 'outcolor', 'plain') ))) |
| 252 | + ((*- elif type in ['text/latex']*)) |
| 253 | + ((( custom_add_prompt(output.data['text/latex'] | wrap_text(88) | ansi2latex, cell, 'Out', 'outcolor', 'latex') ))) |
| 254 | + ((* else -*)) |
| 255 | + ((( custom_add_prompt( '' | wrap_text(88)| escape_latex | ansi2latex, cell, 'Out', 'outcolor', 'plain') ))) |
| 256 | + ((*- endif -*)) |
| 257 | + ((*- endfor -*)) |
| 258 | +((* endblock execute_result *)) |
| 259 | + |
| 260 | +% Display stream ouput with coloring |
| 261 | +((* block stream *)) |
| 262 | +\begin{Verbatim}[commandchars=\\\{\}, fontsize=\footnotesize] |
| 263 | + ((( output.text | wrap_text(86) | escape_latex | ansi2latex ))) |
| 264 | +\end{Verbatim} |
| 265 | +%((* endblock stream *)) |
| 266 | + |
| 267 | +%============================================================================== |
| 268 | +% Define macro custom_add_prompt() (derived from add_prompt() macro in style_ipython.tplx) |
| 269 | +%============================================================================== |
| 270 | + |
| 271 | +((* macro custom_add_prompt(text, cell, prompt, prompt_color, type) -*)) |
| 272 | + ((*- if cell.execution_count is defined -*)) |
| 273 | + ((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*)) |
| 274 | + ((*- else -*)) |
| 275 | + ((*- set execution_count = "" -*)) |
| 276 | + ((*- endif -*)) |
| 277 | + ((*- set indention = " " * (execution_count | length + 7) -*)) |
| 278 | +((*- if type == 'plain' -*)) |
| 279 | +\begin{Verbatim}[commandchars=\\\{\}, fontsize=\small, xleftmargin=-3.9em] |
| 280 | +((( text.replace('$$','').replace('$\\',"\\(\\").replace('$','\)') | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) ))) |
| 281 | +\end{Verbatim} |
| 282 | +((*- else -*)) |
| 283 | +\begin{lstlisting}[mathescape, basicstyle=\small\ttfamily\color{black}, keywordstyle={\color{red}}, xleftmargin=-4.8em] |
| 284 | +((( text | add_prompts(first='<@\\textcolor{red}{' ~ prompt ~ '[' ~ execution_count ~ ']: }@>', cont=indention) ))) |
| 285 | +\end{lstlisting} |
| 286 | +((*- endif -*)) |
| 287 | +((*- endmacro *)) |
| 288 | + |
| 289 | +%============================================================================== |
| 290 | +% Support Macros |
| 291 | +%============================================================================== |
| 292 | + |
| 293 | +% Name: draw_prompt |
| 294 | +% Purpose: Renders an output/input prompt |
| 295 | +((* macro draw_prompt(cell, prompt, prompt_color, extra_space) -*)) |
| 296 | + ((*- if cell.execution_count is defined -*)) |
| 297 | + ((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*)) |
| 298 | + ((*- else -*))((*- set execution_count = " " -*))((*- endif *)) |
| 299 | + |
| 300 | + ((*- if (resources.global_content_filter.include_output_prompt and prompt == 'Out') |
| 301 | + or (resources.global_content_filter.include_input_prompt and prompt == 'In' ) *)) |
| 302 | +\prompt{(((prompt)))}{(((prompt_color)))}{(((execution_count)))}{(((extra_space)))} |
| 303 | + ((*- endif -*)) |
| 304 | +((*- endmacro *)) |
| 305 | + |
| 306 | + |
| 307 | +%============================================================================== |
| 308 | +% Bibliography |
| 309 | +%============================================================================== |
| 310 | + |
| 311 | +% Insert citations in markdown as e.g. |
| 312 | +% <cite data-cite="DevoretS2013">[DevoretS2013]</cite> |
| 313 | +% requires file references.bib in current directory (or the file set as "bib" in the latex_metadata) |
| 314 | + |
| 315 | + |
| 316 | +((* block bibliography *)) |
| 317 | +% delete-from-here-book % |
| 318 | +((*- if nb.metadata.get("latex_metadata", {}).get("bib_include", ""): -*)) |
| 319 | +% Add a bibliography block to the postdoc |
| 320 | +\bibliographystyle{plain} |
| 321 | +\bibliography{((( nb.metadata.get("latex_metadata", {}).get("bib", "quant-econ") )))} |
| 322 | +((*- endif -*)) |
| 323 | +((* endblock bibliography *)) |
0 commit comments