
I am looking for typesetting recommendations. I am writing a book, using Typst, that contains code from more than one programming language. In several places, it is useful to show the intermediate outputs that you would see on a REPL.
I like how Codly looks, but it doesn't have any support (that I know of) for formatting outputs from your code.
Here are some examples, in case I'm being unclear. IPython looks like this:
In [1]: data = {'Bob': 5, 'Sue': 7,
...: 'Tim': None}
In [2]: [data.get(x) for x in ['Bob', 'Sue', 'Tim', 'Hank']]
Out[2]: [5, 7, None, None]
Mathematica looks similar:
In[1]:= x := {10, 85, 50, 7, 52, 24, 56, 55, 2, 28}
In[2]:= Minimize[Total[(x - mu)^2], mu]
64869 369
Out[2]= {-----, {mu -> ---}}
10 10
JavaScript (in the Firefox console) uses a doubled >> with no numbering:
>> 5 + '5'
"55"
>> 5 * '5'
25
R similarly uses a single >:
> integrate(dnorm, -1, 1)
0.6826895 with absolute error < 7.6e-15
> integrate(dnorm, -Inf, +Inf)
1 with absolute error < 9.4e-05
I have not found much discussion of formatting REPL inputs and outputs on the Internet. This old Stack Overflow post shows a simple format that is similar to R but with inputs bolded. I like it, but I foresee some complexities:
- Lots of my inputs have multiple lines. IPython indents nicely with
.... - Mathematica's vertical centering is a nice touch for multi-line outputs.
- The reason I was using Codly was it has nice syntax highlighting, which can be useful to the reader.
- REPL numbering helps me refer to specific inputs in the prose, especially if I can continue numbering in a later code block, but Codly has some weird issues with
offset-from.
Any recommendations?