diff options
author | Karl Berry <karl@freefriends.org> | 2024-02-16 21:06:30 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-02-16 21:06:30 +0000 |
commit | 6eba0f2ddc69d22154f045e2795972107832121f (patch) | |
tree | 9015caf0edd24092fe70b7f96179b5b9170c2d4d /Master/texmf-dist | |
parent | 7d41c56dca4a7b341a662744f327fb9f4e4ce0ab (diff) |
pynotebook (16feb24)
git-svn-id: svn://tug.org/texlive/trunk@69909 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/latex/pynotebook/README.md | 6 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.pdf | bin | 0 -> 392958 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.tex | 482 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.pdf | bin | 0 -> 74884 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.tex | 239 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/pynotebook/pynotebook.sty | 315 |
6 files changed, 1042 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/pynotebook/README.md b/Master/texmf-dist/doc/latex/pynotebook/README.md new file mode 100644 index 00000000000..e291f076eda --- /dev/null +++ b/Master/texmf-dist/doc/latex/pynotebook/README.md @@ -0,0 +1,6 @@ +pynotebook is a package to present (raw, markdown or python) codes (and execution with lualatex) as in a jupyter notebook. +-------------------------------------------------------------------------------------------------------------------------- + +Author....: Cédric Pierquet +email.....: cpierquet@outlook.fr +Licence...: Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txt diff --git a/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.pdf b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.pdf Binary files differnew file mode 100644 index 00000000000..d688335cf97 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.pdf diff --git a/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.tex b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.tex new file mode 100644 index 00000000000..ef408c246b1 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-doc.tex @@ -0,0 +1,482 @@ +% !TeX TXS-program:compile = txs:///arara +% arara: pdflatex: {shell: no, synctex: no, interaction: batchmode} +% arara: pdflatex: {shell: no, synctex: no, interaction: batchmode} if found('log', '(undefined references|Please rerun|Rerun to get)') + +\documentclass[english,11pt,a4paper]{article} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{pynotebook} +\usepackage{enumitem} +\usepackage{soul} +\usepackage{codehigh} +\usepackage{multicol} +\usepackage{fontawesome5} +\usepackage{fancyvrb} +\usepackage{fancyhdr} +\fancyhf{} +\renewcommand{\headrulewidth}{0pt} +%\rhead{\sffamily\small\affloetalab[Legende]} +\lfoot{\sffamily\small [pynotebook]} +\cfoot{\sffamily\small - \thepage{} -} +\rfoot{\hyperlink{matoc}{\small\faArrowAltCircleUp[regular]}} +\usepackage{hologo} +\usepackage{xspace} +\providecommand\tikzlogo{Ti\textit{k}Z} +\providecommand\TeXLive{\TeX{}Live\xspace} +\providecommand\PSTricks{\textsf{PSTricks}\xspace} +\let\pstricks\PSTricks +\let\TikZ\tikzlogo + +\usepackage{hyperref} +\urlstyle{same} +\hypersetup{pdfborder=0 0 0} +\usepackage[margin=2cm]{geometry} +\setlength{\parindent}{0pt} + +\def\TPversion{0.1.0} +\def\TPdate{15/02/2024} + +\sethlcolor{lightgray!25} +\NewDocumentCommand\ShowCode{ m }{% + \hl{\vphantom{\texttt{pf}}\texttt{#1}}% +} + +\usepackage{babel} + +\begin{document} + +\pagestyle{fancy} + +\thispagestyle{empty} + +\begin{center} + \begin{minipage}{0.88\linewidth} + \begin{tcolorbox}[colframe=yellow,colback=yellow!15] + \begin{center} + \begin{tabular}{c} + {\Huge \texttt{pynotebook}}\\ + \\ + {\LARGE Present a Jupyter notebook, with} \\ + {\LARGE tcolorbox, and listings or piton/pyluatex.} \\ + \\ + {\small \texttt{Version \TPversion{} -- \TPdate}} + \end{tabular} + \end{center} + \end{tcolorbox} +\end{minipage} +\end{center} + +\begin{center} + \begin{tabular}{c} + \texttt{Cédric Pierquet}\\ + {\ttfamily c pierquet -- at -- outlook . fr}\\ + \texttt{\url{https://github.com/cpierquet/pynotebook}} +\end{tabular} +\end{center} + +\hrule + +\phantomsection + +\hypertarget{matoc}{} + +\tableofcontents + +\vspace*{5mm} + +\hrule + +\vspace*{5mm} + +\vfill~ + +\pagebreak + +\section{Samples, with listings} + +\begin{NotebookMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.} + +It's possible to use \LaTeX{} formulas, like % +\[ +\left\lbrace\begin{array}{l} + F_0 = 0\\ + F_1 = 1 \\ + F_{n+2} = F_{n+1} + F_n +\end{array}\right. +\] +\end{NotebookMarkdown} + +\begin{NotebookRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookRaw} + +\begin{NotebookIn}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}{\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +%\vspace*{5mm} +% +%\begin{center} +% With \ShowCode{piton} and \ShowCode{pyluatex} (with code execution, but with \hologo{LuaLaTeX} and \textsf{--shell-escape}) : +%\end{center} +% +%\includegraphics[clip]{pynotebook-samples-pitonpyluatex.pdf} + +\vfill~ + +\section{History} + +\verb|v0.1.0|~:~~~~Initial version + +\vspace*{15mm} + +\pagebreak + +\section{The package pynotebook} + +\subsection{Ideas} + +The idea is to provides environments to reproduce a Jupyter notebook : + +\begin{itemize} + \item with \textit{blocks} for \textsf{RAW} or \textsf{Markdown} ; + \item with \ShowCode{listings} and no limitation with compiler, but without code execution ; + \item with \ShowCode{piton} and \ShowCode{pyluatex} with \hologo{LuaLaTeX} and \textsf{--shell-escape}. +\end{itemize} + +The documentation use \hologo{pdfLaTeX}, but examples with \hologo{LuaLaTeX} are given in an other doc. + +\subsection{Loading} + +The package loads within the preamble, with \ShowCode{\textbackslash usepackage\{pynotebook\}}. + +The loaded packages are \ShowCode{tcolorbox} (with \ShowCode{skins,breakable,listings}), \ShowCode{calc}, \ShowCode{xstring} and \ShowCode{iftex}. + +If \hologo{LuaLaTeX} is detected, \ShowCode{piton} is loaded (but there's an option to avoid the loading), whereas \ShowCode{pyluatex} needs to be manually loaded, due to the declaration of the executable. + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +%with pdflatex +\usepackage{pynotebook} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +%with LuaLaTeX and piton +\usepackage{pynotebook} +\usepackage[options]{pyluatex} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +%with LuaLaTeX but without piton capability +\usepackage[nopiton]{pynotebook} +\end{codehigh} + +\subsection{Global usage} + +In order to respect the left-alignment, the \textit{titles} \ShowCode{In [ ]} and \ShowCode{Out[ ]} can add a blank character, to avoid offset due to counter with two digits ! + +\pagebreak + +\section{Common text blocks} + +\subsection{Intro} + +The different text blocks are given with their own output. + +The package provides environments : + +\begin{itemize} + \item for a \textsf{RAW} block, with \texttt{teletype} font ; for a \textsf{Mardown} block, with all \hologo{LaTeX} support ; + \item a version with \textsf{piton} is given, in order to align perfectly the blocks ! +\end{itemize} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookRaw}[options tcbox]{<width>} +<code> +\end{NotebookRaw} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookMarkdown}[options tcbox]{<width>} +<code> +\end{NotebookMarkdown} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookPitonRaw}[options tcbox]{<width>} +<code> +\end{NotebookPitonRaw} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookPitonMarkdown}[options tcbox]{<width>} +<code> +\end{NotebookPitonMarkdown} +\end{codehigh} + +\subsection{Examples} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.}\\ +It's possible to use \LaTeX{} formulas, like % +\[ + \left\lbrace\begin{array}{l} + F_0 = 0\\ + F_1 = 1 \\ + F_{n+2} = F_{n+1} + F_n + \end{array}\right. +\] +\end{NotebookMarkdown} + +\begin{NotebookRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookRaw} +\end{codehigh} + +\begin{NotebookMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.}\\ +It's possible to use \LaTeX{} formulas, like % +\[ + \left\lbrace\begin{array}{l} + F_0 = 0\\ + F_1 = 1 \\ + F_{n+2} = F_{n+1} + F_n + \end{array}\right. +\] +\end{NotebookMarkdown} + +\begin{NotebookRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookRaw} + +\pagebreak + +\section{The code blocks, with listings} + +\subsection{Intro} + +With \ShowCode{listings}, the different blocks are given with their own output (no code execution). + +The package provides environments : + +\begin{itemize} + \item with \texttt{In~[...]} ; + \item with \texttt{Out[...]} ; + \item without \textit{header}, eg for a \textit{console execution}. +\end{itemize} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookIn}(*)[options tcbox]{<width>} +<code> +\end{NotebookIn} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookOut}(*)[options tcbox]{<width>} +<code> +\end{NotebookOut} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookConsole}[options tcbox]{<width>} +<code> +\end{NotebookConsole} +\end{codehigh} + +The starred versions removes the counter, and don't display it. + +The blocks with \textit{header} (\texttt{In/Out}) are automatically numbered, and the global style is fixed. + +\subsection{Examples} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookIn}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}{\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +\begin{NotebookConsole}{\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookConsole} +\end{codehigh} + +\begin{NotebookIn}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}{\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +\begin{NotebookConsole}{\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookConsole} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookIn}*[flush right]{13cm} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +\end{NotebookIn} + +\begin{NotebookOut}*[flush right]{13cm} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +\begin{NotebookConsole}[flush right]{13cm} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookConsole} +\end{codehigh} + +\begin{NotebookIn}*[flush right]{13cm} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}*[flush right]{13cm} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +\begin{NotebookConsole}[flush right]{13cm} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookConsole} + +\pagebreak + +\section{The code blocks, with piton and pyluatex} + +\subsection{Intro} + +With \ShowCode{piton} and \ShowCode{pyluatex}, the different blocks are given with the code to be displayed (\texttt{In/Out}) or with the code to be executed (\textsf{Out} or \textsf{Console}). + +The package provides environments : + +\begin{itemize} + \item with \texttt{In~[...]} ; + \item with \texttt{Out[...]} ; + \item without \textit{header}, eg for a \textit{console execution}. +\end{itemize} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookPitonIn}(*)[options tcbox]{<width>} +<code> +\end{NotebookPitonIn} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookPitonOut}(*)[options tcbox]{<width>} +<code> +\end{NotebookPitonOut} +\end{codehigh} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\begin{NotebookPitonConsole}[options tcbox]{<width>} +<code> +\end{NotebookPitonConsole} +\end{codehigh} + +The starred versions removes the counter, and don't display it. + +The blocks with \textit{header} (\texttt{In/Out}) are automatically numbered, and the global style is fixed. + +\subsection{Examples} + +Due to the necessary usage of \hologo{LuaLaTeX} and \textsf{--shell-escape}, examples are given in a separate file. + +\pagebreak + +\section{Some customization} + +\subsection{Ideas} + +The package provides to macro, in order to : + +\begin{itemize} + \item configure the \textit{words} \texttt{In/Out} in \textsf{french} ; + \item configure the spacing before and after the boxes (\ShowCode{0.33\textbackslash baselineskip} by default). +\end{itemize} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\SetJupyterLng{fr} %set french words + +\SetJupyterParSkip{<length>} %modify space before/after (or default) + +\setcounter{JupyterIn}{<nb>} %modify the counter +\end{codehigh} + +\subsection{Examples} + +\begin{codehigh}[language=latex/latex2,style/main=cyan!10,style/code=cyan!10] +\SetJupyterLng{fr} +\SetJupyterParSkip{\baselineskip} +\setcounter{JupyterIn}{14} + +\begin{NotebookIn}{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}{0.75\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} +\end{codehigh} + +\SetJupyterLng{fr} +\SetJupyterParSkip{\baselineskip} +\setcounter{JupyterIn}{14} + +\hrulefill + +\begin{NotebookIn}{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookIn} + +\begin{NotebookOut}{0.75\linewidth} +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] +\end{NotebookOut} + +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.pdf b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.pdf Binary files differnew file mode 100644 index 00000000000..7869f7ff323 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.pdf diff --git a/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.tex b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.tex new file mode 100644 index 00000000000..86123fccfa4 --- /dev/null +++ b/Master/texmf-dist/doc/latex/pynotebook/pynotebook-examples-pitonpylautex.tex @@ -0,0 +1,239 @@ +% !TeX TXS-program:compile = txs:///arara +% arara: lualatex: {shell: yes, synctex: yes, interaction: batchmode} +% arara: lualatex: {shell: yes, synctex: yes, interaction: batchmode} if found('log', '(undefined references|Please rerun|Rerun to get)') + +\documentclass[a4paper,11pt]{article} +\def\PLver{0.1.0} +\usepackage[margin=1.5cm]{geometry} +\usepackage{pynotebook} +\usepackage[executable=python]{pyluatex} +\usepackage{codehigh} + +\begin{document} + +\part*{pynotebook (\PLver), with piton and pyluatex} + +\section{Preamble} + +\begin{codehigh} +\documentclass{article} +\usepackage{pynotebook} +\usepackage[executable=python]{pyluatex} % with a specific compilation !! +\end{codehigh} + +\section{Examples of text blocks} + +\begin{codehigh} +\begin{NotebookPitonMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.} + +It's possible to use \LaTeX{} formulas, like % +\[ + \left\lbrace\begin{array}{l} + F_0 = 0\\ + F_1 = 1 \\ + F_{n+2} = F_{n+1} + F_n + \end{array}\right. +\] +\end{NotebookPitonMarkdown} + +\begin{NotebookPitonRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookPitonRaw} +\end{codehigh} + +\begin{NotebookPitonMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.} + +It's possible to use \LaTeX{} formulas, like % +\[ +\left\lbrace\begin{array}{l} +F_0 = 0\\ +F_1 = 1 \\ +F_{n+2} = F_{n+1} + F_n +\end{array}\right. +\] +\end{NotebookPitonMarkdown} + +\begin{NotebookPitonRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookPitonRaw} + +\section{Examples of code blocks (with execution of code !)} + +\begin{codehigh} +\begin{NotebookPitonIn}{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookPitonIn} +\end{codehigh} + +\begin{NotebookPitonIn}{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookPitonIn} + +\begin{codehigh} +\begin{NotebookPitonOut}{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonOut} +\end{codehigh} + +\begin{NotebookPitonOut}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonOut} + +\begin{codehigh} +\SetJupyterLng{fr} +\SetJupyterParSkip{\baselineskip} +\setcounter{JupyterIn}{11} +\end{codehigh} + +\SetJupyterLng{fr} +\SetJupyterParSkip{\baselineskip} +\setcounter{JupyterIn}{14} + +\begin{codehigh} +\begin{NotebookPitonIn}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookPitonIn} +\end{codehigh} + +\begin{NotebookPitonIn}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookPitonIn} + +\begin{codehigh} +\begin{NotebookPitonOut}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonOut} +\end{codehigh} + +\begin{NotebookPitonOut}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonOut} + +\begin{codehigh} +\begin{NotebookPitonConsole}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonConsole} +\end{codehigh} + +\begin{NotebookPitonConsole}[center]{0.75\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonConsole} + +\pagebreak + +\section{Global example} + +\SetJupyterParSkip{default} +\setcounter{JupyterIn}{0} + +\begin{NotebookPitonMarkdown}{\linewidth} +{\Large\bfseries This is a test for a \textsf{Markdown} block.} + +It's possible to use \LaTeX{} formulas, like % +\[ +\left\lbrace\begin{array}{l} +F_0 = 0\\ +F_1 = 1 \\ +F_{n+2} = F_{n+1} + F_n +\end{array}\right. +\] +\end{NotebookPitonMarkdown} + +\begin{NotebookPitonRaw}{\linewidth} +This is a sample block, with RAW output. + +Just to use all capacities of Jupyter notebook ;-) +\end{NotebookPitonRaw} + +\begin{NotebookPitonIn}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +[fibonacci_of(n) for n in range(15)] +\end{NotebookPitonIn} + +\begin{NotebookPitonOut}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(15)]) +\end{NotebookPitonOut} + +\begin{NotebookPitonRaw}{\linewidth} +Let’s compute Fibonacci terms from 10th to 20th :-) +\end{NotebookPitonRaw} + +\begin{NotebookPitonIn}{\linewidth} +[fibonacci_of(n) for n in range(10,21)] +\end{NotebookPitonIn} + +\begin{NotebookPitonConsole}{\linewidth} +def fibonacci_of(n) : + if n in {0,1} : + return n + return fibonacci_of(n-1) + fibonacci_of(n-2) + +print([fibonacci_of(n) for n in range(10,21)]) +\end{NotebookPitonConsole} + +\end{document}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/latex/pynotebook/pynotebook.sty b/Master/texmf-dist/tex/latex/pynotebook/pynotebook.sty new file mode 100644 index 00000000000..6a84f42a6bf --- /dev/null +++ b/Master/texmf-dist/tex/latex/pynotebook/pynotebook.sty @@ -0,0 +1,315 @@ +% Author : C. Pierquet +% licence : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{pynotebook}[2024/02/15 0.1.0 Present codes like in jupyter notebook] +%0.1.0 Initial version + +%------Usefull packages and libraries +\RequirePackage{tcolorbox} +\RequirePackage{iftex} +\RequirePackage{xstring} +\RequirePackage{calc} +\tcbuselibrary{skins,breakable} + +%-----Option(s) for not loading piton and not creating environments +\newif\if@piton \@pitontrue +\DeclareOption{nopiton}{\@pitonfalse}% +\DeclareOption*{} +\ProcessOptions\relax + +%------Utils +\newcommand\JupyterPromptIn{In~} +\newcommand\JupyterPromptOut{Out} + +\NewDocumentCommand\promptjupyter{ s m m m m }{% + \IfBooleanTF{#1}% + {\makebox[0pt][r]{\texttt{\color{#3}#2[~~]:#5}}\vspace{-\baselineskip}}% + {\makebox[0pt][r]{\texttt{\color{#3}#2[#4]:#5}}\vspace{-\baselineskip}}% +} + +\newcounter{JupyterIn} + +\NewDocumentCommand\SetJupyterLng{ m }{% + \IfStrEqCase{#1}{% + {en}{\renewcommand\JupyterPromptIn{In~}\renewcommand\JupyterPromptOut{Out}}% + {fr}{\renewcommand\JupyterPromptIn{Entrée}\renewcommand\JupyterPromptOut{Sortie}}% + }% + [\renewcommand\JupyterPromptIn{In~}\renewcommand\JupyterPromptOut{Out}]% +} + +%-----Parskip +\newlength{\JupyterParSkip} +\setlength{\JupyterParSkip}{0.33\baselineskip} +\NewDocumentCommand\SetJupyterParSkip{ m }{% + \IfStrEq{#1}{default}% + {\setlength{\JupyterParSkip}{0.33\baselineskip}}% + {\setlength{\JupyterParSkip}{#1}}% +} +\tcbset{tcbjpuparskip/.style={before skip=\JupyterParSkip,after skip=\JupyterParSkip}} + +%------With listings (pdflatex or lualatex) +\ifluatex +\tcbuselibrary{listings} +\lstdefinestyle{PLJupyter}{% + language = python, + inputencoding = utf8, + basicstyle = \ttfamily\footnotesize, + keywordstyle = \color{green!50!black}, + keywordstyle = [2]\color{magenta}, + commentstyle = \color{gray}\itshape, + stringstyle = \color{red!75}, + numberstyle = \scriptsize\ttfamily\color{gray}, + aboveskip = 0pt, + belowskip = 0pt, + tabsize = 4, + showstringspaces = false, + columns = fullflexible, + keepspaces = true, + breaklines = true, + breakatwhitespace = true +} +\else +\tcbuselibrary{listingsutf8} +\lstdefinestyle{PLJupyter}{% + language = python, + inputencoding = utf8/latin1, + basicstyle = \ttfamily\footnotesize, + keywordstyle = \color{green!50!black}, + keywordstyle = [2]\color{magenta}, + commentstyle = \color{gray}\itshape, + stringstyle = \color{red!75}, + numberstyle = \scriptsize\ttfamily\color{gray}, + aboveskip = 0pt, + belowskip = 0pt, + tabsize = 4, + showstringspaces = false, + columns = fullflexible, + keepspaces = true, + breaklines = true, + breakatwhitespace = true +} +\fi + +\newlength{\LargeurPromptJupyterIn} +\newlength{\LargeurPromptJupyterOut} +\newlength{\LargeurPromptJupyter} +\newlength{\OffsetPromptJupyter} +\setlength{\OffsetPromptJupyter}{9pt} +\newlength{\LargeurNumbersJupyter} + +\newcommand\SetJupyterLengths{% + \settowidth{\LargeurPromptJupyterIn}{\footnotesize\texttt{\JupyterPromptIn[10]:}}% + \settowidth{\LargeurPromptJupyterOut}{\footnotesize\texttt{\JupyterPromptOut[10]:}}% + \setlength{\LargeurPromptJupyter}{\maxof{\LargeurPromptJupyterIn}{\LargeurPromptJupyterOut}} + \settowidth{\LargeurNumbersJupyter}{\scriptsize\texttt{00}}% +} + +\NewDocumentEnvironment{NotebookIn}{ s O{} m }% +{% + \SetJupyterLengths% + \noindent% + \IfBooleanTF{#1}% + {\tcbset{tcbjpuptitlein/.style={title=\promptjupyter*{\JupyterPromptIn}{red!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupyter}}}}}% + {\refstepcounter{JupyterIn}\tcbset{tcbjpuptitlein/.style={title=\promptjupyter{\JupyterPromptIn\ifnum\value{JupyterIn}<10~\fi}{red!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupyter}}}}}% + \tcblisting{% + breakable,sharp corners=all,boxrule=0.5pt,enhanced,size=small,width=#3,tcbjpuparskip, + colframe=gray,colback=lightgray!15, + left skip=\LargeurPromptJupyter+\OffsetPromptJupyter-2mm, + tcbjpuptitlein, + fonttitle=\linespread{1}\footnotesize, + attach title to upper, + listing only, + listing options={style=PLJupyter,xleftmargin=\LargeurNumbersJupyter,numbers=left,firstnumber=1,numbersep=2mm},% + overlay={\begin{tcbclipinterior}\draw[line width=0.375pt,gray!75] ([xshift={\LargeurNumbersJupyter+1mm}]frame.south west)--([xshift={\LargeurNumbersJupyter+1mm}]frame.north west);\end{tcbclipinterior}},% + #2 + }% +}% +{% + \endtcblisting% +} + +\NewDocumentEnvironment{NotebookConsole}{ O{} m }% +{% + \SetJupyterLengths% + \addtolength{\LargeurNumbersJupyter}{0.5mm} + \noindent% + \tcblisting{% + breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#2,tcbjpuparskip, + colframe=lightgray!15,colback=white, + left skip=\LargeurPromptJupyter+\OffsetPromptJupyter-2mm, + attach title to upper, + listing only, + listing options={style=tcblatex,basicstyle=\ttfamily\footnotesize},% + #1 + }% +}% +{% + \endtcblisting% +}% + +\NewDocumentEnvironment{NotebookOut}{ s O{} m }% +{% + \SetJupyterLengths% + \addtolength{\LargeurNumbersJupyter}{0.5mm} + \IfBooleanTF{#1}% + {\tcbset{tcbjpuptitleout/.style={title=\promptjupyter*{\JupyterPromptOut}{blue!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupyter}}}}}% + {\tcbset{tcbjpuptitleout/.style={title=\promptjupyter{\JupyterPromptOut\ifnum\value{JupyterIn}<10~\fi}{blue!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupyter}}}}}% + \noindent% + \tcblisting{% + breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#3,tcbjpuparskip, + colframe=lightgray!15,colback=white, + left skip=\LargeurPromptJupyter+\OffsetPromptJupyter-2mm, + tcbjpuptitleout, + fonttitle=\linespread{1}\footnotesize, + attach title to upper, + listing only, + listing options={style=tcblatex,basicstyle=\ttfamily\footnotesize},% + #2 + }% +}% +{% + \endtcblisting% +}% + +\NewDocumentEnvironment{NotebookRaw}{ O{} m }% +{% + \SetJupyterLengths% + \addtolength{\LargeurNumbersJupyter}{0.5mm} + \noindent% + \tcblisting{% + breakable,sharp corners=all,boxrule=0.5pt,enhanced,size=small,width=#2,tcbjpuparskip, + colframe=gray,colback=lightgray!15, + left skip=\LargeurPromptJupyter+\OffsetPromptJupyter-2mm, + attach title to upper, + listing only, + listing options={style=tcblatex,basicstyle=\ttfamily\footnotesize,numberstyle=\scriptsize\ttfamily\color{gray},xleftmargin=\LargeurNumbersJupyter,numbers=left,firstnumber=1,numbersep=2mm},% + overlay={\begin{tcbclipinterior}\draw[line width=0.375pt,gray!75] ([xshift={\LargeurNumbersJupyter+1mm}]frame.south west)--([xshift={\LargeurNumbersJupyter+1mm}]frame.north west);\end{tcbclipinterior}},% + #1 + }% +}% +{% + \endtcblisting% +}% + +\NewDocumentEnvironment{NotebookMarkdown}{ O{} m }% +{% + \SetJupyterLengths% + \addtolength{\LargeurNumbersJupyter}{0.5mm} + \noindent% + \tcolorbox[breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#2,tcbjpuparskip,colframe=lightgray!15,colback=white,left skip=\LargeurPromptJupyter+\OffsetPromptJupyter-2mm, + attach title to upper,fontupper=\footnotesize,tcbjpuparskip,#1]% +}% +{% + \endtcolorbox% +}% + +\if@piton +%----With Piton (only lualatex) +\ifluatex +\RequirePackage{piton} +\RequirePackage{environ} +\newlength{\LargeurPromptJupiter} +\newlength{\LargeurPromptJupiterIn} +\newlength{\LargeurPromptJupiterOut} +\newlength{\OffsetPromptJupiter} +\setlength{\OffsetPromptJupiter}{9pt} +\newlength{\LargeurNumbersJupiter} + +\newcommand\SetJupiterLengths{% + \settowidth{\LargeurPromptJupiterIn}{\footnotesize\texttt{\JupyterPromptIn[10]:}}% + \settowidth{\LargeurPromptJupiterOut}{\footnotesize\texttt{\JupyterPromptOut[10]:}}% + \setlength{\LargeurPromptJupiter}{\maxof{\LargeurPromptJupiterIn}{\LargeurPromptJupiterOut}}% + \settowidth{\LargeurNumbersJupiter}{\footnotesize\texttt{00}}% +} + +\NewPitonEnvironment{NotebookPitonIn}{ s O{} m }% +{% + \SetJupiterLengths% + \IfBooleanTF{#1}% + {\tcbset{tcbjpuptitlein/.style={title=\promptjupyter*{\JupyterPromptIn}{red!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupiter}}}}}% + {\refstepcounter{JupyterIn}\tcbset{tcbjpuptitlein/.style={title=\promptjupyter{\JupyterPromptIn\ifnum\value{JupyterIn}<10~\fi}{red!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupiter}}}}}% + \noindent% + \PitonOptions{left-margin={\LargeurNumbersJupiter+1.75mm},all-line-numbers}% + \PitonOptions{tabs-auto-gobble,break-lines,indent-broken-lines}% + %on crée la boîte + \tcolorbox[breakable,sharp corners=all,boxrule=0.5pt,enhanced,size=small,width=#3,colframe=gray,colback=lightgray!15,left skip=\LargeurPromptJupiter+\OffsetPromptJupiter-2mm,tcbjpuptitlein,fonttitle=\linespread{1}\footnotesize,attach title to upper,fontupper=\footnotesize,overlay={% + \begin{tcbclipinterior}\draw[line width=0.375pt,gray!75] ([xshift={\LargeurNumbersJupiter+2.25mm}]frame.south west)--([xshift={\LargeurNumbersJupiter+2.25mm}]frame.north west);\end{tcbclipinterior}},bottom=-0.5mm,tcbjpuparskip,#2]% +}% +{% + \endtcolorbox% +} + +\NewDocumentEnvironment{NotebookPitonConsole}{ O{} m }% +{% + \SetJupiterLengths% + \noindent% + \PitonOptions{tabs-auto-gobble,break-lines,indent-broken-lines}% + %on crée la boîte + \PyLTVerbatimEnv% + \tcolorbox[breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#2,colframe=lightgray!15,colback=white,left skip=\LargeurPromptJupiter+\OffsetPromptJupiter-2mm,attach title to upper,fontupper=\footnotesize,bottom=-0.5mm,tcbjpuparskip,#1]% + \begin{pythonq}% +}% +{% + \end{pythonq}% + \directlua{% + tex.print("\\begin{Piton}") + tex.print(pyluatex.get_last_output()) + tex.print("\\end{Piton}") + }% + \endtcolorbox% +} + +\NewDocumentEnvironment{NotebookPitonOut}{ s O{} m }% +{% + \SetJupiterLengths% + \IfBooleanTF{#1}% + {\tcbset{tcbjpuptitleout/.style={title=\promptjupyter*{\JupyterPromptOut}{blue!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupiter}}}}}% + {\tcbset{tcbjpuptitleout/.style={title=\promptjupyter{\JupyterPromptOut\ifnum\value{JupyterIn}<10~\fi}{blue!75!black}{\theJupyterIn}{\hspace*{\OffsetPromptJupiter}}}}}% + \noindent% + \PitonOptions{tabs-auto-gobble,break-lines,indent-broken-lines}% + %on crée la boîte + \PyLTVerbatimEnv% + \tcolorbox[breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#3,colframe=lightgray!15,colback=white,left skip=\LargeurPromptJupiter+\OffsetPromptJupiter-2mm,tcbjpuptitleout,fonttitle=\linespread{1}\footnotesize,attach title to upper,fontupper=\footnotesize,bottom=-0.5mm,tcbjpuparskip,#2]% + \begin{pythonq}% +}% +{% + \end{pythonq}% + \directlua{% + tex.print("\\begin{Piton}") + tex.print(pyluatex.get_last_output()) + tex.print("\\end{Piton}") + }% + \endtcolorbox% +} + +\NewPitonEnvironment{NotebookPitonRaw}{ O{} m }% +{% + \SetJupiterLengths% + \noindent% + \SetPitonStyle{Number=}% + \PitonOptions{left-margin={\LargeurNumbersJupiter+1.75mm},all-line-numbers,language=minimal}% + \PitonOptions{tabs-auto-gobble,break-lines,indent-broken-lines}% + %on crée la boîte + \tcolorbox[breakable,sharp corners=all,boxrule=0.5pt,enhanced,size=small,width=#2,colframe=gray,colback=lightgray!15,left skip=\LargeurPromptJupiter+\OffsetPromptJupiter-2mm,attach title to upper,fontupper=\footnotesize,overlay={% + \begin{tcbclipinterior}\draw[line width=0.375pt,gray!75] ([xshift={\LargeurNumbersJupiter+2.25mm}]frame.south west)--([xshift={\LargeurNumbersJupiter+2.25mm}]frame.north west);\end{tcbclipinterior}},bottom=-0.5mm,tcbjpuparskip,#1]% +}% +{% + \endtcolorbox% +} + +\NewDocumentEnvironment{NotebookPitonMarkdown}{ O{} m }% +{% + \SetJupiterLengths% + \noindent% + \tcolorbox[breakable,sharp corners=all,boxrule=0.3pt,enhanced,size=small,width=#2,tcbjpuparskip,colframe=lightgray!15,colback=white,left skip=\LargeurPromptJupiter+\OffsetPromptJupiter-2mm, + attach title to upper,fontupper=\footnotesize,tcbjpuparskip,#1]% +}% +{% + \endtcolorbox% +}% + +\fi +\fi + +\endinput
\ No newline at end of file |