ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan via ntg-context <ntg-context@ntg.nl>
To: Jason Ross via ntg-context <ntg-context@ntg.nl>
Cc: Aditya Mahajan <adityam@umich.edu>
Subject: Re: Converting LaTeX math to ConTeXt
Date: Mon, 11 Oct 2021 19:02:55 -0400 (EDT)	[thread overview]
Message-ID: <nycvar.YAK.7.78.908.2110111845060.2962387@nqv-guvaxcnq> (raw)
In-Reply-To: <30bf2652-92e6-f571-e424-e0586ff09d4d@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4256 bytes --]

On Sun, 10 Oct 2021, Jason Ross via ntg-context wrote:

> On 10/10/21 3:23 AM, Hans Hagen wrote:
> 
> These are just a couple examples, but in general it's not enough to do
> naive string substitution in LaTeX and get valid ConTeXt back, and my
> patchwork solutions are starting to smell.

You can use pandoc to parse latex and convert it to mathml:

$ cat math.tex

\documentclass{amsart}
\begin{document}
\begin{align}
 a &= \begin{pmatrix}
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3
 \end{pmatrix},
 b &= \begin{pmatrix}
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3
 \end{pmatrix},
 \\
 c &= \begin{pmatrix}
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3
 \end{pmatrix},
 d &= \begin{pmatrix}
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3
 \end{pmatrix},
\end{align}
\end{document}

$ pandoc -f latex -t html --mathml math.tex


<p><math display="block" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mtable><mtr><mtd columnalign="right"><mi>a</mi></mtd><mtd columnalign="left"><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mtable><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr></mtable><mo stretchy="true" form="postfix">)</mo></mrow><mo>,</mo><mi>b</mi></mtd><mtd columnalign="right"><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mtable><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr></mtable><mo stretchy="true" form="postfix">)</mo></mrow><mo>,</mo></mtd></mtr><mtr><mtd columnalign="right"><mi>c</mi></mtd><mtd columnalign="left"><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mtable><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr></mtable><mo stretchy="true" form="postfix">)</mo></mrow><mo>,</mo><mi>d</mi></mtd><mtd columnalign="right"><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mtable><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr><mtr><mtd columnalign="center"><mn>1</mn></mtd><mtd columnalign="center"><mn>2</mn></mtd><mtd columnalign="center"><mn>3</mn></mtd></mtr></mtable><mo stretchy="true" form="postfix">)</mo></mrow><mo>,</mo></mtd></mtr></mtable><annotation encoding="application/x-tex">\begin{aligned}
 a &amp;= \begin{pmatrix}
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3
 \end{pmatrix},
 b &amp;= \begin{pmatrix}
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3
 \end{pmatrix},
 \\
 c &amp;= \begin{pmatrix}
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3
 \end{pmatrix},
 d &amp;= \begin{pmatrix}
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3 \\
    1 &amp; 2 &amp; 3
 \end{pmatrix},\end{aligned}</annotation></semantics></math></p>

Processing this in context (see attached files), gives a partially working solution. It doesn't look okay, but should be easily fixable.

Do note that this is almost same as compiling latex output to PDF because editing presentation mathml by hand is no fun.

Aditya

[-- Attachment #2: Type: application/x-tex, Size: 2557 bytes --]

[-- Attachment #3: Type: application/pdf, Size: 8175 bytes --]

[-- Attachment #4: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2021-10-11 23:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-10  3:45 Jason Ross via ntg-context
2021-10-10 10:23 ` Hans Hagen via ntg-context
2021-10-10 14:44   ` Jason Ross via ntg-context
2021-10-11 23:02     ` Aditya Mahajan via ntg-context [this message]
2021-10-12 21:43       ` Jason Ross via ntg-context
2021-10-13  3:31         ` Aditya Mahajan via ntg-context
2021-10-13  4:46           ` Jason Ross via ntg-context

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=nycvar.YAK.7.78.908.2110111845060.2962387@nqv-guvaxcnq \
    --to=ntg-context@ntg.nl \
    --cc=adityam@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).