style_ipython.tplx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ((= IPython input/output style =))
  2. ((*- extends 'base.tplx' -*))
  3. % Custom definitions
  4. ((* block definitions *))
  5. ((( super() )))
  6. % Pygments definitions
  7. ((( resources.latex.pygments_definitions )))
  8. % Exact colors from NB
  9. \definecolor{incolor}{rgb}{0.0, 0.0, 0.5}
  10. \definecolor{outcolor}{rgb}{0.545, 0.0, 0.0}
  11. ((* endblock definitions *))
  12. %===============================================================================
  13. % Input
  14. %===============================================================================
  15. ((* block input scoped *))
  16. ((*- if resources.global_content_filter.include_input_prompt *))
  17. ((( add_prompt(cell.source | highlight_code(strip_verbatim=True, metadata=cell.metadata), cell, 'In ', 'incolor') )))
  18. ((*- else *))
  19. ((( cell.source | highlight_code(strip_verbatim=True, metadata=cell.metadata) )))
  20. ((* endif *))
  21. ((* endblock input *))
  22. %===============================================================================
  23. % Output
  24. %===============================================================================
  25. ((* block execute_result scoped *))
  26. ((*- for type in output.data | filter_data_type -*))
  27. ((*- if resources.global_content_filter.include_output_prompt -*))
  28. ((*- if type in ['text/plain'] *))
  29. ((( add_prompt(output.data['text/plain'] | escape_latex, cell, 'Out', 'outcolor') )))
  30. ((* else -*))
  31. \texttt{\color{outcolor}Out[{\color{outcolor}((( cell.execution_count )))}]:}((( super() )))
  32. ((*- endif -*))
  33. ((*- else -*))
  34. ((*- if type in ['text/plain'] *))
  35. ((( output.data['text/plain'] | escape_latex )))
  36. ((* else -*))
  37. ((( super() )))
  38. ((*- endif -*))
  39. ((*- endif -*))
  40. ((*- endfor -*))
  41. ((* endblock execute_result *))
  42. %==============================================================================
  43. % Support Macros
  44. %==============================================================================
  45. % Name: draw_prompt
  46. % Purpose: Renders an output/input prompt
  47. ((* macro add_prompt(text, cell, prompt, prompt_color) -*))
  48. ((*- if cell.execution_count is defined -*))
  49. ((*- set execution_count = "" ~ (cell.execution_count | replace(None, " ")) -*))
  50. ((*- else -*))
  51. ((*- set execution_count = " " -*))
  52. ((*- endif -*))
  53. ((*- set indention = " " * (execution_count | length + 7) -*))
  54. \begin{Verbatim}[commandchars=\\\{\}]
  55. ((( text | add_prompts(first='{\color{' ~ prompt_color ~ '}' ~ prompt ~ '[{\\color{' ~ prompt_color ~ '}' ~ execution_count ~ '}]:} ', cont=indention) )))
  56. \end{Verbatim}
  57. ((*- endmacro *))