##// END OF EJS Templates
Tex stack exchange suggestions
Jonathan Frederic -
Show More
@@ -1,48 +1,40 b''
1 1
2 2 %===============================================================================
3 3 % Cell style
4 4 %===============================================================================
5 5
6 6 % Inherit from the specified cell style.
7 7 ((* extends 'latex_article.tplx' *))
8 8
9 9 %===============================================================================
10 10 % Latex Sphinx Article
11 11 %===============================================================================
12 12
13 13 ((* block docclass *))
14 14 % Make sure that the sphinx doc style knows who it inherits from.
15 15 \def\sphinxdocclass{article}
16 16
17 17 % Declare the document class
18 18 \documentclass[letterpaper,10pt,english]{((( resources.sphinx.texinputs | posix_path )))/sphinxhowto}
19 19 ((* endblock docclass *))
20 20
21 21 ((* block packages *))
22 22 ((* block chstyle *))
23 23 \usepackage[Bjarne]{((( resources.sphinx.texinputs | posix_path )))/fncychap}
24 24 ((* endblock chstyle *))
25 25
26 26 \usepackage{((( resources.sphinx.texinputs | posix_path )))/sphinx}
27 27
28 28 ((( super() )))
29 29 ((* endblock packages *))
30 30
31 31 ((* block commands *))
32 32 ((( super() )))
33 33
34 34 % Override to specify your own logo
35 35 ((* block logo *))\newcommand{\sphinxlogo}{}((* endblock logo *))
36 36
37 37 % Make the index page of the document.
38 38 \makeindex
39 39
40 40 ((* endblock commands *))
41
42 ((* block notebook_input_extra_space -*))
43 \vspace{-0.9\baselineskip}%
44 ((*- endblock notebook_input_extra_space *))
45
46 ((* block notebook_output_extra_space -*))
47 \vspace{-0.6\baselineskip}%
48 ((*- endblock notebook_output_extra_space *))
@@ -1,185 +1,191 b''
1 1 ((= Notebook input/output style =))
2 2
3 3 ((* extends 'latex_base.tplx' *))
4 4
5 5 % Custom packages
6 6 ((* block packages *))
7 7 ((( super() )))
8 8
9 9 \usepackage{tikz} % Needed to box output/input
10 10 \usepackage{scrextend} % Used to indent output
11 11 \usepackage{needspace} % Make prompts follow contents
12 12 \usepackage{framed} % Used to draw output that spans multiple pages
13 13 ((* endblock packages *))
14 14
15 15 % Custom definitions
16 16 ((* block definitions *))
17 17 ((( super() )))
18 18
19 19 % Pygments definitions
20 20 ((( resources.latex.pygment_definitions )))
21 21
22 % NB prompt font size
23 \def\smaller{\fontsize{9.5pt}{9.5pt}\selectfont}
24
25 22 % NB prompt colors
26 23 \definecolor{nbframe-border}{rgb}{0.867,0.867,0.867}
27 24 \definecolor{nbframe-bg}{rgb}{0.969,0.969,0.969}
28 25 \definecolor{nbframe-in-prompt}{rgb}{0.0,0.0,0.502}
29 26 \definecolor{nbframe-out-prompt}{rgb}{0.545,0.0,0.0}
30 27
31 28 % NB prompt lengths
32 29 \newlength{\inputpadding}
33 30 \setlength{\inputpadding}{0.5em}
34 31 \newlength{\cellleftmargin}
35 32 \setlength{\cellleftmargin}{0.15\linewidth}
36 33 \newlength{\borderthickness}
37 34 \setlength{\borderthickness}{0.4pt}
35 \newlength{\smallerfontscale}
36 \setlength{\smallerfontscale}{9.5pt}
37
38 % NB prompt font size
39 \def\smaller{\fontsize{\smallerfontscale}{\smallerfontscale}\selectfont}
38 40
39 41 % Define a background layer, in which the nb prompt shape is drawn
40 42 \pgfdeclarelayer{background}
41 43 \pgfsetlayers{background,main}
42 44 \usetikzlibrary{calc}
43 45
44 46 % define styles for the normal border and the torn border
45 47 \tikzset{
46 48 normal border/.style={draw=nbframe-border, fill=nbframe-bg,
47 49 rectangle, rounded corners=2.5pt, line width=\borderthickness},
48 50 torn border/.style={draw=white, fill=white, line width=\borderthickness}}
49 51
50 52 % Macro to draw the shape behind the text, when it fits completly in the
51 53 % page
52 54 \def\notebookcellframe#1{%
53 55 \tikz{%
54 56 \node[inner sep=\inputpadding] (A) {#1};% Draw the text of the node
55 57 \begin{pgfonlayer}{background}% Draw the shape behind
56 58 \fill[normal border]%
57 59 (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) --
58 60 ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle;
59 61 \end{pgfonlayer}}}%
60 62
61 63 % Macro to draw the shape, when the text will continue in next page
62 64 \def\notebookcellframetop#1{%
63 65 \tikz{%
64 66 \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node
65 67 \begin{pgfonlayer}{background}
66 68 \fill[normal border] % Draw the ``complete shape'' behind
67 69 (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) --
68 70 ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle;
69 71 \fill[torn border] % Add the torn lower border
70 72 ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) --
71 73 ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle;
72 74 \end{pgfonlayer}}}
73 75
74 76 % Macro to draw the shape, when the text continues from previous page
75 77 \def\notebookcellframebottom#1{%
76 78 \tikz{%
77 79 \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node
78 80 \begin{pgfonlayer}{background}
79 81 \fill[normal border] % Draw the ``complete shape'' behind
80 82 (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) --
81 83 ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle;
82 84 \fill[torn border] % Add the torn upper border
83 85 ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) --
84 86 ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle;
85 87 \end{pgfonlayer}}}
86 88
87 89 % Macro to draw the shape, when both the text continues from previous page
88 90 % and it will continue in next page
89 91 \def\notebookcellframemiddle#1{%
90 92 \tikz{%
91 93 \node[inner sep=\inputpadding] (A) {#1}; % Draw the text of the node
92 94 \begin{pgfonlayer}{background}
93 95 \fill[normal border] % Draw the ``complete shape'' behind
94 96 (A.south east) -- ($(A.south west)+(\cellleftmargin,0)$) --
95 97 ($(A.north west)+(\cellleftmargin,0)$) -- (A.north east) -- cycle;
96 98 \fill[torn border] % Add the torn lower border
97 99 ($(A.south east)-(0,.1)$) -- ($(A.south west)+(\cellleftmargin,-.1)$) --
98 100 ($(A.south west)+(\cellleftmargin,.1)$) -- ($(A.south east)+(0,.1)$) -- cycle;
99 101 \fill[torn border] % Add the torn upper border
100 102 ($(A.north east)-(0,.1)$) -- ($(A.north west)+(\cellleftmargin,-.1)$) --
101 103 ($(A.north west)+(\cellleftmargin,.1)$) -- ($(A.north east)+(0,.1)$) -- cycle;
102 104 \end{pgfonlayer}}}
103 105
104 106 % Define the environment which puts the frame
105 107 % In this case, the environment also accepts an argument with an optional
106 108 % title (which defaults to ``Example'', which is typeset in a box overlaid
107 109 % on the top border
108 110 \newenvironment{notebookcell}[1][0]{%
109 111 \def\FrameCommand{\notebookcellframe}%
110 112 \def\FirstFrameCommand{\notebookcellframetop}%
111 113 \def\LastFrameCommand{\notebookcellframebottom}%
112 114 \def\MidFrameCommand{\notebookcellframemiddle}%
113 \vskip\baselineskip%
115 \par\vspace{1\baselineskip}%
114 116 \MakeFramed {\FrameRestore}%
115 117 \noindent\tikz\node[inner sep=0em] at ($(A.north west)-(0,0)$) {%
116 118 ((( draw_prompt("In ", "#1", "nbframe-in-prompt", "2pt") )))%
117 }; }%
119 }; \par}%
118 120 {\endMakeFramed}
119 121
120 122 ((* endblock definitions *))
121 123
122 124
123 125 %===============================================================================
124 126 % Input
125 127 %===============================================================================
126 128
127 129 ((* block input scoped *))
128 130 % Add contents below.
129 131
132 {\par%
130 133 \vspace{-1\baselineskip}%
131 \needspace{4\baselineskip}%
134 \needspace{4\baselineskip}}%
132 135 \begin{notebookcell}[((( cell.prompt_number )))]%
133 136 \begin{addmargin}[\cellleftmargin]{0em}% left, right
134 ((* block notebook_input_extra_space *))%((* endblock notebook_input_extra_space *))
135 \smaller%
136 \vspace{-1\baselineskip}%
137 \vspace{-1\borderthickness}%
137 {\smaller%
138 \par%
139 ((* block extra_input_spacing *))((* endblock extra_input_spacing *))%
140 \vspace{-1\smallerfontscale}%
138 141 ((( cell.input | highlight2latex )))%
139 \vspace{-1\baselineskip}%
142 \par%
143 \vspace{-1\smallerfontscale}}%
140 144 \end{addmargin}
141 145 \end{notebookcell}
142 146
143 147 ((* endblock input *))
144 148
145 149 %===============================================================================
146 150 % Output
147 151 %===============================================================================
148 152
149 ((* block output *))
150 \vspace{1\baselineskip}%
153 ((* block output -*))
154 \par\vspace{1\smallerfontscale}%
151 155 % Only render the prompt if the cell is pyout. Note, the outputs prompt
152 156 % block isn't used since we need to check each indiviual output and only
153 157 % add prompts to the pyout ones.
154 158 ((* if output.output_type in ['pyout'] *))
155 \vspace{-1\baselineskip}%
159 {\par%
160 \vspace{-1\smallerfontscale}%
156 161 \noindent%
157 162 ((( draw_prompt("Out", cell.prompt_number, "nbframe-out-prompt", "0em") )))%
163 ((* block extra_output_spacing *))((* endblock extra_output_spacing *))}%
158 164 ((* endif *))%
159 165 %
160 166 \begin{addmargin}[\cellleftmargin]{0em}% left, right
161 \smaller%
162 ((* block notebook_output_extra_space *))%((* endblock notebook_output_extra_space *))
163 \vspace{-1\baselineskip}%
164 ((( super() )))
165 \end{addmargin}
166 ((* endblock output *))
167 {\smaller%
168 \vspace{-1\smallerfontscale}%
169 ((( super() )))}%
170 \end{addmargin}%
171 ((*- endblock output *))
167 172
168 173 %==============================================================================
169 174 % Support Macros
170 175 %==============================================================================
171 176
172 177 % Name: draw_prompt
173 178 % Purpose: Renders an output/input prompt for notebook style pdfs
174 179 ((* macro draw_prompt(prompt, number, color, space) -*))
175 \begin{minipage}{\cellleftmargin}
176 \smaller%
180 \begin{minipage}{\cellleftmargin}%
181 \hfill%
182 {\smaller%
177 183 \tt%
178 184 \color{(((color)))}%
179 \hfill%
180 (((prompt)))[(((number)))]:%
185 (((prompt)))[(((number)))]:}%
181 186 \hspace{\inputpadding}%
182 187 \hspace{(((space)))}%
183 188 \hspace{3pt}%
184 \end{minipage}
189 \end{minipage}%
185 190 ((*- endmacro *))
191
General Comments 0
You need to be logged in to leave comments. Login now