Subject: [bug#67019] [PATCH v2 15/16] gnu: Add font-katex.

From: Philip McGrath <[email-masked]>
Date: Thu, 16 Nov 2023 14:15:53 -0500

* gnu/packages/javascript.scm (font-katex): New variable.
---
 gnu/packages/javascript.scm | 74 +++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index 97cb3b6270..ee7a48154c 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -30,9 +30,15 @@ (define-module (gnu packages javascript)
   #:use-module (gnu packages base)
   #:use-module (gnu packages bash)
   #:use-module (gnu packages compression)
+  #:use-module (gnu packages fontutils)
   #:use-module (gnu packages java)
   #:use-module (gnu packages node)
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages python)
+  #:use-module (gnu packages python-compression)
+  #:use-module (gnu packages python-xyz)
   #:use-module (gnu packages readline)
+  #:use-module (gnu packages tex)
   #:use-module (gnu packages uglifyjs)
   #:use-module (gnu packages web)
   #:use-module (guix gexp)
@@ -41,6 +47,7 @@ (define-module (gnu packages javascript)
   #:use-module (guix git-download)
   #:use-module (guix build-system ant)
   #:use-module (guix build-system cmake)
+  #:use-module (guix build-system copy)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system minify)
   #:use-module (guix build-system node)
@@ -372,6 +379,73 @@ (define-public js-mathjax-for-r-mathjaxr
               (base32
                "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh")))))))))
 
+(define-public font-katex
+  (package
+    (name "font-katex")
+    (version "0.16.4")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+              (url "https://github.com/KaTeX/KaTeX")
+              (commit (string-append "v" version))))
+       (sha256
+        (base32
+         "0z6y2188lhfv0gk0hp4rm37g6fs99qb3ab2q3n9g76ga9dwxhw3s"))
+       (snippet
+        ;; unbundle generated files
+        #~(begin
+            (use-modules (guix build utils))
+            (delete-file "src/fontMetricsData.js")
+            (delete-file-recursively "fonts")))
+       (file-name (git-file-name "katex" version))))
+    (build-system copy-build-system)
+    (native-inputs (list (texlive-updmap.cfg
+                          (list texlive-amsfonts
+                                texlive-cm
+                                texlive-fonts-rsfs))
+                         fontforge
+                         mftrace
+                         ttfautohint
+                         perl
+                         perl-json
+                         python
+                         python-fonttools
+                         python-brotli
+                         python-zopfli
+                         which))
+    (arguments
+     (list
+      #:install-plan
+      #~`(("fonts/" "share/fonts/truetype/katex/")
+          ("src/fontMetricsData.js" "share/katex/"))
+      #:imported-modules
+      `((guix build union)
+        ,@%copy-build-system-modules)
+      #:modules
+      '((guix build copy-build-system)
+        (guix build union)
+        (guix build utils))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-before 'install 'build
+            (lambda args
+              (invoke "make" "-C" "src/fonts" "all")
+              (union-build "fonts"
+                           '("src/fonts/ttf"
+                             "src/fonts/woff"
+                             "src/fonts/woff2")
+                           #:symlink copy-file)))
+          (add-after 'build 'build-metrics
+            (lambda args
+              (with-directory-excursion "dockers/fonts"
+                ;; script assumes it is run from this directory
+                (invoke "./buildMetrics.sh")))))))
+    (home-page "https://katex.org")
+    (synopsis "Fonts for KaTeX")
+    (description "This package contains the fonts required for KaTeX.")
+    (license license:expat)))
+
 (define-public js-commander
   (package
     (name "js-commander")
-- 
2.41.0