Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TeX rendering prototype [in progress] #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{:paths ["src" "resources"]
:deps
{org.clojure/data.json {:mvn/version "2.4.0"}
org.mentat/emmy {:mvn/version "0.31.0"}
org.mentat/emmy
#_{:mvn/version "0.31.0"}
{:local/root "../emmy"}
org.mentat/jsxgraph.cljs {:mvn/version "0.2.1"}
org.mentat/leva.cljs {:mvn/version "0.3.0"}
org.mentat/mathbox.cljs {:mvn/version "0.2.2"}
Expand All @@ -16,7 +18,7 @@
{org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
io.github.nextjournal/cas-client
{:git/sha "84ab35c3321c1e51a589fddbeee058aecd055bf8"}
{:git/sha "22ef8360689cd3938e43a3223023ab1b9711818f"}
io.github.nextjournal/clerk
{:git/sha "d80187013d7b7b96db3d8b114b8d99f687170668"}

Expand Down
2 changes: 1 addition & 1 deletion dev/examples/mafs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@

(let [f ((expt D 3) tanh)]
(clerk/col
(->tex (f 'x))
(->TeX (f 'x))
(mafs/mafs {:zoom {:min 0.1 :max 2}}
(mafs/cartesian)
(mafs/of-x f {:color :blue}))))
Expand Down
11 changes: 9 additions & 2 deletions dev/examples/power_series.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
^{:nextjournal.clerk/visibility {:code :hide}}
(ns examples.power-series
{:nextjournal.clerk/toc true})
{:nextjournal.clerk/toc true}
(:require [emmy.env :refer :all]
[emmy.clerk :as ec]))

;; ## Power Series
;; ## TeX Rendering

^{:nextjournal.clerk/visibility {:code :hide :result :hide}}
(ec/install!)

(->TeX (sin 'x))
3 changes: 3 additions & 0 deletions dev/examples/simulation/ellipsoid.clj
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@
:state->xyz
(ev/with-params {:atom !opts :params [:a :b :c]}
e->r)}))))


;; https://2.maria.cloud/gist/1b981499d785c4291ba83f8f7006ca35
1 change: 0 additions & 1 deletion dev/examples/simulation/phase_portrait.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
{::clerk/width :wide}

;; potential energy term:

(defn T [m l]
(fn [[_ _ thetadot]]
(* 1/2 m (square (* l thetadot)))))
Expand Down
2 changes: 1 addition & 1 deletion dev/examples/vega/pendulum.clj
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
false
(first xs)
{:calling-convention :structure})
pv (principal-value Math/PI)]
pv (principal-value Math/PI)]
(map (fn [[t [theta1 theta2] [thetadot1 thetadot2] :as state]]
(let [[x1 y1 x2 y2] (xform state)]
{:t t
Expand Down
13 changes: 10 additions & 3 deletions src/emmy/clerk.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
(:require [clojure.walk :refer [postwalk]]
[emmy.env :as e]
[emmy.expression :as x]
[emmy.expression.render :as render]
[emmy.viewer :as ev]
#?(:clj [emmy.viewer.css :as vc])
#?(:clj [mentat.clerk-utils.build :as b])
Expand Down Expand Up @@ -164,8 +165,8 @@
renders the original input."
[expr & {:keys [simplify?]}]
(let [expr (if simplify?
expr
(e/simplify expr))]
(e/simplify expr)
expr)]
(viewer/tex (e/->TeX expr))))

(def literal-viewer
Expand All @@ -178,6 +179,12 @@
:transform-fn
(viewer/update-val x/expression-of)})

(def tex-viewer
{:name `tex-viewer
:pred render/tex?
:transform-fn (viewer/update-val
#(viewer/tex (.-s %)))})

#?(:clj (alter-var-root #'ev/reagent-viewer (constantly reagent-viewer))
:cljs (set! ev/reagent-viewer reagent-viewer))

Expand All @@ -188,7 +195,7 @@
[[install!]] is required for any Mafs, MathBox etc code to render correctly."
[& viewers]
(let [high-priority [meta-viewer]
low-priority [literal-viewer]]
low-priority [literal-viewer tex-viewer]]
(viewer/add-viewers!
(into high-priority
(concat viewers low-priority)))))
Expand Down
Loading