15.2.1 • Published 1 month ago

@amermathsoc/texml-to-html v15.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 month ago

texml-to-html

Converting texml-generated JATS/BITS-like XML to HTML.

Getting started

Quick example

For a first test run, try an example, e.g.,

  • Install via npm: $ npm i @amermathsoc/texml-to-html
  • Process a test file: $ node node_modules/@amermathsoc/texml-to-html/examples/cli.js node_modules/@amermathsoc/texml-to-html/text/article.xml > htmlOutput.html

Basic usage

import fs from "fs";
import path from "path";
import xml2html from "@amermathsoc/texml-to-html";

const article = xml2html(
  fs.readFileSync(path.resolve(process.argv[2])).toString()
).window.document;
console.log(article.toString());

Overview

Our general strategy for elements and attributes is to follow allow-lists and discard everything else.

We primarily we are recursing through the input DOM, building the output DOM. Rarely, we deviate from this approach for practical reasons (e.g., for metadata extraction).

preserved elements

Some elements in texml's XML output have the same name (and purpose) as in HTML. We preserve them in the output:

  • hr
  • p
  • pre
  • sup
  • sub
  • table
  • tbody
  • thead
  • th
  • tr
  • td

preseved attributes

Some attributes in texml's XML output have the same name (and purpose) in HTML.

As per our general strategy, we only preserve some attributes on some elements.

  • attribute names that are preserved
    • class
    • id
    • rowspan
    • colspan
    • hidden
  • element names where those attributes are preserved
    • all preserved elements (cf. above)
    • abstract
    • app
    • boxed-text
    • def-list
    • def
    • fig
    • fn
    • notes
    • p
    • preface
    • ref-list
    • sec-heading
    • statement
    • target
    • term

data-* attributes

Beyond HTML element and attributes, texml-to-html stores data in custom data-* attributes. The following lists should help as a guide to understand the this structural information.

:warning: This list can easily fall out of date. It should be automated.

data-* attribute values and origin

downstream data-* attributes

While the vast majority of data attributes originate in texml-to-html, we have a few cases where downstream tooling introduces custom attributes. We list the attribute names, the related tools and purpose:

  • deprecated data-eqn-tag-#
    • superceded by data-ams-tags (cf. earlier)
    • ams-eqn-store used to use these numbered attribute names to store extracted equation tags for downstream use (e.g., ams-html math panel)
  • deprecated data-ams-tags
    • this attribute contained a stringified array of equation tag strings
    • while initially generated by texml-to-html, ams-eqn-store overwrote them with rendered output if TeX was present in the strings.
role values

The following ARIA-DPUB role attribute values are used:

  • doc-preface
  • doc-bibliography
  • doc-appendix
  • doc-dedication
  • doc-noteref
  • doc-biblioref
  • doc-footnote
  • doc-chapter
  • doc-abstract
  • doc-toc
  • doc-footnote
  • doc-appendix

texml XML to data-* mappings

The following provide a list from the reverse point of view.

  • book
    • book-id@book-id-type = 'publ_key' => data-ams-doc="series"
    • book-meta => data-ams-doc="titlepage"
      • contains JSON blob with book-meta, collection-meta; cf. metadata section in this document
    • book-back//ref-list => data-ams-doc-level="1
    • book//sec/alt-title => data-ams-doc-alttitle
  • article => data-ams-doc="article" this is a somewhat messy part as we pick and choose, sort of reversely; much of it repeated on copyright page without data attributes
    • front => data-ams-doc="frontmatter" (some info in head element)
      • contains JSON blob with (most of) journal-meta, article-meta; cf. metadata section in this document.
      • the folllowing descendants create additional HTML (since they may contain tex-math):
        • article-meta>title-group => passthrough
        • notes => data-ams-doc=notes with data-ams-content-type (for @notes-type)
        • abstract => via role
        • kwd-group's => data-ams-doc with @vocab or "keywords"
        • funding-group => data-ams-doc=funding-group
  • styled-content => data-ams-style="{@style-type}"
    • roman => data-ams-style="roman"
      • or \textrm{...} (if inside text)
    • sc => data-ams-style="sc"
      • or $\mathsc{...}$ (if inside text)
    • monospace => data-ams-style="monospace"
      • or \texttt{...} (if inside text)
    • underline => data-ams-style="underline"
  • disp-quote => data-ams-style="{@specific-use}"
  • xref => data-ams-ref="{@ref-type}"
  • p//p => data-ams-doc="paragraph"
  • fn/label => data-ams-doc="label"
  • statement/secheading/title | statement/secheading/label => data-ams-doc="secheading"
  • mixed-citation => data-ams-doc="biblioentry" formerly role="doc-biblioentry" (deprecated)
  • sec | ack | front-matter-part | front-matter/dedication => data-ams-doc="{@specific-use}"
  • abstract => role="doc-abstract">
  • statement => data-ams-doc="statement"
  • graphic | inline-graphic => data-ams-doc="{name()}" data-ams-style="{@specific-use}"
    • graphic | inline-graphic @width => data-ams-width
    • graphic | inline-graphic @height => data-ams-height.
  • inline-formula => data-ams-doc="math inline" OR $...$
    • within disp/inline-formula, inline-formula may appear inside text. In that case, we have to create TeX strings for MathJax to process, wrapped in $
  • disp-formula => data-ams-doc="math block"
  • disp-formula-group => data-ams-doc="statement" data-ams-content-type="disp-formula-group"
  • raw-citation => data-ams-doc="amsref"
  • string-name => data-ams-doc="stringname"
  • verse-group => data-ams-doc="verse-group"
  • boxed-text => div@data-ams-style="boxed"
  • notes => section with data-ams-doc="notes"
    • @notes-type => @data-ams-content-type (and role=dedication for dedications)
    • use cases: dedication (articles), article and section notes (NOTI only), drm notice & epub note (books)
  • attributes

