initial upload
This commit is contained in:
120
scientific-computing-1/chapter.tplx
Normal file
120
scientific-computing-1/chapter.tplx
Normal file
@@ -0,0 +1,120 @@
|
||||
((*- extends 'display_priority.tplx' -*))
|
||||
|
||||
%===============================================================================
|
||||
% Abstract overrides
|
||||
%===============================================================================
|
||||
|
||||
((* block header *))
|
||||
((* endblock header *))
|
||||
|
||||
((* block body *))
|
||||
((( super() )))
|
||||
((* endblock body *))
|
||||
|
||||
%===============================================================================
|
||||
% Support blocks
|
||||
%===============================================================================
|
||||
|
||||
% Displaying simple data text
|
||||
((* block data_text *))
|
||||
\begin{verbatim}
|
||||
((( output.data['text/plain'] )))
|
||||
\end{verbatim}
|
||||
((* endblock data_text *))
|
||||
|
||||
% Display python error text as-is
|
||||
((* block error *))
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
((( super() )))
|
||||
\end{Verbatim}
|
||||
((* endblock error *))
|
||||
((* block traceback_line *))
|
||||
((( line | indent | strip_ansi | escape_latex )))
|
||||
((* endblock traceback_line *))
|
||||
|
||||
% Display stream ouput with coloring
|
||||
((* block stream *))
|
||||
\begin{Verbatim}[commandchars=\\\{\}]
|
||||
((( output.text | escape_latex | ansi2latex )))
|
||||
\end{Verbatim}
|
||||
((* endblock stream *))
|
||||
|
||||
% Display latex
|
||||
((* block data_latex -*))
|
||||
((( output.data['text/latex'] | citation2latex | strip_files_prefix | markdown2latex )))
|
||||
((* endblock data_latex *))
|
||||
|
||||
% Display markdown
|
||||
((* block data_markdown -*))
|
||||
((( output.data['text/markdown'] | citation2latex | strip_files_prefix | markdown2latex )))
|
||||
((* endblock data_markdown *))
|
||||
|
||||
% Default mechanism for rendering figures
|
||||
((*- block data_png -*))((( draw_figure(output.metadata.filenames['image/png']) )))((*- endblock -*))
|
||||
((*- block data_jpg -*))((( draw_figure(output.metadata.filenames['image/jpeg']) )))((*- endblock -*))
|
||||
((*- block data_svg -*))((( draw_figure(output.metadata.filenames['image/svg+xml']) )))((*- endblock -*))
|
||||
((*- block data_pdf -*))((( draw_figure(output.metadata.filenames['application/pdf']) )))((*- endblock -*))
|
||||
|
||||
% Draw a figure using the graphicx package.
|
||||
((* macro draw_figure(filename) -*))
|
||||
((* set filename = filename | posix_path *))
|
||||
((*- block figure scoped -*))
|
||||
\begin{center}
|
||||
\adjustimage{max size={0.9\linewidth}{0.9\paperheight}}{((( filename )))}
|
||||
\end{center}
|
||||
{ \hspace*{\fill} \\}
|
||||
((*- endblock figure -*))
|
||||
((*- endmacro *))
|
||||
|
||||
% Render markdown
|
||||
((* block markdowncell scoped *))
|
||||
((( cell.source | citation2latex | strip_files_prefix | markdown2latex(extra_args=["--chapters"]) )))
|
||||
((* endblock markdowncell *))
|
||||
|
||||
% Don't display unknown types
|
||||
((* block unknowncell scoped *))
|
||||
((* endblock unknowncell *))
|
||||
|
||||
%===============================================================================
|
||||
% Input
|
||||
%===============================================================================
|
||||
|
||||
((* block input scoped *))
|
||||
((( add_prompt(cell.source | highlight_code(strip_verbatim=True), cell, 'In ', 'incolor') )))
|
||||
((* endblock input *))
|
||||
|
||||
|
||||
%===============================================================================
|
||||
% Output
|
||||
%===============================================================================
|
||||
|
||||
((* block execute_result scoped *))
|
||||
((*- for type in output.data | filter_data_type -*))
|
||||
((*- if type in ['text/plain']*))
|
||||
((( add_prompt(output.data['text/plain'] | escape_latex, cell, 'Out', 'outcolor') )))
|
||||
((* else -*))
|
||||
\texttt{\color{outcolor}Out[{\color{outcolor}((( cell.execution_count )))}]:}((( super() )))
|
||||
((*- endif -*))
|
||||
((*- endfor -*))
|
||||
((* endblock execute_result *))
|
||||
|
||||
|
||||
%==============================================================================
|
||||
% Support Macros
|
||||
%==============================================================================
|
||||
|
||||
% Name: draw_prompt
|
||||
% Purpose: Renders an output/input prompt
|
||||
((* macro 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=\\\{\}]
|
||||
((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
|
||||
\end{Verbatim}
|
||||
((*- endmacro *))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user