Compare commits
1 Commits
55d04707b7
...
fa42052a6a
| Author | SHA1 | Date | |
|---|---|---|---|
| fa42052a6a |
@@ -11,8 +11,8 @@
|
|||||||
[clojure.pprint]
|
[clojure.pprint]
|
||||||
#_
|
#_
|
||||||
[net.deertopia.doerg.tex :as tex]
|
[net.deertopia.doerg.tex :as tex]
|
||||||
[net.deertopia.doerg.tex.native :as tex]
|
[net.deertopia.doerg.tex.native :as tex-native]
|
||||||
[net.deertopia.doerg.tex.temml :as tex]
|
[net.deertopia.doerg.tex.temml :as tex-temml]
|
||||||
[clojure.zip :as z]
|
[clojure.zip :as z]
|
||||||
[babashka.fs :as fs]))
|
[babashka.fs :as fs]))
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
(defn org-document
|
(defn org-document
|
||||||
"Recursively render an Org-mode document to Hiccup."
|
"Recursively render an Org-mode document to Hiccup."
|
||||||
[doc]
|
[doc]
|
||||||
(tex/binding-temml-worker
|
(tex-temml/binding-worker
|
||||||
(let [rendered (-> doc gather-footnotes render-tex-snippets
|
(let [rendered (-> doc gather-footnotes render-tex-snippets
|
||||||
org-element-recursive)]
|
org-element-recursive)]
|
||||||
[:html
|
[:html
|
||||||
@@ -176,11 +176,11 @@
|
|||||||
(let [rendered-snippets
|
(let [rendered-snippets
|
||||||
(delay (->> @promises
|
(delay (->> @promises
|
||||||
(map #(-> % :node :value))
|
(map #(-> % :node :value))
|
||||||
(apply tex/render-xelatex svg-dir)))]
|
(apply tex-native/render svg-dir)))]
|
||||||
(doseq [{:keys [promise node]} @promises]
|
(doseq [{:keys [promise node]} @promises]
|
||||||
(try (let [{:keys [value]} node
|
(try (let [{:keys [value]} node
|
||||||
temml (tex/render-temml value)]
|
temml (tex-temml/render value)]
|
||||||
(if (tex/erroneous-temml-output? temml)
|
(if (tex-temml/erroneous-output? temml)
|
||||||
(let [tex (get @rendered-snippets value)]
|
(let [tex (get @rendered-snippets value)]
|
||||||
(if (:errors tex)
|
(if (:errors tex)
|
||||||
(deliver promise (hiccup/raw temml))
|
(deliver promise (hiccup/raw temml))
|
||||||
|
|||||||
@@ -43,8 +43,8 @@
|
|||||||
(-> r
|
(-> r
|
||||||
(assoc ::out out))))
|
(assoc ::out out))))
|
||||||
|
|
||||||
(defn- parse-tightpage [xelatex-out]
|
(defn- parse-tightpage [latex-out]
|
||||||
(->> (re-find tightpage-regexp xelatex-out)
|
(->> (re-find tightpage-regexp latex-out)
|
||||||
(drop 1)
|
(drop 1)
|
||||||
(map parse-long)))
|
(map parse-long)))
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
scale-divisor
|
scale-divisor
|
||||||
font-size)}))
|
font-size)}))
|
||||||
|
|
||||||
(defn- parse-output [out]
|
(defn- parse-latex-output [out]
|
||||||
(let [tightpage-info (parse-tightpage out)
|
(let [tightpage-info (parse-tightpage out)
|
||||||
m-start (re-matcher preview-start-regexp out)
|
m-start (re-matcher preview-start-regexp out)
|
||||||
m-end (re-matcher preview-end-regexp out)]
|
m-end (re-matcher preview-end-regexp out)]
|
||||||
@@ -80,10 +80,11 @@
|
|||||||
errors))))))
|
errors))))))
|
||||||
acc))))
|
acc))))
|
||||||
|
|
||||||
(defn- invoke-xelatex [& {:keys [file output-dir]}]
|
(defn- invoke-latex [& {:keys [file output-dir latex]
|
||||||
|
:or {latex "xelatex"}}]
|
||||||
(invoke
|
(invoke
|
||||||
{:dir output-dir}
|
{:dir output-dir}
|
||||||
"xelatex" "-no-pdf" "-interaction" "nonstopmode"
|
latex "-no-pdf" "-interaction" "nonstopmode"
|
||||||
"-output-directory" output-dir file))
|
"-output-directory" output-dir file))
|
||||||
|
|
||||||
(defn- invoke-dvisvgm [& {:keys [file output-dir]}]
|
(defn- invoke-dvisvgm [& {:keys [file output-dir]}]
|
||||||
@@ -112,25 +113,26 @@
|
|||||||
slurp
|
slurp
|
||||||
(str/replace-first "% {{contents}}" contents))))
|
(str/replace-first "% {{contents}}" contents))))
|
||||||
|
|
||||||
(defn render-xelatex
|
(defn render
|
||||||
"Render a collection of `snippets` to SVGs in `output-dir` using
|
"Render a collection of `snippets` to SVGs in `output-dir` using a
|
||||||
XeLaTeX and dvisvgm. Returns a map whose keys are `snippets` and
|
LaTeX engine (XeLaTeX at the moment) and dvisvgm. Returns a map
|
||||||
whose values are maps containing geometry info, a string of errors
|
whose keys are `snippets` and whose values are maps containing
|
||||||
output by XeLaTeX, and the path to the generated SVG file. Math
|
geometry info, a string of errors output by LaTeX, and the path to
|
||||||
delimiters are *not* implicitly added to each snippet."
|
the generated SVG file. Math delimiters are *not* implicitly added
|
||||||
|
to each snippet."
|
||||||
[output-dir & snippets]
|
[output-dir & snippets]
|
||||||
(fs/with-temp-dir [dir {:prefix "doerg-xelatex"}]
|
(fs/with-temp-dir [dir {:prefix "doerg-latex"}]
|
||||||
(let [preview-tex (fs/file dir "preview.tex")
|
(let [preview-tex (fs/file dir "preview.tex")
|
||||||
preview-xdv (fs/file dir "preview.xdv")
|
preview-xdv (fs/file dir "preview.xdv")
|
||||||
distinct-snippets (distinct snippets)]
|
distinct-snippets (distinct snippets)]
|
||||||
(fs/create-dirs output-dir)
|
(fs/create-dirs output-dir)
|
||||||
(->> (instantiate-preview-template distinct-snippets)
|
(->> (instantiate-preview-template distinct-snippets)
|
||||||
(spit preview-tex))
|
(spit preview-tex))
|
||||||
(let [dimensions (-> (invoke-xelatex :output-dir dir :file preview-tex)
|
(let [dimensions (-> (invoke-latex :output-dir dir :file preview-tex)
|
||||||
::out parse-xelatex-output)
|
::out parse-latex-output)
|
||||||
_ (invoke-dvisvgm :output-dir output-dir :file preview-xdv)]
|
_ (invoke-dvisvgm :output-dir output-dir :file preview-xdv)]
|
||||||
;; Adorn each snippet with dimensions and errors parsed from
|
;; Adorn each snippet with dimensions and errors parsed from
|
||||||
;; XeLaTeX's output, and the paths to SVG files generated by
|
;; LaTeX's output, and the paths to SVG files generated by
|
||||||
;; dvisvgm.
|
;; dvisvgm.
|
||||||
(assert (= (count distinct-snippets) (count dimensions)))
|
(assert (= (count distinct-snippets) (count dimensions)))
|
||||||
(->> (map (fn [ix snippet dimensions]
|
(->> (map (fn [ix snippet dimensions]
|
||||||
@@ -145,8 +147,8 @@
|
|||||||
(into {}))))))
|
(into {}))))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(render-xelatex "/tmp/doerg-tex-svgs"
|
(render "/tmp/doerg-tex-svgs"
|
||||||
"\\(c = \\sqrt{x^2 + y^2}\\)"
|
"\\(c = \\sqrt{x^2 + y^2}\\)"
|
||||||
"\\(x\\)" "\\(y\\)" "\\(x\\)"
|
"\\(x\\)" "\\(y\\)" "\\(x\\)"
|
||||||
"\\(\\undefinedcommandlol\\)"))
|
"\\(\\undefinedcommandlol\\)"))
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
(defn render-display [s]
|
(defn render-display [s]
|
||||||
(command-worker [s]))
|
(command-worker [s]))
|
||||||
|
|
||||||
(defn render-temml [s]
|
(defn render [s]
|
||||||
(if-let [[_ inner] (re-matches #"(?s)\\[(.*)\\]" s)]
|
(if-let [[_ inner] (re-matches #"(?s)\\[(.*)\\]" s)]
|
||||||
(render-display inner)
|
(render-display inner)
|
||||||
(if (re-matches #"(?s)\\begin\{.+?}(.*?)\\end\{.+?}" s)
|
(if (re-matches #"(?s)\\begin\{.+?}(.*?)\\end\{.+?}" s)
|
||||||
|
|||||||
Reference in New Issue
Block a user