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!
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")}
prose defaults to :inline? true while cell results default to false
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!Agreed that it would be nice to render maps with clerk/tex values in them nicely by default.
we might find something, but I think the non-inline default is good for simple latex results
Even for values embedded inside maps?
no, I mean for simple values
I mean non-nested
Agreed
@andrea712 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.
can you try latest main as well? Will fix it next week if it’s still a problem there.
oh sorry I confused that with your GitHub issue, pretty sure this is a problem on main as well, no need to try
Not in front of a computer right now, will check the Github issue tonight or tomorrow on latest main!
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).nice!
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
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.