Compare commits

..

17 Commits

Author SHA1 Message Date
26410655d9 fix: tikz svgs
All checks were successful
build / build (push) Successful in 43s
Fixes #9
2026-03-05 15:09:37 -07:00
faa84f986d doc: doerg-temml-worker
All checks were successful
build / build (push) Successful in 1m24s
2026-03-05 11:47:59 -07:00
9ec8bca383 feat: warning message on timeout
All checks were successful
build / build (push) Successful in 40s
2026-03-05 09:52:29 -07:00
d946c57bff Merge pull request 'fix: namespace error lol' (#8) from ns-error into main
All checks were successful
build / build (push) Successful in 4s
Reviewed-on: #8
2026-03-05 09:49:24 -07:00
7c4ad64d58 fix: increase snippet timeout to 20s
All checks were successful
build / build (push) Successful in 5s
2026-03-05 09:49:04 -07:00
56742cf72d fix: namespace error lol
Some checks failed
build / build (push) Failing after 1m1s
2026-03-05 09:36:49 -07:00
a92b387e63 refactor: more.
Some checks failed
build / build (push) Failing after 3h13m17s
2026-03-02 15:18:35 -07:00
98c106b3cf fix: trim temml/render input 2026-03-02 15:17:57 -07:00
b336aa873e refactor: more cleanup >_<
Some checks failed
build / build (push) Has been cancelled
2026-03-02 14:59:11 -07:00
e49f847f20 refactor: move texslop into tex module
Some checks failed
build / build (push) Has been cancelled
2026-03-02 14:53:07 -07:00
ec4ad7c9c2 fix: set doerg-parser in config 2026-03-02 14:12:52 -07:00
762324d9f0 fix: config spec 2026-03-02 14:06:50 -07:00
c97b7ab0dc chore: clean doerg sources
All checks were successful
build / build (push) Successful in 5s
2026-03-01 12:18:14 -07:00
c45852097b chore: package.nix → default.nix
All checks were successful
build / build (push) Successful in 5s
2026-03-01 12:08:21 -07:00
74e48264ea chore: clean up serialise
Some checks failed
build / build (push) Has been cancelled
2026-03-01 11:56:06 -07:00
283c18fd9e chore: remove demo action
All checks were successful
build / build (push) Successful in 4s
2026-03-01 11:52:58 -07:00
570fca833d Merge pull request 'tex' (#7) from tex into main
All checks were successful
build / build (push) Successful in 4s
Gitea Actions Demo / build (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1s
Reviewed-on: #7
2026-03-01 11:50:07 -07:00
21 changed files with 219 additions and 135 deletions

View File

@@ -1,26 +0,0 @@
name: Gitea Actions Demo
run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀
on: [push]
jobs:
build:
runs-on: nixos
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: build doerg
run: nix build -L .#doerg
Explore-Gitea-Actions:
runs-on: nixos
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!"
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."

View File

@@ -7,7 +7,6 @@
, fake-git
, our-tex ? callPackage ./our-tex.nix {}
, makeWrapper
, breakpointHook
}:
let
@@ -16,9 +15,9 @@ let
mkCljBin' = args: (mkCljBin args).overrideAttrs (final: prev: {
nativeBuildInputs =
builtins.filter
# A possibly-sketchy predicate, lol.
(x: x != fake-git)
prev.nativeBuildInputs;
# A possibly-sketchy predicate, lol.
(x: x != fake-git)
prev.nativeBuildInputs;
});
plex = ibm-plex-web.override {
@@ -32,13 +31,12 @@ let
in mkCljBin' {
name = "net.deertopia/doerg";
version = "0.1.0";
projectSrc = ./.;
projectSrc = lib.cleanSource ./.;
lockfile = ../deps-lock.json;
main-ns = "net.deertopia.doerg.main";
nativeBuildInputs = [
plex
makeWrapper
breakpointHook
];
buildInputs = [
doerg-parser

0
doerg/doerg-parser/index.js Normal file → Executable file
View File

View File

@@ -1,11 +1,17 @@
{
"name": "doerg-parser",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "doerg-parser",
"version": "0.1.0",
"dependencies": {
"uniorg-parse": "^3.2.0"
},
"bin": {
"doerg-parser": "index.js"
}
},
"node_modules/@types/unist": {

View File

@@ -1 +1,12 @@
#+title: doerg-temml-worker
This is a tiny Node script that is used by doerg. For each CBOR-encoded value on stdin (a "command"), a response value is spit to stdout.
Currently, the following commands are supported:
- Any string: Return the Temml-rendered MathML code as a string (inline).
- An array with a single string element: Return the Temml-rendered MathML code as a string (display).
If something goes wrong, either of these commands may return an object of form
#+begin_src json
{"type": "error"
,"error": «error object»}
#+end_src

View File

@@ -8,7 +8,13 @@
buildNpmPackage {
pname = "doerg-temml-worker";
version = "0.1.0";
src = ./.;
src =
builtins.filterSource
(name: _file-type: ! builtins.elem name [
"deserialise.clj" "deps.edn" "default.nix"
"README.org" "serialise.clj" "node_modules"
])
./.;
npmDeps = importNpmLock { npmRoot = ./.; };
npmConfigHook = importNpmLock.npmConfigHook;
dontNpmBuild = true;

View File

@@ -3,4 +3,4 @@
com.rpl/specter {:mvn/version "1.1.6"}
mvxcvi/clj-cbor {:mvn/version "1.1.1"}
babashka/process {:mvn/version "0.6.25"}}
:paths ["." "classes"]}
:paths ["."]}

View File

@@ -1,4 +1,6 @@
(ns deserialise
"A toy script for conveniently interfacing with doerg-temml-worker
during development."
(:require [clj-cbor.core :as cbor]
[clojure.string :as str]))

View File

@@ -1,11 +1,11 @@
{
"name": "doerg-tex",
"name": "doerg-temml-worker",
"version": "0.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "doerg-tex",
"name": "doerg-temml-worker",
"version": "0.1.0",
"dependencies": {
"cbor-x": "^1.6.0",
@@ -13,7 +13,7 @@
"temml": "^0.13.1"
},
"bin": {
"doerg-tex": "index.js"
"doerg-temml-worker": "index.js"
}
},
"node_modules/@cbor-extract/cbor-extract-darwin-arm64": {

View File

@@ -1,4 +1,6 @@
(ns serialise
"A toy script for conveniently interfacing with doerg-temml-worker
during development."
(:require [clj-cbor.core :as cbor]
[clojure.string :as str]))
@@ -8,12 +10,4 @@
(defn c [x]
(->> x cbor/encode (map #(format "%02x" %)) (str/join " ")))
#_
(w "\\naturalto")
(w "\\ifxetex blah \\fi")
#_#_#_
(w "c = \\sqrt{a^2 + y^2}")
(w "c = \\sqrt{a^ + y^2")
(w "\\alpha^\\beta")

View File

@@ -39,5 +39,6 @@ texlive.combine {
collection-fontsrecommended # Essential fonts.
etoolbox # For Org-mode exports.
caption
standalone
;
}

View File

@@ -1,11 +1,56 @@
\documentclass{article}
\usepackage{amsmath}
\documentclass[tikz,dvisvgm]{standalone}
\usepackage[active,tightpage,auctex,dvips]{preview}
\usepackage{fontspec}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ifxetex}
\usepackage{syd-plex}
\usepackage{quiver}
\usepackage{tikz}
\usepackage{amscd}
\newcommand{\catname}[1]{\textbf{#1}}
\newcommand{\C}[1]{\catname{#1}}
% Specific categories
\newcommand{\Set}{\catname{Set}}
\newcommand{\Cat}{\catname{Cat}}
\newcommand{\CAT}{\catname{CAT}}
\newcommand{\Grp}{\catname{Grp}}
% Common objects and functions
\newcommand{\Ob}{\operatorname{Ob}}
\newcommand{\op}{\text{op}}
\newcommand{\opof}[1]{{#1}^{\text{op}}}
% \id{x} is the identity morphism on x.
\newcommand{\id}[1]{1_{#1}}
% \Id{C} is the identity functor on C.
\newcommand{\Id}[1]{1_{#1}}
\newcommand{\Mor}{\operatorname{Mor}}
\newcommand{\homset}[3]{{{#1} \left[ {#2} \to {#3} \right]}}
% Constructions of categories.
\newcommand{\FunctorCategory}[2]{\left[#1, #2\right]}
\newcommand{\Funct}[2]{\FunctorCategory{#1}{#2}} % Deprecated.
\newcommand{\ArrowCategory}[1]{{#1}^\to}
% Semantic aliases
\newcommand{\monicto}{\rightarrowtail}
\newcommand{\epicto}{\twoheadrightarrow}
\newcommand{\naturalto}{\Rightarrow}
\newcommand{\isoto}{\cong}
\newcommand{\equivto}{\simeq}
\newcommand{\naturaltrans}[2]{#1 \naturalto #2} % Deprecated.
\newcommand{\horizontalcompose}{\ast}
% Optics
\newcommand{\opticname}[1]{\textbf{#1}}
\newcommand{\optic}[3]{\opticname{#1}^\prime\;#2\;#3}
\newcommand{\Optic}[5]{\opticname{#1}\;#2\;#3\;#4\;#5}
\begin{document}
\setlength\abovedisplayskip{0pt}
\setlength\abovedisplayskip{0pt} % Remove padding before equation environments.
%% \color[rgb]{0.000,0.000,0.004}\special{dvisvgm:currentcolor on}\setcounter{equation}{0}%
% {{contents}}
\end{document}

View File

@@ -6,30 +6,38 @@
(s/def ::config
(s/keys :req [::ibm-plex-web
::latex
::dvisvgm]))
::dvisvgm
::doerg-temml-worker
::doerg-parser]))
(s/def ::file
#(or (instance? java.io.File %)
(string? %)))
(s/def ::executable #(or (fs/executable? %)
(and (fs/relative? %)
(fs/which %))))
(def default
{::ibm-plex-web
(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")))))
(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-temml-worker/index.js" in
;; a development environment?
::doerg-temml-worker "doerg-temml-worker"})
::doerg-temml-worker "doerg-temml-worker"
::doerg-parser "doerg-parser"})
(def ^:dynamic *cfg* default)
(s/def ::ibm-plex-web ::file)
(s/def ::latex ::file)
(s/def ::latex ::executable)
(s/def ::dvisvgm ::file)
(s/def ::dvisvgm ::executable)
(s/def ::doerg-temml-worker ::file)
(s/def ::doerg-temml-worker ::executable)
(s/def ::doerg-parser ::executable)

View File

@@ -29,7 +29,7 @@
:or {in *in*}}]
(let [r (-> (p/process
{:in in :out :string}
"doerg-parser")
(::cfg/doerg-parser cfg/*cfg*))
(common/deref-with-timeout *uniorg-timeout-duration*))]
(if (zero? (:exit r))
(-> r :out (json/parse-string (comp keyword camel->kebab))))))

View File

@@ -9,9 +9,9 @@
[net.deertopia.doerg.html :as doerg-html]
[hiccup2.core :as hiccup]
[clojure.pprint]
#_
;; #_
[net.deertopia.doerg.tex :as tex]
[net.deertopia.doerg.tex.native :as tex-native]
;; [net.deertopia.doerg.tex.native :as tex-native]
[net.deertopia.doerg.tex.temml :as tex-temml]
[clojure.zip :as z]
[babashka.fs :as fs]))
@@ -143,78 +143,38 @@
#(element/of-keyword-type? % "LATEX_HEADER")
(sp/view :value)])))
(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'\?>\n?" "")
(str/replace-first #" height=['\"][^\"']+[\"']" "")
(str/replace-first #" width=['\"][^\"']+[\"']" "")
(str/replace-first
#"viewBox=['\"][^\"']+[\"']"
(fn [s]
(format "%s style=\"%s\""
s
(format "height:%.4fem;vertical-align:%.4fem;display:inline-block"
height (- depth)))))))
(defn- timeout-snippet-promises [snippet-promises fut]
;; Time out after twenty seconds. With all the LaTeX and IPC, there
;; are so many opportunities for things to go wrong </3.
(let [ms (* 20 1000)
fut-res (deref fut ms ::timed-out)]
(if (= fut-res ::timed-out)
(do (l/warnf "Giving up on rendering TeX snippets after %.3f seconds."
(/ ms 1000))
(future-cancel fut)
(doseq [[_snippet p] snippet-promises]
(deliver p ::timed-out)))
fut-res)))
(defn render-tex-snippets
"Traverse doc, adorning each LaTeX node with a promise resolving to,
optimistically, Hiccup-rendered SVG or MathML code."
[doc]
(let [promises (atom [])
(let [snippet-promises (atom [])
r (->> doc (sp/transform
[element/postorder-walker
#(element/of-type?
% "latex-fragment" "latex-environment")]
(fn [node]
(let [p (promise)]
(swap! promises #(conj % {:promise p :node node}))
(swap! snippet-promises #(conj % [(:value node) p]))
(assoc node ::rendered p)))))
f (fn []
(fs/with-temp-dir [svg-dir {:prefix "doerg-svg"}]
(let [rendered-snippets
(delay (->> @promises
(map #(-> % :node :value))
(apply tex-native/render svg-dir)))]
(doseq [{:keys [promise node]} @promises]
(try (let [{:keys [value]} node
temml (tex-temml/render value)]
(if (tex-temml/erroneous-output? temml)
(let [tex (get @rendered-snippets value)]
(if (:errors tex)
(deliver promise (hiccup/raw temml))
(->> tex
read-and-patch-generated-svg
hiccup/raw
(deliver promise))))
(deliver promise (hiccup/raw temml))))
(catch Exception e
(lr/error e)
(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.
(let [fut-res (deref fut (* 10 1000) ::timed-out)]
(if (= fut-res ::timed-out)
(do (future-cancel fut)
(doseq [{:keys [promise]} @promises]
(deliver promise ::timed-out)))
fut-res))
sp @snippet-promises
fut (-> #(tex/render-snippets sp)
bound-fn* future-call)]
(timeout-snippet-promises sp fut)
r))
(comment
(render-tex-snippets doc))
(defn- render-pprint

View File

@@ -14,16 +14,26 @@
"/home/msyds/org/20250919114912-homepage.org"
#_
"/home/msyds/org/20251111182118-path_induction.org"
#_
;; #_
"/home/msyds/org/20250512144715-natural_transformation_category_theory.org"
#_
"/home/msyds/org/20251021155921-path_action.org"
"test/net/deertopia/doerg/render_test/fallbacks.org")
#_
"test/net/deertopia/doerg/render_test/fallbacks.org"
#_
"/home/msyds/org/20250910115311-men_who_would_make_stunning_dykes.org")
(defn- force-create-sym-link [path target]
(fs/delete-if-exists path)
(fs/create-sym-link path target))
(defn reconfigure-doerg! []
(alter-var-root
#'cfg/*cfg*
#(assoc %
::cfg/doerg-temml-worker "./doerg-temml-worker/index.js"
::cfg/doerg-parser "./doerg-parser/index.js")))
(defn render-html [& {:keys [src dest]
:or {src some-org-file
dest "/tmp/doerg-test"}}]

View File

@@ -1,4 +1,71 @@
(ns net.deertopia.doerg.tex
(:require [net.deertopia.doerg.tex.native :as native]
[net.deertopia.doerg.tex.temml :as temml]
[babashka.fs :as fs]))
[babashka.fs :as fs]
[clojure.string :as str]
[hiccup2.core :as hiccup]
[clojure.tools.logging :as l]
[clojure.tools.logging.readable :as lr]))
(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'\?>\n?" "")
(str/replace-first #" height=['\"][^\"']+[\"']" "")
(str/replace-first #" width=['\"][^\"']+[\"']" "")
(str/replace-first
#"viewBox=['\"][^\"']+[\"']"
(fn [s]
(format "%s style=\"%s\""
s
(format "height:%.4fem;vertical-align:%.4fem;display:inline-block"
height (- depth)))))
;; Stupid hack. --currentcolor on dvisvgm should be enough, but
;; it doesn't get e.g. TikZ arrows.
(str/replace #"stroke=['\"]#000['\"]" "stroke=\"currentColor\"")))
(def ^:dynamic *save-snippets?* false)
(defn render-snippets [snippet-promises]
(with-redefs [fs/delete-tree
(fn
([path]
(l/warnf "refusing to delete %s" path))
([path opts]
(lr/warnf "refusing to delete %s with opts %s"
path opts)))]
(fs/with-temp-dir [svg-dir {:prefix "doerg-svg-"}]
(let [rendered-snippets
(delay (->> snippet-promises
(map first)
(apply native/render svg-dir)))]
(doseq [[snippet p] snippet-promises]
(try (let [temml (temml/render snippet)]
(->> (if (temml/erroneous-output? temml)
(let [tex (get @rendered-snippets snippet)]
(if (:errors tex)
temml
(read-and-patch-generated-svg tex)))
temml)
hiccup/raw (deliver p)))
(catch Exception e
(l/error e "Error in TeX thread")
(throw e))))))))
(comment
(let [snippets (for [x ["\\(\\ifxetex blah \\fi\\)"
"\\(\\sqrt{x^2 + y^2}\\)"]]
[x (promise)])]
(temml/binding-worker
(render-snippets snippets)
(map #(-> % second deref) snippets))))

View File

@@ -93,7 +93,7 @@
(invoke
{:dir output-dir}
dvisvgm "--page=1-" "--optimize" "--clipjoin"
"--relative" "--no-fonts" "-v3"
"--relative" "--no-fonts" "-v3" "--currentcolor"
"--message=processing page {?pageno}: output written to {?svgpath}"
"--bbox=preview" "-o" "%9p.svg" file)))

View File

@@ -55,13 +55,18 @@
(command-worker [s]))
(defn render [s]
(if-let [[_ inner] (re-matches #"(?s)\\[(.*)\\]" s)]
(render-display inner)
(if (re-matches #"(?s)\\begin\{.+?}(.*?)\\end\{.+?}" s)
(render-display s)
(if-let [[_ inner] (re-matches #"(?s)\\\((.*)\\\)" s)]
(render-inline inner)
(throw (ex-info "weird" {:snippet s}))))))
(let [s (str/trim s)]
(if-let [[_ inner] (re-matches #"(?s)\\\[(.*)\\]" s)]
(render-display inner)
(if (re-matches #"(?s)\\begin\{.+?}(.*?)\\end\{.+?}" s)
(render-display s)
(if-let [[_ inner] (re-matches #"(?s)\\\((.*)\\\)" s)]
(render-inline inner)
(throw (IllegalArgumentException.
(ex-info
(str "`net.deertopia.doerg.tex.temml` argument should"
" be enclosed in math delimiters.")
{:arg s}))))))))
;; hackky....
(defn erroneous-output? [s]

View File

@@ -41,8 +41,8 @@
vendored = final.callPackage ./vendor {};
in {
inherit (vendored) ibm-plex-web;
publisher = final.callPackage ./publisher/package.nix {};
doerg = final.callPackage ./doerg/package.nix {};
publisher = final.callPackage ./publisher {};
doerg = final.callPackage ./doerg {};
doerg-parser = final.callPackage ./doerg/doerg-parser {};
doerg-temml-worker = final.callPackage ./doerg/doerg-temml-worker {};
};
@@ -65,9 +65,6 @@
clojure-lsp
doerg-parser
doerg-temml-worker
# wahhh ibm-plex-web is a dependency of doerg... why must
# i specify it hereeee.
# ibm-plex-web
zprint
clojure
babashka