unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Removing/Ignoring xmlns when using xml->sxml
@ 2024-07-22  3:11 Richard Sent
  2024-07-22 15:28 ` Luis Felipe
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Sent @ 2024-07-22  3:11 UTC (permalink / raw)
  To: guile-user

Hi all,

I have some XML created by a tool called latexml that can convert LaTeX
equations to MathML. I am processing the output of this tool as part of
a Guile program and will be using it in a website.

The output looks something like this:

--8<---------------cut here---------------start------------->8---
<math xmlns=\"http://www.w3.org/1998/Math/MathML\" alttext=\"\\frac{1}{2}\" display=\"block\">
  <mfrac>
    <mn>1</mn>
    <mn>2</mn>
  </mfrac>
</math>
--8<---------------cut here---------------end--------------->8---

I need to convert this output to SXML to integrate it with the rest of
the toolchain.

Annoyingly, when using xml->sxml, the xmlns attribute is prepended to
every non-default element. For example,
'(http://www.w3.org/1998/Math/MathML:math ...) [1].

This behavior is undesirable when splicing the MathML into HTML, since
HTML doesn't support namespaces and web browsers don't seem to handle
elements with colons. The intended conversion is to simply splice the
MathML into HTML, sans namespace [2].

xml->sxml has a #:namespaces argument that allows me to alias the URL
namespace to something else in the SXML, but it doesn't look like I can
alias it to a "nil" namespace that isn't prepended at all.

The only option I can think of is to strip the xmlns=blah string from
the XML ahead of time. (Because converting to SXML prepends every
element, that's a lot harder to fix.) This solution feels rather hacky.

Does anyone know of a better way? I don't believe latexml has an option
to force HTML-compatible MathML output for individual equations.

I'd be surprised if no one else encountered this before. Hopefully I'm
missing something. Thanks! :)

[1]: (guile) Reading and Writing XML, "SXML elements built from
non-default namespaces will have their tags prefixed with their URI."
[2]:
https://en.wikipedia.org/wiki/MathML#Embedding_MathML_in_HTML/XHTML_files

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Removing/Ignoring xmlns when using xml->sxml
  2024-07-22  3:11 Removing/Ignoring xmlns when using xml->sxml Richard Sent
@ 2024-07-22 15:28 ` Luis Felipe
  2024-07-22 23:58   ` Richard Sent
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Felipe @ 2024-07-22 15:28 UTC (permalink / raw)
  To: Richard Sent, guile-user


[-- Attachment #1.1.1: Type: text/plain, Size: 1737 bytes --]

Hi Richard,

El 22/07/24 a las 3:11, Richard Sent escribió:
> Hi all,
>
> I have some XML created by a tool called latexml that can convert LaTeX
> equations to MathML. I am processing the output of this tool as part of
> a Guile program and will be using it in a website.
>
> The output looks something like this:
>
> --8<---------------cut here---------------start------------->8---
> <math xmlns=\"http://www.w3.org/1998/Math/MathML\" alttext=\"\\frac{1}{2}\" display=\"block\">
>    <mfrac>
>      <mn>1</mn>
>      <mn>2</mn>
>    </mfrac>
> </math>
> --8<---------------cut here---------------end--------------->8---
>
> I need to convert this output to SXML to integrate it with the rest of
> the toolchain.
>
> Annoyingly, when using xml->sxml, the xmlns attribute is prepended to
> every non-default element. For example,
> '(http://www.w3.org/1998/Math/MathML:math ...) [1].
>
> This behavior is undesirable when splicing the MathML into HTML, since
> HTML doesn't support namespaces and web browsers don't seem to handle
> elements with colons. The intended conversion is to simply splice the
> MathML into HTML, sans namespace [2].
>
> xml->sxml has a #:namespaces argument that allows me to alias the URL
> namespace to something else in the SXML, but it doesn't look like I can
> alias it to a "nil" namespace that isn't prepended at all.

The following seems to work (where xml-string is the example you provided):

(define namespaces '((#false . "http://www.w3.org/1998/Math/MathML")))

(xml->sxml xml-string #:namespaces namespaces)
$7 = (*TOP* (math (@ (display "block") (alttext "\\frac{1}{2}")) "\n  " 
(mfrac "\n    " (mn "1") "\n    " (mn "2") "\n  ") "\n"))



[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 2881 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Removing/Ignoring xmlns when using xml->sxml
  2024-07-22 15:28 ` Luis Felipe
@ 2024-07-22 23:58   ` Richard Sent
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Sent @ 2024-07-22 23:58 UTC (permalink / raw)
  To: Luis Felipe; +Cc: guile-user

Thanks! That works. As far as I can tell that behavior is not documented
in the manual so I'll try to send out a patch for that.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-22 23:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-22  3:11 Removing/Ignoring xmlns when using xml->sxml Richard Sent
2024-07-22 15:28 ` Luis Felipe
2024-07-22 23:58   ` Richard Sent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).