diff mbox series

[bug#65479,core-updates,17/61] gnu: Add docbook-mathml-1.0.

Message ID 3971596b65c5520b349e80cff4e07f67a840131b.1692830149.git.mirai@makinata.eu
State New
Headers show
Series The Draining of the XML & DocBook Swamp. | expand

Commit Message

Bruno Victal Aug. 23, 2023, 10:35 p.m. UTC
* gnu/packages/docbook.scm (docbook-mathml-1.0): New variable.
---
 gnu/packages/docbook.scm | 59 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

Comments

Maxim Cournoyer Oct. 6, 2023, 12:05 a.m. UTC | #1
Hi!

Bruno Victal <mirai@makinata.eu> writes:

> * gnu/packages/docbook.scm (docbook-mathml-1.0): New variable.
> ---
>  gnu/packages/docbook.scm | 59 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
>
> diff --git a/gnu/packages/docbook.scm b/gnu/packages/docbook.scm
> index 91b3eeeccb..8cabaa780d 100644
> --- a/gnu/packages/docbook.scm
> +++ b/gnu/packages/docbook.scm
> @@ -278,6 +278,65 @@ (define-public docbook-xml-4.1.2
>         (modify-inputs (package-native-inputs template)
>           (prepend libxml2))))))
>  
> +(define-public docbook-mathml-1.0
> +  (package
> +    (name "docbook-mathml")
> +    (version "1.0")
> +    (source (origin
> +              (method url-fetch)
> +              (uri
> +               (string-append "https://www.oasis-open.org/docbook/xml/mathml/"
> +                              version "/dbmathml.dtd"))
> +              (sha256
> +               (base32
> +                "10vmyl29j829w4xn928rznh163pf47gyzbbjjwqrbg2bidfnk7vp"))))
> +    (build-system copy-build-system)
> +    (arguments
> +     (let ((target (format #f "xml/docbook/mathml/~a/" version)))
> +       (list
> +        #:modules '((guix build copy-build-system)
> +                    (guix build utils)
> +                    (sxml simple)
> +                    (srfi srfi-1))
> +        #:phases
> +        #~(modify-phases %standard-phases
> +            (add-before 'install 'generate-catalog.xml
> +              (lambda _
> +                (let ((store-uri (string-append "file://"
> +                                                #$output "/"
> +                                                #$target "dbmathml.dtd")))
> +                  (call-with-output-file "catalog.xml"
> +                    (lambda (port)
> +                      (sxml->xml
> +                       `(*TOP*
> +                         (*PI* xml "version='1.0'")
> +                         (catalog (@ (xmlns "urn:oasis:names:tc:entity:xmlns:xml:catalog"))
> +                           (public (@ (publicId "-//OASIS//DTD DocBook MathML Module V1.0//EN")
> +                                      (uri ,store-uri)))

These lines are > 80 chars.  You could bind the public ID and namespace
as variables to keep these lines shorter.

> +                           ,@(map
> +                              (lambda (scheme)
> +                                `(system
> +                                  (@ (systemId
> +                                      ,(string-append scheme
> +                                                      "://www.oasis-open.org/docbook/xml/"
> +                                                      "mathml/1.0/dbmathml.dtd"))

Here you could move scheme under string-append to keep the line width in
check.

> +                                     (uri ,store-uri))))
> +                              '("http" "https"))))
> +                       port)))))))
> +        #:install-plan
> +        #~`(("catalog.xml" #$target)
> +            ("dbmathml.dtd" #$target)))))
> +    (propagated-inputs
> +     ;; These must be propagated for the package to make sense.
> +     ;; TODO: Package MathML2 DTD and propagate it as well.
> +     (list docbook-xml-4.1.2))
> +    (home-page
> +     "https://www.oasis-open.org/docbook/xml/mathml/1.0/index.1.shtml")
> +    (synopsis "MathML support for DocBook XML V4.1.2.")

There shouldn't be a trailing '.' in synopses.  'guix lint' should say so.
Bruno Victal Oct. 6, 2023, 2:59 p.m. UTC | #2
On 2023-10-06 01:05, Maxim Cournoyer wrote:
>> +            (add-before 'install 'generate-catalog.xml
>> +              (lambda _
>> +                (let ((store-uri (string-append "file://"
>> +                                                #$output "/"
>> +                                                #$target "dbmathml.dtd")))
>> +                  (call-with-output-file "catalog.xml"
>> +                    (lambda (port)
>> +                      (sxml->xml
>> +                       `(*TOP*
>> +                         (*PI* xml "version='1.0'")
>> +                         (catalog (@ (xmlns "urn:oasis:names:tc:entity:xmlns:xml:catalog"))
>> +                           (public (@ (publicId "-//OASIS//DTD DocBook MathML Module V1.0//EN")
>> +                                      (uri ,store-uri)))
> 
> These lines are > 80 chars.  You could bind the public ID and namespace
> as variables to keep these lines shorter.

Would it perhaps be better to define the SXML catalog instead as a
separate procedure/phase and invoke it instead? i.e.

--8<---------------cut here---------------start------------->8---
;; Decouple catalog

(define make-dbmath-catalog-sxml
  #~(lambda* (#:key outputs #:allow-other-keys)
      (let* ((…something along the lines of (assoc-ref output "out")
              or (search-input-files outputs "dbmath.dtd"))
             (uri (string-append "file:/" …)))
        … SXML representation of catalog…))

(define-public
  …
  (add-before 'install 'generate-catalog.xml
    (lambda* (#:key outputs #:allow-other-keys)
      (call-with-output-file "catalog.xml"
        (lambda (port)
          (sxml->xml (#$make-dbmath-catalog-sxml outputs)))))))

;; alternatively, if this is valid…

(define-public
  (define make-dbmath-catalog-sxml …)
  (package
    …
    (add-before 'install 'generate-catalog.xml
      (lambda* (#:key outputs #:allow-other-keys)
        (call-with-output-file "catalog.xml"
          (lambda (port)
            (sxml->xml (#$make-dbmath-catalog-sxml outputs)))))))

--8<---------------cut here---------------end--------------->8---

Alternatively we could do as you suggest though I think the only thing
that's tenable to bind is the namespace. In general, binding public IDs
(and other kinds of ID) in XML Catalogs will quickly yield a rabbit hole
of bindings:

--8<---------------cut here---------------start------------->8---
(let ((namespace …)
      (public-id-for-entry-X …)
      (public-id-for-entry-Y …)
      …
      …
      (public-id-for-entry-γ …)
  …)) 

--8<---------------cut here---------------end--------------->8---

(can you picture what the SXML representations would look like for
something like [1] and [2]?)

Note¹: Though it's tempting to use string manipulation to make some
sort of parameterizable routine that can `map' and generate the full
URIs using only “version” parameters and perhaps other datums I'm
skeptical this is even a good idea. The XML Catalog spec says that
the URIs do not have to be resolvable or have any specific meaning
other than serve as a identifier for some resource. (it could be
something totally crazy, as long the document author and tools
understand that it represents some kind of external “thing”)

> There shouldn't be a trailing '.' in synopses.  'guix lint' should say so.

Nice catch!
I don't usually run `guix lint' as sometimes it can reindent things
with a worse result. I wonder if there's a way to control this behavior.


[1]: <https://docbook.org/xml/4.5/catalog.xml>
[2]: <https://docs.oasis-open.org/docbook/docbook/v5.2/cs01/catalog.xml>

¹ PS: Not really relevant for this series though this question will
be important when packaging the namespace-less variant of docbook-xsl
and generating proper catalogs for both docbook-xsl and docbook-xsl-nons.
Maxim Cournoyer Oct. 7, 2023, 5:01 p.m. UTC | #3
Hi Bruno,

Bruno Victal <mirai@makinata.eu> writes:

> On 2023-10-06 01:05, Maxim Cournoyer wrote:
>>> +            (add-before 'install 'generate-catalog.xml
>>> +              (lambda _
>>> +                (let ((store-uri (string-append "file://"
>>> +                                                #$output "/"
>>> +                                                #$target "dbmathml.dtd")))
>>> +                  (call-with-output-file "catalog.xml"
>>> +                    (lambda (port)
>>> +                      (sxml->xml
>>> +                       `(*TOP*
>>> +                         (*PI* xml "version='1.0'")
>>> +                         (catalog (@ (xmlns "urn:oasis:names:tc:entity:xmlns:xml:catalog"))
>>> +                           (public (@ (publicId "-//OASIS//DTD DocBook MathML Module V1.0//EN")
>>> +                                      (uri ,store-uri)))
>> 
>> These lines are > 80 chars.  You could bind the public ID and namespace
>> as variables to keep these lines shorter.
>
> Would it perhaps be better to define the SXML catalog instead as a
> separate procedure/phase and invoke it instead? i.e.
>
> ;; Decouple catalog
>
> (define make-dbmath-catalog-sxml
>   #~(lambda* (#:key outputs #:allow-other-keys)
>       (let* ((…something along the lines of (assoc-ref output "out")
>               or (search-input-files outputs "dbmath.dtd"))
>              (uri (string-append "file:/" …)))
>         … SXML representation of catalog…))
>
> (define-public
>   …
>   (add-before 'install 'generate-catalog.xml
>     (lambda* (#:key outputs #:allow-other-keys)
>       (call-with-output-file "catalog.xml"
>         (lambda (port)
>           (sxml->xml (#$make-dbmath-catalog-sxml outputs)))))))
>
> ;; alternatively, if this is valid…
>
> (define-public
>   (define make-dbmath-catalog-sxml …)
>   (package
>     …
>     (add-before 'install 'generate-catalog.xml
>       (lambda* (#:key outputs #:allow-other-keys)
>         (call-with-output-file "catalog.xml"
>           (lambda (port)
>             (sxml->xml (#$make-dbmath-catalog-sxml outputs)))))))
>

I don't think that's valid, but I've not tried.

The idea is to try to meet the 80 chars limit while not making the
unique strings awkward to use (e.g. by breaking them on multiple lines).

I thought there's only 2 of them here so binding them in a let seemed
the best way to go.

Let's keep it simple :-).
diff mbox series

Patch

diff --git a/gnu/packages/docbook.scm b/gnu/packages/docbook.scm
index 91b3eeeccb..8cabaa780d 100644
--- a/gnu/packages/docbook.scm
+++ b/gnu/packages/docbook.scm
@@ -278,6 +278,65 @@  (define-public docbook-xml-4.1.2
        (modify-inputs (package-native-inputs template)
          (prepend libxml2))))))
 
+(define-public docbook-mathml-1.0
+  (package
+    (name "docbook-mathml")
+    (version "1.0")
+    (source (origin
+              (method url-fetch)
+              (uri
+               (string-append "https://www.oasis-open.org/docbook/xml/mathml/"
+                              version "/dbmathml.dtd"))
+              (sha256
+               (base32
+                "10vmyl29j829w4xn928rznh163pf47gyzbbjjwqrbg2bidfnk7vp"))))
+    (build-system copy-build-system)
+    (arguments
+     (let ((target (format #f "xml/docbook/mathml/~a/" version)))
+       (list
+        #:modules '((guix build copy-build-system)
+                    (guix build utils)
+                    (sxml simple)
+                    (srfi srfi-1))
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-before 'install 'generate-catalog.xml
+              (lambda _
+                (let ((store-uri (string-append "file://"
+                                                #$output "/"
+                                                #$target "dbmathml.dtd")))
+                  (call-with-output-file "catalog.xml"
+                    (lambda (port)
+                      (sxml->xml
+                       `(*TOP*
+                         (*PI* xml "version='1.0'")
+                         (catalog (@ (xmlns "urn:oasis:names:tc:entity:xmlns:xml:catalog"))
+                           (public (@ (publicId "-//OASIS//DTD DocBook MathML Module V1.0//EN")
+                                      (uri ,store-uri)))
+                           ,@(map
+                              (lambda (scheme)
+                                `(system
+                                  (@ (systemId
+                                      ,(string-append scheme
+                                                      "://www.oasis-open.org/docbook/xml/"
+                                                      "mathml/1.0/dbmathml.dtd"))
+                                     (uri ,store-uri))))
+                              '("http" "https"))))
+                       port)))))))
+        #:install-plan
+        #~`(("catalog.xml" #$target)
+            ("dbmathml.dtd" #$target)))))
+    (propagated-inputs
+     ;; These must be propagated for the package to make sense.
+     ;; TODO: Package MathML2 DTD and propagate it as well.
+     (list docbook-xml-4.1.2))
+    (home-page
+     "https://www.oasis-open.org/docbook/xml/mathml/1.0/index.1.shtml")
+    (synopsis "MathML support for DocBook XML V4.1.2.")
+    (description "The DocBook MathML Module is an extension to DocBook XML
+V4.1.2 that adds support for MathML in equation markup.")
+    (license (license:non-copyleft "" "See file headers."))))
+
 (define-public docbook-xml docbook-xml-5.1)
 
 ;;; There's an issue in docbook-xsl 1.79.2 that causes manpages to be