This commit is contained in:
@@ -127,6 +127,28 @@
|
|||||||
element/footnotes-section?]
|
element/footnotes-section?]
|
||||||
sp/NONE))))
|
sp/NONE))))
|
||||||
|
|
||||||
|
(defn- read-and-patch-generated-svg [{:keys [file height depth]}]
|
||||||
|
;; dvisvgm writes standalone SVG files, to which we need to make a
|
||||||
|
;; few changes to use them inline within our HTML.
|
||||||
|
;; • XML header: Bad syntax when embedded in an HTML doc. Remove
|
||||||
|
;; it.
|
||||||
|
;; • Width and height: We override these with our own values
|
||||||
|
;; computed by `net.deertopia.doerg.tex` to ensure correct
|
||||||
|
;; positioning relative to the surrounding text. More
|
||||||
|
;; accurately, we remove the height and width attributes from
|
||||||
|
;; the SVG tag, and set the new values for height and
|
||||||
|
;; vertical-align in the style attribute
|
||||||
|
;; • Viewbox: Must be removed entirely for correct positioning.
|
||||||
|
(-> (slurp file)
|
||||||
|
(str/replace-first "<?xml version='1.0' encoding='UTF-8'?>" "")
|
||||||
|
(str/replace-first #" height=['\"][^\"']+[\"']" "")
|
||||||
|
(str/replace-first #" width=['\"][^\"']+[\"']" "")
|
||||||
|
(str/replace-first
|
||||||
|
#"viewBox=['\"][^\"']+[\"']"
|
||||||
|
(format "style=\"%s\""
|
||||||
|
(format "height:%.4fem;vertical-align:%.4f;display:inline-block"
|
||||||
|
height (- depth))))))
|
||||||
|
|
||||||
(defn- render-tex-snippets [doc]
|
(defn- render-tex-snippets [doc]
|
||||||
(let [promises (atom [])
|
(let [promises (atom [])
|
||||||
r (->> doc (sp/transform
|
r (->> doc (sp/transform
|
||||||
@@ -148,11 +170,13 @@
|
|||||||
(try (let [{:keys [value contents]} node
|
(try (let [{:keys [value contents]} node
|
||||||
temml (tex/render-temml (or contents value))]
|
temml (tex/render-temml (or contents value))]
|
||||||
(if (tex/erroneous-temml-output? temml)
|
(if (tex/erroneous-temml-output? temml)
|
||||||
(let [{:keys [file]} (get @rendered-snippets value)]
|
(let [tex (get @rendered-snippets value)]
|
||||||
(deliver
|
(if (:errors tex)
|
||||||
promise
|
(deliver promise (hiccup/raw temml))
|
||||||
[:div.latex-fragment
|
(->> tex
|
||||||
(hiccup/raw (slurp file))]))
|
read-and-patch-generated-svg
|
||||||
|
hiccup/raw
|
||||||
|
(deliver promise))))
|
||||||
(deliver promise (hiccup/raw temml))))
|
(deliver promise (hiccup/raw temml))))
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(prn e)
|
(prn e)
|
||||||
|
|||||||
Reference in New Issue
Block a user