1

Background

A document, having inline math statements, is being written in Markdown. The document is converted to XHTML for subsequent processing using ConTeXt.

Problem

The XHTML contains XML elements with inline TeX commands. The inline TeX commands are not interpreted by ConTeXt, resulting in output similar to the following:

Output document

SSCCE

Consider the following buffered XHTML snippet (e.g., generated from Markdown):

\startbuffer[document]
<body>
<p>$N = R_{*} \cdot f_{p} \cdot n_{e} \cdot f_{l} \cdot f_{i} \cdot f_{c} \cdot L$</p>
</body>
\stopbuffer

\startxmlsetups xml:xhtml
  \xmlsetsetup{\xmldocument}{*}{-}
  \xmlsetsetup{\xmldocument}{body|p}{xml:*}
\stopxmlsetups

\startxmlsetups xml:body \xmlflush{#1} \stopxmlsetups

\startxmlsetups xml:p
  \xmlflush{#1}\par
\stopxmlsetups

\xmlregistersetup{xml:xhtml}

\starttext
  \xmlprocessbuffer{xhtml}{document}{}
\stoptext

Idea 1 - Syntax

It's possible to produce documents that export new XHTML elements, such as:

<tex>$N = R_{*} \cdot f_{p} \cdot n_{e} \cdot f_{l} \cdot f_{i} \cdot f_{c} \cdot L$</tex>

Or even without the $ sigil:

<tex>N = R_{*} \cdot f_{p} \cdot n_{e} \cdot f_{l} \cdot f_{i} \cdot f_{c} \cdot L</tex>

However, TeX allows for both inline $ and block-level $$ syntax. These could be exported as tex_inline and tex_block elements, respectively, but that seems like duplication because ConTeXt already contains the parsing logic.

Idea 2 - Setups

The problem is likely with the setups. Variations, such as those from the steps document, did not result in typeset math:

\startbuffer[document]
<body>
<tex>$N = R_{*} \cdot f_{p} \cdot n_{e} \cdot f_{l} \cdot f_{i} \cdot f_{c} \cdot L$</tex>
</body>
\stopbuffer

\startxmlsetups xml:xhtml
  \xmlsetsetup{\xmldocument}{*}{-}
  \xmlsetsetup{\xmldocument}{body|p|tex}{xml:*}
\stopxmlsetups

% ...

\startxmlsetups xml:tex
  \mathematics{\xmlflush{#1}}
\stopxmlsetups

Even if it worked, this approach may prove problematic because users can insert (inline) TeX into any element: p, blockquotes, emphasis, strong, td, li, etc.

Idea 3 - Convert to MathML

itex2MML and TeX4ht both convert TeX to MathML, but such a step should not be needed.

Question

How would you embed inline/block-level TeX macros anywhere inside a well-formed XHTML document such that the macros will be typeset by ConTeXt?

(MathML is not a viable option for writing inside Markdown; conversion afterwards may be feasible.)

References

1 Answer 1

0

The following works:

% ...
  <tex>$N = R_{*} \cdot f_{p} \cdot n_{e} \cdot f_{l} \cdot f_{i} \cdot f_{c} \cdot L$</tex>  
% ...

\startxmlsetups xml:tex
  \xmlflushcontext{#1}
\stopxmlsetups

Using $$ also works.

3
  • It works if you remove \startimath and \stopimath, which are ConTeXt equivalents of inline math mode ($ ... $). Nice allusion to alien life, btw.
    – user226564
    Mar 22, 2021 at 3:53
  • 2
    I worked with your first example: using \startxmlsetups xml:p \xmlflushcontext{#1} \par \stopxmlsetups gives the expected result. I'm on ConTeXt 2021.03.20 01:07
    – user226564
    Mar 22, 2021 at 5:54
  • Using xml:p and xmlflushcontext errors out because XHTML documents can contain <p><img .../></p>. A <tex> tag that isolates \xmlflushcontext from otherwise un-flushable HTML elements seems necessary. Mar 25, 2021 at 5:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .