Fork me on GitHub
#clerk
<
2024-01-07
>
teodorlu15:01:13

Good afternoon! Is there a way to display TeX math with Clerk in the object browser, but not force newlines? When I’m using clerk/tex for values in a map, I can’t get rid of the newlines. (Example image below, https://github.clerk.garden/teodorlu/lab/commit/5b54a0fa3e85c0ab71d2fa81d13c8acb1dad6946/src/repro/tex_newlines/). It appears the markdown viewer (`nextjournal.clerk/md`) is able to display math inline (for example Assume $x = 3$, then …. But I want the rest of the object browser too, not flat Markdown paragraphs!

👀 1
mkvlr16:01:31

can you try latest main as well? Will fix it next week if it’s still a problem there.

mkvlr16:01:34

oh sorry I confused that with your GitHub issue, pretty sure this is a problem on main as well, no need to try

👀 1
teodorlu16:01:51

Not in front of a computer right now, will check the Github issue tonight or tomorrow on latest main!

🙏 1
teodorlu19:01:38

can you try latest main as well? Will fix it next week if it’s still a problem there.I’m seeing the same behavior on io.github.nextjournal/clerk {:git/sha "65988e062c8e9dc5e48111d05fec5350cf80e4c9"} (latest as of today).

mkvlr19:01:43

thanks @U3X7174KS, we’ll look into it

👍 1
Andrea17:01:35

katex display mode can actually be controlled via render options like this:

(ns scratch.debug
  (:require [nextjournal.clerk :as clerk]
            [nextjournal.clerk.viewer :as viewer]))

^{::clerk/visibility {:result :hide}}
(clerk/add-viewers! [(update viewer/katex-viewer
                            :transform-fn comp (fn [wv] (-> wv (assoc-in [:nextjournal/render-opts :inline?] true))))])

{:a (clerk/tex "\\phi") :b (clerk/tex "\\psi")}

Andrea17:01:59

prose defaults to :inline? true while cell results default to false

mkvlr17:01:21

ideally things should look correctly by default

1
teodorlu17:01:44

oooh, awesome. Looks like I just want to rewrite my viewer to use this directly. In the example, I used clerk/tex directly. In my non-simplified code, I have my own viewer:

(def with-unit-viewer
  {:name `with-unit-viewer
   :pred with-unit?
   :transform-fn (clerk/update-val (fn [unit] (clerk/tex (with-unit->tex unit))))})

(clerk/add-viewers! [with-unit-viewer])
I think I can probably just configure my viewer correctly. Thank you!

teodorlu17:01:11

Agreed that it would be nice to render maps with clerk/tex values in them nicely by default.

Andrea17:01:57

we might find something, but I think the non-inline default is good for simple latex results

teodorlu17:01:28

Even for values embedded inside maps?

Andrea17:01:55

no, I mean for simple values

Andrea17:01:07

I mean non-nested

teodorlu21:01:50

@U9EQP1K0X thanks again for the inline viewer example. My maps look way better now! Viewing doubles still has a way to go, but that’s entirely my fault for shoving a double .toString into LaTeX.

Andrea09:01:15

the thing with inline settings is that katex renders stuff differently when expressions are meant for https://katex.org/docs/options or not, this affects how sub/super scripts and symbols in general like \sum or \int are drawn, and not only alignment

teodorlu09:01:08

Aaah, right, just like in plain LaTeX. So my “inline all the things” solution might not be ideal — perhaps it be better if the viewer knows about the context it renders in before rendering.

Andrea10:01:21

yeah, just like latex

👍 1