facundobatista/jupynotex

Making the outcome look closer to native jupyter notebook format

hfwang132 opened this issue · 3 comments

This is an amazing project. I want to share my idea that the outcome could look closer to native jupyter notebook format.

The preamble settings (reference) are:

\newlength\inwd
\setlength\inwd{1.3cm}

\newcounter{ipythcntr}

\newtcblisting{ipythonnb}[1][\theipythcntr]{
  enlarge left by=\inwd,
  width=\linewidth-\inwd,
  enhanced,
  boxrule=0.4pt,
  colback=light-gray,
  listing only,
  top=0pt,
  bottom=0pt,
  overlay={
    \node[
      anchor=north east,
      text width=\inwd,
      font=\footnotesize\ttfamily\color{blue!50!black},
      inner ysep=2mm,
      inner xsep=0pt,
      outer sep=0pt
      ] 
      at (frame.north west)
      {\stepcounter{ipythcntr}In [#1]:};
  },
  listing options={
    basicstyle=\footnotesize\ttfamily,
    language=python,
    escapechar=¢,
    showstringspaces=false,
    frame=none,
    backgroundcolor=\color{white!95!black},
    numbers=none,
    breaklines=true,
  },
}

And the code is:

\begin{ipythonnb}
import pynq
from pynq.lib import AxiGPIO
from pynq import Overlay
import time
import struct

overlay = Overlay("./bp_gpio.bit")
\end{ipythonnb}

The rendered pdf would look like this:
image

Anyway, hope if this could help someone.

Hello @godfly666 , thanks for the report!

The problem I see with this "original look" is the width. In a realy Jupyter environment you have the whole browser and the whole screen (normally very wide) to your disposition. That way, if you have long lines, you can make everything larger with no issue.

But in a book the width is a very important factor. Books are narrow. And you cannot adjust their size. And having wrapped lines is so ugly!

In that spirit, losing a lot of available width because the "In [1]: " it's a misfeature.

Thanks!

@hfwang132, this does look really neat! Have you found a way to integrate that into jupynotex? Would be amazing if the appearance could be optionally modified to look like that.

FTR, I'm ok to include code in Jupynotex that, optionally, render the output like this (the default would be as it is now). Patches welcomed! :)