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