metadata handling

Publication metadata (both journal/series and article/book metadata) is primarily stored in a JSON blob in a script tag in the frontmatter (for articles) and titlepage (for books) sections respectively.

Section metadata (contributor metadata and pre-generated byline) is stored similarly as a json blob inside the data-ams-contributors attribute.

The relevant components in texml-to-html (i.e., article-metadata-json.js, book-meta-json.js, sec-meta.js) should provide a (hopefully easy enough) overview how the XML metadata is mapped and stored. The snapshots in the test folder should also be helpful, alongside any (example) article's JSON blob.

The following are commonly found metadata items:

For journal articles:

  • <article-meta>
    • <contrib-group> etc (cf. "contributors" below)
    • <self-uri>
    • <title-group> etc
    • <pub-date> etc
    • <notes>
    • <kwd-group>
      • MSC (using <compound-kwd> etc)
      • article keywords (using <kwd>)
    • <related-article> etc (correction/erratum forward/backward)
    • <custom-meta-group> (communicated by, NOTI categories, NOTI titlepic)
    • <funding-group> / <funding-statement>
    • <permissions>
      • <copyright-statement>
    • <history> etc
    • <article-id> etc
    • <abstract> etc
    • <volume>, <issue>
  • <journal-meta>
    • <journal-id>
    • <journal-title-group> etc
    • <issn> etc
    • <publisher>
    • <self-uri> etc

For books:

  • <collection-meta>
    • <publisher> etc
    • <title-group>
    • <volume-in-collection>
      • <volume-number>
    • <custom-meta-group> (for subseries) <book-meta>
    • <book-id> etc
    • <book-title-group> etc
    • <book-volume-number>
    • <publisher>
    • <contrib-group> etc (cf. "contributors" below)
    • <self-uri>
    • <title-group> etc
    • <pub-date> etc
    • <notes>
    • <issn>
    • <isbn>
    • <permissions>
  • <front-matter>
    • <toc> etc
    • <notes>
    • <preface>
    • <front-matter-part>

math mode

Note. There is some overlap with other sections of this document. Ensure that updates are consistent across the document.

For math mode, texml creates MathJax-optimized TeX strings that may contain XML markup; for content not supported by MathJax it falls back to SVG creation. This mix requires extra processing.

xref

Math mode output may contain xref elements. This gets turned into something like \xhref[@ref-type]{#@rid}{...}; the custom xhref MathJax macro works in both (MathJax's) text and math mode.

text inside math mode

In the case where math mode contains text mode, texml creates text elements possibly containing text XML markup. We turn this into MathJax-compatible TeX strings.

  • text only appears inside tex-math; it is converted to \\text{...}
  • italic creates \textit{}
  • bold creates \textbf{}
  • roman creats \textrm{...}
  • sc creates $\mathsc{...}$
  • monospace creates \texttt{...}
  • ext-link creates \href{}{} as(which works in both text and math mode)

nested math mode

In the case where math mode is nested (math mode inside text mode inside math mode), we have to adjust our processing to create MathJax-compatible TeX strings.

  • nested math mode can only appear within text and will only be inline-formula which is (essentially) converted to $...$

algorithm layout

Note. Since the markup and attributes are heavily scoped, we do not reproduce the attributes in other sections.

Texml creates pseudo-namespaced elements for algorithm layout (e.g., from algorithmicx pacakge).

We convert the markup to HTML custom elements with attributes. Further processing happens downstream to enable adequate styling.

  • alg:algorithm => alg-algorithm
  • *alg:line => alg-line
    • @lineno => alg-lineno (preceding sibling of alg-line)
    • data-ams-alg-spanslineno (if first child is alg:require or alg:ensure)
  • alg:block => alg-block
    • data-ams-alg-blocklevel (calculated from nesting)
  • alg:statement, alg:require, alg:ensure, alg:globals => alg-statement
  • alg:comment => alg-comment
  • pass through:
    • alg:body
    • alg:outputs
    • alg:inputs
    • alg:condition
    • alg:if
    • alg:elsif
    • alg:else
    • alg:for
    • alg:forall
    • alg:while
    • alg:repeat
    • alg:until
    • alg:loop
15.2.0

1 month ago

15.2.1

1 month ago

15.1.1

5 months ago

15.1.0

6 months ago

15.0.0

6 months ago