fix: nix stuff and config

This commit is contained in:
2026-02-28 20:26:55 -07:00
parent 17e61aabc8
commit 6ef81a4a45
11 changed files with 304 additions and 37 deletions

View File

@@ -4,16 +4,32 @@
[spec-dict.main :refer [dict]]))
(s/def ::config
(s/keys :req [::ibm-plex-web]))
(s/keys :req [::ibm-plex-web
::latex
::dvisvgm]))
(s/def ::file
#(or (instance? java.io.File %)
(string? %)))
(def default
{::ibm-plex-web
(fs/file
(or (System/getenv "IBM_PLEX_WEB")
(some #(let [x (fs/path % "ibm-plex-web")]
(and (fs/exists? x) x))
(fs/split-paths (System/getenv "XDG_DATA_DIRS")))))})
(or (System/getenv "DOERG_IBM_PLEX_WEB")
(fs/file (some #(let [x (fs/path % "ibm-plex-web")]
(and (fs/exists? x) x))
(fs/split-paths (System/getenv "XDG_DATA_DIRS")))))
::latex "xelatex"
::dvisvgm "dvisvgm"
;; TODO: Can we automatically set this to "./doerg-tex/index.js" in
;; a development environment?
::doerg-tex "doerg-tex"})
(def ^:dynamic *cfg* default)
(s/def ::ibm-plex-web #(instance? java.io.File %))
(s/def ::ibm-plex-web ::file)
(s/def ::latex ::file)
(s/def ::dvisvgm ::file)
(s/def ::doerg-tex ::file)

View File

@@ -200,10 +200,7 @@
(deliver promise (hiccup/raw temml))))
(catch Exception e
(lr/error e)
(throw e))))
(when (fs/exists? "/tmp/doerg-svgs")
(fs/delete-tree "/tmp/doerg-svgs"))
(fs/copy-tree svg-dir "/tmp/doerg-svgs"))))
(throw e)))))))
fut (future-call (bound-fn* f))]
;; Time out after eight seconds. With all the LaTeX and IPC, there
;; are so many opportunities for things to go wrong </3.

View File

@@ -6,7 +6,8 @@
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as l]
[babashka.fs :as fs])
[babashka.fs :as fs]
[net.deertopia.doerg.config :as cfg])
(:import (java.io ByteArrayOutputStream)))
(def ^:private scale-divisor 66873.46948423679)
@@ -80,20 +81,21 @@
errors))))))
acc))))
(defn- invoke-latex [& {:keys [file output-dir latex]
:or {latex "xelatex"}}]
(invoke
{:dir output-dir}
latex "-no-pdf" "-interaction" "nonstopmode"
"-output-directory" output-dir file))
(defn- invoke-latex [& {:keys [file output-dir]}]
(let [latex (::cfg/latex cfg/*cfg*)]
(invoke
{:dir output-dir}
latex "-no-pdf" "-interaction" "nonstopmode"
"-output-directory" output-dir file)))
(defn- invoke-dvisvgm [& {:keys [file output-dir]}]
(invoke
{:dir output-dir}
"dvisvgm" "--page=1-" "--optimize" "--clipjoin"
"--relative" "--no-fonts" "-v3"
"--message=processing page {?pageno}: output written to {?svgpath}"
"--bbox=preview" "-o" "%9p.svg" file))
(let [dvisvgm (::cfg/dvisvgm cfg/*cfg*)]
(invoke
{:dir output-dir}
dvisvgm "--page=1-" "--optimize" "--clipjoin"
"--relative" "--no-fonts" "-v3"
"--message=processing page {?pageno}: output written to {?svgpath}"
"--bbox=preview" "-o" "%9p.svg" file)))
(defn- snippet-file-names
"Return a map of TeX snippets (as strings, including the math

View File

@@ -1,6 +1,7 @@
(ns net.deertopia.doerg.tex.temml
(:require [babashka.process :as p]
[net.deertopia.doerg.common :as common]
[net.deertopia.doerg.config :as cfg]
[clj-cbor.core :as cbor]
[clojure.java.io :as io]
[clojure.string :as str]
@@ -16,13 +17,13 @@
(def ^:dynamic *worker*)
(defn worker [& {:keys [preamble]}]
(p/process
{:shutdown p/destroy-tree
:err (l/log-stream :info "temml/err")}
#_"doerg-tex"
"./doerg-tex/index.js"
"--preamble"
"resources/net/deertopia/doerg/prelude.tex"))
(let [doerg-tex (::cfg/doerg-tex cfg/*cfg*)]
(p/process
{:shutdown p/destroy-tree
:err (l/log-stream :info "temml/err")}
doerg-tex
"--preamble"
"resources/net/deertopia/doerg/prelude.tex")))
(defn close-worker [tw]
(.close (:in tw)))