This commit is contained in:
2026-02-24 10:43:43 -07:00
parent aa8b89fe84
commit 790ce7e01f
2 changed files with 42 additions and 16 deletions

View File

@@ -110,9 +110,9 @@
(comment (comment
(let [out (ByteArrayOutputStream.)] (let [out (ByteArrayOutputStream.)]
(p/shell {:out (tee-output-stream (p/shell {:out (tee-output-stream
out out (l/log-stream :info "blah"))}
(l/log-stream :info "blah"))} "echo" "hello\n" "worms")
"echo" "hello" "worms"))) (.toString out)))
(defn invoke [opts & cmd] (defn invoke [opts & cmd]
(l/info (str/join " " (cons "$" cmd))) (l/info (str/join " " (cons "$" cmd)))
@@ -122,7 +122,4 @@
opts) opts)
cmd) cmd)
bin (first 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)) r))

View File

@@ -2,7 +2,10 @@
(:require [babashka.process :as p] (:require [babashka.process :as p]
[net.deertopia.doerg.common :as common] [net.deertopia.doerg.common :as common]
[clj-cbor.core :as cbor] [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 ;;; XeLaTeX
@@ -13,15 +16,41 @@
(def ^:private tightpage-regexp (def ^:private tightpage-regexp
#"^Preview: Tightpage (-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)\s*(-?[0-9]+)") #"^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]}] (defn- invoke-xelatex [& {:keys [file output-dir]}]
(let [{:keys [out]} (common/invoke (let [{out ::out} (invoke
{:dir output-dir} {:dir output-dir}
"xelatex" "-no-pdf" "-interaction" "nonstopmode" "xelatex" "-no-pdf" "-interaction" "nonstopmode"
"-output-directory" output-dir file) "-output-directory" output-dir file)
[tp1 tp2 tp3 tp4] (->> (re-find tightpage-regexp out) [tp1 tp2 tp3 tp4] (->> (re-find tightpage-regexp out)
(drop 1) (drop 1)
(map parse-long))] (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 %)) (map #(let [[d1 d2 d3] (map parse-long (drop 1 %))
depth (/ (- d2 tp2) depth (/ (- d2 tp2)
scale-divisor scale-divisor
@@ -29,11 +58,11 @@
{:depth depth {:depth depth
:height (+ depth :height (+ depth
(/ (+ d1 tp4) (/ (+ d1 tp4)
tex-scale-divisor scale-divisor
tex-fontsize)) font-size))
:width (/ (+ d3 tp3 (- tp2)) :width (/ (+ d3 tp3 (- tp2))
tex-scale-divisor scale-divisor
tex-fontsize)}))))) font-size)})))))
;;; Temml ;;; Temml