Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equation ID #872

Open
rgieseke opened this issue Mar 23, 2021 · 3 comments · Fixed by #875
Open

Equation ID #872

rgieseke opened this issue Mar 23, 2021 · 3 comments · Fixed by #875
Labels

Comments

@rgieseke
Copy link
Contributor

When going e.g. from JATS with MathML to JSON i noted that an id like

<inline-formula id="eq1"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" alttext="1\times 1" display="inline"><mml:mrow><mml:mn>1</mml:mn><mml:mo>&#xD7;</mml:mo><mml:mn>1</mml:mn></mml:mrow></mml:math></inline-formula> 

doesn't get an id in the resulting output.

I've changed the following

diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts
index ef6a6e8c..40503729 100644
--- a/src/codecs/jats/index.ts
+++ b/src/codecs/jats/index.ts
@@ -2125,11 +2125,13 @@ function decodeMath(
     const image = decodeGraphic(graphic, inline)
     return inline ? image : [stencila.paragraph({ content: image })]
   }
-
+  const equationId = attr(formula, 'id') ?? ''
+  
   // Wrapper is needed to dump the entire math element
   const text = xml.dump(elem('wrapper', mathml))
   return [
     (inline ? stencila.mathFragment : stencila.mathBlock)({
+      id: equationId,
       mathLanguage: 'mathml',
       text,
     }),

Should i make a PR for this?

Another question, could the alttext attribute with the original TeX or screen reader information be a separate attribute?
If yes, would that have to be added in the Math schema (https://schema.stenci.la/math) or meta field?

@rgieseke
Copy link
Contributor Author

Figured out the last question, one way to get the alttext:

diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts
index ef6a6e8c..d7f1572b 100644
--- a/src/codecs/jats/index.ts
+++ b/src/codecs/jats/index.ts
@@ -2125,11 +2125,14 @@ function decodeMath(
     const image = decodeGraphic(graphic, inline)
     return inline ? image : [stencila.paragraph({ content: image })]
   }
-
+  const equationId = attr(formula, 'id') ?? ''
+  const altText = attr(mathml, "alttext") ?? ''
   // Wrapper is needed to dump the entire math element
   const text = xml.dump(elem('wrapper', mathml))
   return [
     (inline ? stencila.mathFragment : stencila.mathBlock)({
+      id: equationId,
+      meta: {altText: altText},
       mathLanguage: 'mathml',
       text,
     }),

@nokome
Copy link
Member

nokome commented Mar 24, 2021

I like the idea of capturing the alttext and agree that meta.altText is the best place for this for now. However, in the longer term it should probably live in a specific property (meta is really just a temporary dumping ground for properties that we don't have specific properties for. Some options could be

Happy to consider alternatives. If you would like to progress this further a PR to stencila/schema would be appreciated.

@stencila-ci
Copy link
Collaborator

🎉 This issue has been resolved in version 0.111.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants