| 1 |
% !TeX TXS-program:compile = txs:///arara |
| 2 |
% arara: lualatex: {shell: yes, synctex: no, interaction: batchmode} |
| 3 |
% arara: lualatex: {shell: yes, synctex: no, interaction: batchmode} if found('log', '(undefined references|Please rerun|Rerun to get)') |
| 4 |
|
| 5 |
\documentclass[a4paper,11pt]{article} |
| 6 |
\def\PLver{0.1.6} |
| 7 |
\usepackage[margin=1.5cm]{geometry} |
| 8 |
\usepackage{pynotebook} |
| 9 |
\usepackage[executable=python]{pyluatex} |
| 10 |
\usepackage{codehigh} |
| 11 |
|
| 12 |
\begin{document} |
| 13 |
|
| 14 |
\part*{pynotebook (\PLver), with piton and pyluatex} |
| 15 |
|
| 16 |
\section{Preamble} |
| 17 |
|
| 18 |
\begin{codehigh} |
| 19 |
\documentclass{article} |
| 20 |
\usepackage{pynotebook} |
| 21 |
\usepackage[executable=python]{pyluatex} % with a specific compilation !! |
| 22 |
% pyluatex version > 0.7.0 |
| 23 |
\end{codehigh} |
| 24 |
|
| 25 |
\section{With gobble} |
| 26 |
|
| 27 |
Due to \texttt{gobble} options with \textsf{piton}, it's possible to add \texttt{gobble} parameters to the environments, given within last argument between \texttt{<...>}, and default is \texttt{empty} : |
| 28 |
|
| 29 |
\begin{itemize} |
| 30 |
\item \texttt{<gobble=xx>} ; |
| 31 |
\item \texttt{<env-gobble>} ; |
| 32 |
\item \texttt{<auto-gobble>} ; |
| 33 |
\item \texttt{<tabs-auto-gobble>}. |
| 34 |
\end{itemize} |
| 35 |
|
| 36 |
\noindent{}\textbf{Explanations} are given in the doc of \textsf{piton} : \texttt{https://ctan.org/pkg/piton} |
| 37 |
|
| 38 |
\section{Examples of text blocks} |
| 39 |
|
| 40 |
\begin{codehigh} |
| 41 |
\begin{NotebookPitonMarkdown}{\linewidth} |
| 42 |
{\Large\bfseries This is a test for a \textsf{Markdown} block.} |
| 43 |
|
| 44 |
It's possible to use \LaTeX{} formulas, like % |
| 45 |
\[ |
| 46 |
\left\lbrace\begin{array}{l} |
| 47 |
F_0 = 0\\ |
| 48 |
F_1 = 1 \\ |
| 49 |
F_{n+2} = F_{n+1} + F_n |
| 50 |
\end{array}\right. |
| 51 |
\] |
| 52 |
\end{NotebookPitonMarkdown} |
| 53 |
|
| 54 |
\begin{NotebookPitonRaw}{\linewidth} |
| 55 |
This is a sample block, with RAW output. |
| 56 |
|
| 57 |
Just to use all capacities of Jupyter notebook ;-) |
| 58 |
\end{NotebookPitonRaw} |
| 59 |
\end{codehigh} |
| 60 |
|
| 61 |
\begin{NotebookPitonMarkdown}{\linewidth} |
| 62 |
{\Large\bfseries This is a test for a \textsf{Markdown} block.} |
| 63 |
|
| 64 |
It's possible to use \LaTeX{} formulas, like % |
| 65 |
\[ |
| 66 |
\left\lbrace\begin{array}{l} |
| 67 |
F_0 = 0\\ |
| 68 |
F_1 = 1 \\ |
| 69 |
F_{n+2} = F_{n+1} + F_n |
| 70 |
\end{array}\right. |
| 71 |
\] |
| 72 |
\end{NotebookPitonMarkdown} |
| 73 |
|
| 74 |
\begin{NotebookPitonRaw}{\linewidth} |
| 75 |
This is a sample block, with RAW output. |
| 76 |
|
| 77 |
Just to use all capacities of Jupyter notebook ;-) |
| 78 |
\end{NotebookPitonRaw} |
| 79 |
|
| 80 |
\section{Examples of code blocks (with execution of code !)} |
| 81 |
|
| 82 |
\subsection{With block In then block Out} |
| 83 |
|
| 84 |
\begin{codehigh} |
| 85 |
\begin{NotebookPitonIn}{0.75\linewidth} |
| 86 |
def fibonacci_aux(n,a,b): |
| 87 |
if n == 0 : |
| 88 |
return a |
| 89 |
elif n == 1 : |
| 90 |
return b |
| 91 |
else: |
| 92 |
return fibonacci_aux(n-1,b,a+b) |
| 93 |
|
| 94 |
def fibonacci_of(n): |
| 95 |
return fibonacci_aux(n,0,1) |
| 96 |
|
| 97 |
[fibonacci_of(n) for n in range(10)] |
| 98 |
\end{NotebookPitonIn} |
| 99 |
\end{codehigh} |
| 100 |
|
| 101 |
\begin{NotebookPitonIn}{0.75\linewidth} |
| 102 |
def fibonacci_aux(n,a,b): |
| 103 |
if n == 0 : |
| 104 |
return a |
| 105 |
elif n == 1 : |
| 106 |
return b |
| 107 |
else: |
| 108 |
return fibonacci_aux(n-1,b,a+b) |
| 109 |
|
| 110 |
def fibonacci_of(n): |
| 111 |
return fibonacci_aux(n,0,1) |
| 112 |
|
| 113 |
[fibonacci_of(n) for n in range(10)] |
| 114 |
\end{NotebookPitonIn} |
| 115 |
|
| 116 |
\begin{codehigh} |
| 117 |
\begin{NotebookPitonOut}{0.75\linewidth} |
| 118 |
def fibonacci_aux(n,a,b): |
| 119 |
if n == 0 : |
| 120 |
return a |
| 121 |
elif n == 1 : |
| 122 |
return b |
| 123 |
else: |
| 124 |
return fibonacci_aux(n-1,b,a+b) |
| 125 |
|
| 126 |
def fibonacci_of(n): |
| 127 |
return fibonacci_aux(n,0,1) |
| 128 |
|
| 129 |
print([fibonacci_of(n) for n in range(10)]) |
| 130 |
\end{NotebookPitonOut} |
| 131 |
\end{codehigh} |
| 132 |
|
| 133 |
\begin{NotebookPitonOut}{0.75\linewidth} |
| 134 |
def fibonacci_aux(n,a,b): |
| 135 |
if n == 0 : |
| 136 |
return a |
| 137 |
elif n == 1 : |
| 138 |
return b |
| 139 |
else: |
| 140 |
return fibonacci_aux(n-1,b,a+b) |
| 141 |
|
| 142 |
def fibonacci_of(n): |
| 143 |
return fibonacci_aux(n,0,1) |
| 144 |
|
| 145 |
print([fibonacci_of(n) for n in range(10)]) |
| 146 |
\end{NotebookPitonOut} |
| 147 |
|
| 148 |
\pagebreak |
| 149 |
|
| 150 |
\begin{codehigh} |
| 151 |
\SetJupyterLng{fr} |
| 152 |
\SetJupyterParSkip{\baselineskip} |
| 153 |
\setcounter{JupyterIn}{11} |
| 154 |
\end{codehigh} |
| 155 |
|
| 156 |
\SetJupyterLng{fr} |
| 157 |
\SetJupyterParSkip{\baselineskip} |
| 158 |
\setcounter{JupyterIn}{11} |
| 159 |
|
| 160 |
\begin{codehigh} |
| 161 |
\begin{NotebookPitonIn}[center]{0.75\linewidth} |
| 162 |
def fibonacci_aux(n,a,b): |
| 163 |
if n == 0 : |
| 164 |
return a |
| 165 |
elif n == 1 : |
| 166 |
return b |
| 167 |
else: |
| 168 |
return fibonacci_aux(n-1,b,a+b) |
| 169 |
|
| 170 |
def fibonacci_of(n): |
| 171 |
return fibonacci_aux(n,0,1) |
| 172 |
|
| 173 |
print([fibonacci_of(n) for n in range(10)]) |
| 174 |
\end{NotebookPitonIn} |
| 175 |
\end{codehigh} |
| 176 |
|
| 177 |
\begin{NotebookPitonIn}[center]{0.75\linewidth} |
| 178 |
def fibonacci_aux(n,a,b): |
| 179 |
if n == 0 : |
| 180 |
return a |
| 181 |
elif n == 1 : |
| 182 |
return b |
| 183 |
else: |
| 184 |
return fibonacci_aux(n-1,b,a+b) |
| 185 |
|
| 186 |
def fibonacci_of(n): |
| 187 |
return fibonacci_aux(n,0,1) |
| 188 |
|
| 189 |
print([fibonacci_of(n) for n in range(10)]) |
| 190 |
\end{NotebookPitonIn} |
| 191 |
|
| 192 |
\begin{codehigh} |
| 193 |
\begin{NotebookPitonOut}[center]{0.75\linewidth} |
| 194 |
def fibonacci_aux(n,a,b): |
| 195 |
if n == 0 : |
| 196 |
return a |
| 197 |
elif n == 1 : |
| 198 |
return b |
| 199 |
else: |
| 200 |
return fibonacci_aux(n-1,b,a+b) |
| 201 |
|
| 202 |
def fibonacci_of(n): |
| 203 |
return fibonacci_aux(n,0,1) |
| 204 |
|
| 205 |
print([fibonacci_of(n) for n in range(10)]) |
| 206 |
\end{NotebookPitonOut} |
| 207 |
\end{codehigh} |
| 208 |
|
| 209 |
\begin{NotebookPitonOut}[center]{0.75\linewidth} |
| 210 |
def fibonacci_aux(n,a,b): |
| 211 |
if n == 0 : |
| 212 |
return a |
| 213 |
elif n == 1 : |
| 214 |
return b |
| 215 |
else: |
| 216 |
return fibonacci_aux(n-1,b,a+b) |
| 217 |
|
| 218 |
def fibonacci_of(n): |
| 219 |
return fibonacci_aux(n,0,1) |
| 220 |
|
| 221 |
print([fibonacci_of(n) for n in range(10)]) |
| 222 |
\end{NotebookPitonOut} |
| 223 |
|
| 224 |
\begin{codehigh} |
| 225 |
\begin{NotebookPitonConsole}[center]{0.75\linewidth} |
| 226 |
def fibonacci_aux(n,a,b): |
| 227 |
if n == 0 : |
| 228 |
return a |
| 229 |
elif n == 1 : |
| 230 |
return b |
| 231 |
else: |
| 232 |
return fibonacci_aux(n-1,b,a+b) |
| 233 |
|
| 234 |
def fibonacci_of(n): |
| 235 |
return fibonacci_aux(n,0,1) |
| 236 |
|
| 237 |
print([fibonacci_of(n) for n in range(10)]) |
| 238 |
\end{NotebookPitonConsole} |
| 239 |
\end{codehigh} |
| 240 |
|
| 241 |
\begin{NotebookPitonConsole}[center]{0.75\linewidth} |
| 242 |
def fibonacci_aux(n,a,b): |
| 243 |
if n == 0 : |
| 244 |
return a |
| 245 |
elif n == 1 : |
| 246 |
return b |
| 247 |
else: |
| 248 |
return fibonacci_aux(n-1,b,a+b) |
| 249 |
|
| 250 |
def fibonacci_of(n): |
| 251 |
return fibonacci_aux(n,0,1) |
| 252 |
|
| 253 |
print([fibonacci_of(n) for n in range(10)]) |
| 254 |
\end{NotebookPitonConsole} |
| 255 |
|
| 256 |
\pagebreak |
| 257 |
|
| 258 |
\subsection{With block In/Out} |
| 259 |
|
| 260 |
\SetJupyterLng{en} |
| 261 |
\SetJupyterParSkip{0.33\baselineskip} |
| 262 |
\setcounter{JupyterIn}{0} |
| 263 |
|
| 264 |
\begin{codehigh} |
| 265 |
\begin{NotebookPitonInOut}{0.75\linewidth} |
| 266 |
def fibonacci_aux(n,a,b): |
| 267 |
if n == 0 : |
| 268 |
return a |
| 269 |
elif n == 1 : |
| 270 |
return b |
| 271 |
else: |
| 272 |
return fibonacci_aux(n-1,b,a+b) |
| 273 |
|
| 274 |
def fibonacci_of(n): |
| 275 |
return fibonacci_aux(n,0,1) |
| 276 |
|
| 277 |
print([fibonacci_of(n) for n in range(10)]) |
| 278 |
\end{NotebookPitonInOut} |
| 279 |
\end{codehigh} |
| 280 |
|
| 281 |
\begin{NotebookPitonInOut}{0.75\linewidth} |
| 282 |
def fibonacci_aux(n,a,b): |
| 283 |
if n == 0 : |
| 284 |
return a |
| 285 |
elif n == 1 : |
| 286 |
return b |
| 287 |
else: |
| 288 |
return fibonacci_aux(n-1,b,a+b) |
| 289 |
|
| 290 |
def fibonacci_of(n): |
| 291 |
return fibonacci_aux(n,0,1) |
| 292 |
|
| 293 |
print([fibonacci_of(n) for n in range(10)]) |
| 294 |
\end{NotebookPitonInOut} |
| 295 |
|
| 296 |
%====begin todo |
| 297 |
|
| 298 |
\subsection{Alternate environment for In/Out} |
| 299 |
|
| 300 |
Thanks to F. Pantigny, an alternate environment for \texttt{In/Out} is available, with \textit{all} line numbers and continuation symbol. |
| 301 |
|
| 302 |
\begin{codehigh} |
| 303 |
\begin{NotebookPitonAllNum}{0.66\linewidth} |
| 304 |
print([i**2 for i in range(50)]) |
| 305 |
\end{NotebookPitonAllNum} |
| 306 |
\end{codehigh} |
| 307 |
|
| 308 |
\begin{NotebookPitonAllNum}{0.66\linewidth} |
| 309 |
print([i**2 for i in range(50)]) |
| 310 |
\end{NotebookPitonAllNum} |
| 311 |
|
| 312 |
\pagebreak |
| 313 |
|
| 314 |
%===end todo |
| 315 |
|
| 316 |
\section{Global example} |
| 317 |
|
| 318 |
\SetJupyterParSkip{default} |
| 319 |
\setcounter{JupyterIn}{0} |
| 320 |
|
| 321 |
\begin{NotebookPitonMarkdown}{\linewidth} |
| 322 |
{\Large\bfseries This is a test for a \textsf{Markdown} block.} |
| 323 |
|
| 324 |
It's possible to use \LaTeX{} formulas, like % |
| 325 |
\[ |
| 326 |
\left\lbrace\begin{array}{l} |
| 327 |
F_0 = 0 \: ; \: F_1 = 1 \\ |
| 328 |
F_{n+2} = F_{n+1} + F_n |
| 329 |
\end{array}\right. |
| 330 |
\] |
| 331 |
\end{NotebookPitonMarkdown} |
| 332 |
|
| 333 |
\begin{NotebookPitonRaw}{\linewidth} |
| 334 |
This is a sample block, with RAW output. |
| 335 |
Just to use all capacities of Jupyter notebook ;-) |
| 336 |
\end{NotebookPitonRaw} |
| 337 |
|
| 338 |
\begin{NotebookPitonInOut}{\linewidth} |
| 339 |
def fibonacci_aux(n,a,b): |
| 340 |
if n == 0 : |
| 341 |
return a |
| 342 |
elif n == 1 : |
| 343 |
return b |
| 344 |
else: |
| 345 |
return fibonacci_aux(n-1,b,a+b) |
| 346 |
|
| 347 |
def fibonacci_of(n): |
| 348 |
return fibonacci_aux(n,0,1) |
| 349 |
|
| 350 |
print([fibonacci_of(n) for n in range(10)]) |
| 351 |
\end{NotebookPitonInOut} |
| 352 |
|
| 353 |
\begin{NotebookPitonRaw}{\linewidth} |
| 354 |
Let’s compute Fibonacci terms from 10th to 20th :-) |
| 355 |
\end{NotebookPitonRaw} |
| 356 |
|
| 357 |
\begin{NotebookPitonIn}{\linewidth} |
| 358 |
[fibonacci_of(n) for n in range(10,21)] |
| 359 |
\end{NotebookPitonIn} |
| 360 |
|
| 361 |
\begin{NotebookPitonConsole}{\linewidth} |
| 362 |
def fibonacci_aux(n,a,b): |
| 363 |
if n == 0 : |
| 364 |
return a |
| 365 |
elif n == 1 : |
| 366 |
return b |
| 367 |
else: |
| 368 |
return fibonacci_aux(n-1,b,a+b) |
| 369 |
|
| 370 |
def fibonacci_of(n): |
| 371 |
return fibonacci_aux(n,0,1) |
| 372 |
|
| 373 |
print([fibonacci_of(n) for n in range(10,21)]) |
| 374 |
\end{NotebookPitonConsole} |
| 375 |
|
| 376 |
\begin{NotebookPitonRaw}{\linewidth} |
| 377 |
Let’s work with an other function. |
| 378 |
This time in french :-) |
| 379 |
\end{NotebookPitonRaw} |
| 380 |
|
| 381 |
\begin{NotebookPitonInOut}{\linewidth} |
| 382 |
def calculPerimetre(cote1, cote2, cote3) : |
| 383 |
perimetre = cote1 + cote2 + cote3 |
| 384 |
return perimetre |
| 385 |
|
| 386 |
perimetre1 = calculPerimetre(6, 4, 3) |
| 387 |
perimetre2 = calculPerimetre(10, 3, 11) |
| 388 |
print(f"Le périm de mon 1er triangle est {perimetre1}, et celui de mon 2d est {perimetre2}.") |
| 389 |
\end{NotebookPitonInOut} |
| 390 |
|
| 391 |
\begin{NotebookPitonInOut}{\linewidth} |
| 392 |
A = 15 |
| 393 |
B = 10 |
| 394 |
C = 11 |
| 395 |
print(f"Le périmètre de mon triangle est {calculPerimetre(A,B,C)}.") |
| 396 |
\end{NotebookPitonInOut} |
| 397 |
|
| 398 |
\begin{NotebookPitonIn}{\linewidth} |
| 399 |
calculPerimetre(4, 4, 4) |
| 400 |
\end{NotebookPitonIn} |
| 401 |
|
| 402 |
\begin{NotebookPitonConsole}{\linewidth} |
| 403 |
print(calculPerimetre(4, 4, 4)) |
| 404 |
\end{NotebookPitonConsole} |
| 405 |
|
| 406 |
\begin{NotebookPitonInOut}{0.5\linewidth} |
| 407 |
print([i**2 for i in range(50)]) |
| 408 |
\end{NotebookPitonInOut} |
| 409 |
|
| 410 |
\end{document} |