Fork me on GitHub
#portal
<
2023-06-03
>
Sam Ritchie16:06:51

@djblue does a LaTeX viewer exist yet, using https://katex.org/ or mathjax?

djblue18:06:25

Not that I am aware of

djblue21:06:26

Is this something you are interested in building?

Sam Ritchie21:06:22

Yeah I’m going to give it a go and see if I can get something basic working

djblue21:06:17

Awesome! Let me know if you run into any issues 👍

Sam Ritchie22:06:58

This is close @djblue

(ns emmy.portal.tex
  (:require ["katex" :as k]
            [portal.ui.api :as p]))

(defn tex [text]
  [:span
   {:dangerouslySetInnerHTML
    {:__html
     (.renderToString katex text
                      #js {:throwOnError false
                           :displayMode true})}}])

(p/register-viewer!
 {:name :emmy.portal/tex
  :component tex
  :predicate (constantly true)})
and then load via
(-> (io/resource "emmy/portal/tex.cljs")
      (slurp)
      (p/eval-str))

awesome 2
djblue22:06:50

I think an issue you might run into is that strings don't support metadata :thinking_face:

Sam Ritchie22:06:58

that stops me from sending a default, but once this is working I can render Emmy expressions (which carry metadata) this way with the rpc call approach

💯 2
Sam Ritchie22:06:42

that works but weirdly keeps the original text in there too

djblue22:06:11

Any errors in the console?

Sam Ritchie22:06:05

I bet I’m missing some CSS like last time

👍 2
Sam Ritchie22:06:37

no errors, but the second form is katex-html and has that aria-hidden true flag

Sam Ritchie22:06:35

there we go, works with css

🚀 2
djblue22:06:39

I'm really happy the npm integration is just working awesome

Sam Ritchie22:06:23

it’s amazing

Sam Ritchie22:06:44

so either we require npm install katex here or inject the JS into the header

djblue22:06:53

Are you saying for downstream users?

Sam Ritchie22:06:53

Yeah that’s right

djblue22:06:22

Yeah, I think those two work for now 👍 I think in the future it might be cool if npm deps (only the modules your code needs) could be embedded into your jar :thinking_face: Users wouldn't need npm or be connected to the internet after the jar is downloaded

djblue22:06:09

That plus something like self-hosted cljs or cherryjs and most of Portal itself becomes an extension to some minimal bootstrap code to get everything kicked off

djblue22:06:36

For example here is Portal hosting (via sci) another completely unrelated project I did 😆

Sam Ritchie22:06:19

portal as a TeX REPL:

💯 16
2
awesome 4
🎉 2
2
Sam Ritchie22:06:02

@djblue one thing that WOULD be nice would be to be able to specify default viewers for some type like emmy.expression/Literal without having the instances having to carry around metadata. can I do that somehow? configure some list of predicate => default?

djblue22:06:43

Currently, the easiest place to do something like this is via a custom submit function. Does that type live on the jvm or js?

Sam Ritchie22:06:07

will custom submit cause problems for something like Clojure Notebooks?

djblue22:06:18

Yeah, this wouldn't work with clojure notebooks. However, I'm open to adding extension points, just not sure what they are yet.

Sam Ritchie22:06:22

I guess by “cause problems” I mean, is there a way to specify that clojure notebooks should use my custom submit function

Sam Ritchie22:06:06

I guess we want something like middleware on the JVM side

Sam Ritchie22:06:22

I’ve got to run for now but this was great, and so easy to add!!

👍 2