From b5a5721eed88e9813a7d609dab6d8e9be660a376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Sun, 22 Feb 2026 19:01:12 -0700 Subject: [PATCH] wip: xelatex --- doerg/doerg-tex/index.js | 2 +- .../resources/net/deertopia/doerg/prelude.tex | 1 + doerg/src/net/deertopia/doerg/common.clj | 16 +++++++++- doerg/src/net/deertopia/doerg/tex.clj | 31 +++++++++++++++++++ 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/doerg/doerg-tex/index.js b/doerg/doerg-tex/index.js index de97de9..ea6e854 100755 --- a/doerg/doerg-tex/index.js +++ b/doerg/doerg-tex/index.js @@ -34,7 +34,7 @@ function do_command (cmd) { return null } } catch (e) { - return e + return {type: "error", error: e} } } diff --git a/doerg/resources/net/deertopia/doerg/prelude.tex b/doerg/resources/net/deertopia/doerg/prelude.tex index a0cb5b4..37a3084 100644 --- a/doerg/resources/net/deertopia/doerg/prelude.tex +++ b/doerg/resources/net/deertopia/doerg/prelude.tex @@ -141,6 +141,7 @@ \newcommand{\definedto}{≔} \newcommand{\equivto}{\simeq} \newcommand{\homotopicto}{\sim} +\newcommand{\homotopyto}{\sim} \newcommand{\naturalto}{\Rightarrow} \newcommand{\isoto}{\cong} \newcommand{\monicto}{\rightarrowtail} diff --git a/doerg/src/net/deertopia/doerg/common.clj b/doerg/src/net/deertopia/doerg/common.clj index cc1b4eb..b058bbd 100644 --- a/doerg/src/net/deertopia/doerg/common.clj +++ b/doerg/src/net/deertopia/doerg/common.clj @@ -1,6 +1,7 @@ (ns net.deertopia.doerg.common (:require [babashka.process :as p] - [clojure.string :as str])) + [clojure.string :as str] + [clojure.tools.logging :as l])) (defn deref-with-timeout [process ms] (let [p (promise) @@ -16,3 +17,16 @@ {:process process :timed-out-after-milliseconds ms})) @p))) + +(defn invoke [opts & cmd] + (l/info (str/join " " (cons "$" cmd))) + (let [r (apply p/shell + (merge {:continue true + :in nil :out :string :err :string} + opts) + cmd) + bin (first cmd)] + (l/infof "%s (stdout): %s" bin (:out r)) + (l/infof "%s (stderr): %s" bin (:err r)) + (l/infof "%s exited with status %s" bin (str (:exit r))) + r)) diff --git a/doerg/src/net/deertopia/doerg/tex.clj b/doerg/src/net/deertopia/doerg/tex.clj index e7d854f..ca2caae 100644 --- a/doerg/src/net/deertopia/doerg/tex.clj +++ b/doerg/src/net/deertopia/doerg/tex.clj @@ -3,6 +3,37 @@ [net.deertopia.doerg.common :as common] [clj-cbor.core :as cbor] [clojure.java.io :as io])) + +;;; XeLaTeX + +(def scale-divisor 66873.46948423679) + +(def font-size 10) + +(defn- invoke-xelatex [& {:keys [file output-dir]}] + (let [{:keys [out]} (common/invoke + {:dir output-dir} + "xelatex" "-no-pdf" "-interaction" "nonstopmode" + "-output-directory" output-dir file) + [tp1 tp2 tp3 tp4] (->> (re-find tightpage-regexp out) + (drop 1) + (map parse-long))] + (->> (re-find-all preview-end-regexp out) + (map #(let [[d1 d2 d3] (map parse-long (drop 1 %)) + depth (/ (- d2 tp2) + scale-divisor + font-size)] + {:depth depth + :height (+ depth + (/ (+ d1 tp4) + tex-scale-divisor + tex-fontsize)) + :width (/ (+ d3 tp3 (- tp2)) + tex-scale-divisor + tex-fontsize)}))))) + + +;;; Temml (def ^:dynamic *tex-worker-timeout-duration* "Number of milliseconds to wait before killing the external Uniorg