2

Is it possible, when using IHaskell, to have all the output automatically processed by Latex, or understood as Markdown ?

Perhaps this will involve (at least if I want it to work with data of type MyType) using import IHaskell.Display and instance IHaskellDisplay MyType where... but I don't know how to make this work!

Thanks!

edit Someone asked for an example, so what I have in mind is: every string of output (for every output is a string, ultimately...) is processed as latex code (or markdown). If a function returns, say, an integer, the result will be barely visible, but if a function returns the string $\mathbb{Z}$ then what appears on the screen is

$\mathbb{Z}$

[alert ! I thought we had latex formulae on stackoverflow, just like we do in mathoverflow, but if we don't, you need your imagination here!...]

Ultimately i imagine I would have a class Latexable a where showlatex :: a -> String and I would implement showlatex for some types.

Well, I'm happy with various partial solutions, allowing me to have some formulae typeset directly in the notebook, it doesn't really matter whether all output is processed...

Pierre
  • 233
  • 1
  • 7
  • https://github.com/gibiansky/IHaskell/issues/828 may be relevant. But, what do you mean by “have all the output automatically processed by LaTeX? Please give some examples of the kind of output you mean and how you'd like it to be rendered. – leftaroundabout Aug 30 '18 at 14:33
  • Ok, why not just make it `class Latexable a where showlatex :: a -> LaTeX`? Using a string for this – but then expecting IHaskell to interpret it as LaTeX – seems rather strange... — “For every output is a string, ultimately” ← no it isn't, why would you think so? – leftaroundabout Aug 30 '18 at 15:25
  • the output cells in the notebook are ASCII text. (Well, you can arrange for the notebook to display images, but let's ignore that.) Likewise, using ghci in a terminal, its prints ASCII characters. That's what I mean by "the output is always a string", I meant "the output is a text in ASCII". I would like this ASCII text to be processed by Latex (or to be understood as Markdown.) By the way, when you run Sagemath in a Jupyter Notebook, you get this behaviour exactly by using `%display typeset` – Pierre Aug 30 '18 at 16:01
  • In GHCi it is a string, yes, but IMO it's the main selling point of Jupyter that you're not limited to text but can have all that other stuff. Now in Python of course, you don't tend to rely on the type system to distinguish between different... _types_. of output, but in Haskell that's very much the natural thing to do. – leftaroundabout Aug 30 '18 at 16:04
  • I see what you mean, OK. But anyway, I'm looking for an easy way to call Latex from the notebook. Oh and I'm happy even with quick-and-dirty solutions, such as a way of quickly copying the output to the clipboard (then I can paste in a markdown cell, better than nothing -- having to use CTRL-C manually is VERY slow, on the other hand) – Pierre Aug 30 '18 at 16:14
  • Well, for Quick&Dirty, just wrap your results in [`LaTeX.raw`](http://hackage.haskell.org/package/HaTeX-3.19.0.0/docs/Text-LaTeX-Base-Commands.html#v:raw), or rather [`raw . Text.pack`](http://hackage.haskell.org/package/text-1.2.3.0/docs/Data-Text.html#v:pack). – leftaroundabout Aug 30 '18 at 16:16

1 Answers1

2

Here's a partial answer to my own question.

import IHaskell.Display (latex)

Then if you try, say

latex "$x+y$"

it works!

It remains to find a mechanism so that latex is automatically called in certain situations, so the question remains open. But in most cases, I'm good.

Pierre
  • 233
  • 1
  • 7