From 790ce7e01f9d8fc86647424516b5dcb3a8be5cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Tue, 24 Feb 2026 10:43:43 -0700 Subject: [PATCH] --- doerg/src/net/deertopia/doerg/common.clj | 9 ++--- doerg/src/net/deertopia/doerg/tex.clj | 49 +++++++++++++++++++----- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/doerg/src/net/deertopia/doerg/common.clj b/doerg/src/net/deertopia/doerg/common.clj index ed5ed93..8cbdc1c 100644 --- a/doerg/src/net/deertopia/doerg/common.clj +++ b/doerg/src/net/deertopia/doerg/common.clj @@ -110,9 +110,9 @@ (comment (let [out (ByteArrayOutputStream.)] (p/shell {:out (tee-output-stream - out - (l/log-stream :info "blah"))} - "echo" "hello" "worms"))) + out (l/log-stream :info "blah"))} + "echo" "hello\n" "worms") + (.toString out))) (defn invoke [opts & cmd] (l/info (str/join " " (cons "$" cmd))) @@ -122,7 +122,4 @@ 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 00ebacb..b25ddb1 100644 --- a/doerg/src/net/deertopia/doerg/tex.clj +++ b/doerg/src/net/deertopia/doerg/tex.clj @@ -2,7 +2,10 @@ (:require [babashka.process :as p] [net.deertopia.doerg.common :as common] [clj-cbor.core :as cbor] - [clojure.java.io :as io])) + [clojure.java.io :as io] + [clojure.string :as str] + [clojure.tools.logging :as l]) + (:import (java.io ByteArrayOutputStream))) ;;; XeLaTeX @@ -13,15 +16,41 @@ (def ^:private tightpage-regexp #"^Preview: Tightpage (-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)") +(def ^:private preview-end-regexp + #"(?:^Preview: Tightpage.*$)?\n! Preview: Snippet \d+ ended.\((\d+)\+(\d+)x(\d+)\)") + +(defn- invoke [extra-opts & args] + (let [namespace (or (::ns extra-opts) + (first args)) + out-stream (common/tee-output-stream + (ByteArrayOutputStream.) + (l/log-stream :info (str namespace "/out"))) + err-stream (common/tee-output-stream + (ByteArrayOutputStream.) + (l/log-stream :info (str namespace "/err"))) + opts (merge extra-opts + {:out out-stream :err err-stream :continue true + :shutdown p/destroy-tree + :pre-start-fn (fn [{:keys [cmd]}] + (l/infof "$ %s" + (str/join " " cmd))) + :exit-fn (fn [{:keys [cmd exit]}] + (l/infof "%s exited w/ status %d" + (first cmd) exit))}) + r (apply p/shell opts args) + out (.toString out-stream)] + (-> r + (assoc ::out out)))) + (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) + (let [{out ::out} (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) + (->> (re-seq preview-end-regexp out) (map #(let [[d1 d2 d3] (map parse-long (drop 1 %)) depth (/ (- d2 tp2) scale-divisor @@ -29,11 +58,11 @@ {:depth depth :height (+ depth (/ (+ d1 tp4) - tex-scale-divisor - tex-fontsize)) + scale-divisor + font-size)) :width (/ (+ d3 tp3 (- tp2)) - tex-scale-divisor - tex-fontsize)}))))) + scale-divisor + font-size)}))))) ;;; Temml