Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-14 Thread Jason Ross via ntg-context



On 10/12/21 8:31 PM, Aditya Mahajan wrote:


This is an issue with ConTeXt, but most of these issues are minor are easy to 
fix. Just send minimal examples showing the incorrect rendering.

Aditya




An example is attached.
MathML generated with

pandoc -f latex -t html --mathml sample-math.tex \
| xmlstarlet ed -d "//*[local-name()='annotation']" \
| xmlstarlet sel -t -c "/p/*" \
| xmlstarlet ed -m "//*[local-name()='semantics']/*" \
"//*[local-name()='math']" \
| xmlstarlet ed -d "//*[local-name()='semantics']"
\usemodule[mathml]
\starttext
\startplaceformula
  \startformula
\xmlprocessdata{}{
  
  http://www.w3.org/1998/Math/MathML; display="block">

  
[

  

  
R

  1
  x

  

  
  

  
R

  1
  y

  

  
  

  
F

  2
  x

  

  
  

  
F

  2
  y

  

  
  

  
R

  3
  x

  

  
  

  
R

  3
  y

  

  
  

  
R

  4
  x

  

  
  

  
R

  4
  y

  

  

]
  
  =
  
[

  

  

  
A
1
  
  
E
1
  


  L
  1

  


  0


  
  

  
A
1
  
  
E
1
  


  L
  1

  


  0


  0


  0


  0


  0

  
  

  0


  0


  0


  0


  0


  0


  0


  0

  
  

  
  

  
A
1
  
  
E
1
  


  L
  1

  


  0


  

  
A
1
  
  
E
1
  


  L
 

Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-12 Thread Aditya Mahajan via ntg-context
On Tue, 12 Oct 2021, Jason Ross wrote:

> 
> 
> On 10/11/21 4:02 PM, Aditya Mahajan wrote:
> > You can use pandoc to parse latex and convert it to mathml:
> > 
> > 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.
> 
> Hmm. Looks like converting to MathML isn't going to work just yet.
> Is this an issue with ConTeXt? The MathML seems to render correctly in
> LibreOffice but gets mangled when exporting to ConTeXt.

This is an issue with ConTeXt, but most of these issues are minor are easy to 
fix. Just send minimal examples showing the incorrect rendering.

Aditya
___
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
___


Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-12 Thread Jason Ross via ntg-context



On 10/11/21 4:02 PM, Aditya Mahajan wrote:

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

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.


Hmm. Looks like converting to MathML isn't going to work just yet.
Is this an issue with ConTeXt? The MathML seems to render correctly in
LibreOffice but gets mangled when exporting to ConTeXt.

I'll explore some of the alternatives you suggested. A simple parser
will be fine for now. Thank you the help.

Best Regards,

Jason
___
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
___


Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-11 Thread Aditya Mahajan via ntg-context
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


http://www.w3.org/1998/Math/MathML;>a=(123123123),b=(123123123),c=(123123123),d=(123123123),\begin{aligned}
 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{aligned}

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

test.tex
Description: TeX document


test.pdf
Description: Adobe PDF document
___
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
___


Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-10 Thread Jason Ross via ntg-context

On 10/10/21 3:23 AM, Hans Hagen wrote:


what do you mean with 'quite different'

Hans


Hi Hans,

My current stumbling block is dealing with the `align` environment.
I replace `\begin{align}/\end{align}` with
`\startmathalignment/\stopmathalignment`, and replace all `&` characters
with `\NC` and `\\` with `\NR`, which is simple enough.
However, the two commands work differently - `align` doesn't care
how many columns you have, but `mathalignment` does. This makes dealing
with aligned equations containing matrices hard - you can't just count
how many `&`s you see before you get to a `\\`, because you might be
inside of a matrix in which case they don't count.

Also, `mathalignment` and `matrix` want a leading `\NC` to start each
column, while LaTeX `align` and `matrix` just want `&` as a column
separator.

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.

Thanks,

Jason
___
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
___


Re: [NTG-context] Converting LaTeX math to ConTeXt

2021-10-10 Thread Hans Hagen via ntg-context

On 10/10/2021 5:45 AM, Jason Ross via ntg-context wrote:

Hello,

I'm trying to provide more support for LaTeX math for an Org Mode
exporter for ConTeXt. LaTeX is the de facto standard for mathematics in
Org Mode. However, the syntax is quite different between LaTeX and
ConTeXt. I have a few ideas, but none that I'm happy about.

1. Export LaTeX to MathML then import that into ConTeXt. I don't know
    how to get this to work. latexmlmath only returns the first row of
    `align` environments (for me anyway). Also, this would require users
    to install another program.
2. Typeset equations with LaTeX as standalone pages and then include
    them as images. This will typeset everything with LaTeX defaults.
    Also, either equation alignment or equation numbering will break.
3. Hack every math environment I can think of to accept LaTeX syntax
    (see https://wiki.contextgarden.net/LaTeX_Math_in_ConTeXt). Lots
    of work, lots of problems as described in the article. End-users
    could add their own hacks to the template preamble for cases I
    don't get to.
4. Manually parse and convert every LaTeX math environment to ConTeXt
    before exporting. Basically a non-starter.

I'm wondering what's the best way to go about this. Surely others have
run into the same problem?

what do you mean with 'quite different'

Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
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
___


[NTG-context] Converting LaTeX math to ConTeXt

2021-10-09 Thread Jason Ross via ntg-context

Hello,

I'm trying to provide more support for LaTeX math for an Org Mode
exporter for ConTeXt. LaTeX is the de facto standard for mathematics in
Org Mode. However, the syntax is quite different between LaTeX and
ConTeXt. I have a few ideas, but none that I'm happy about.

1. Export LaTeX to MathML then import that into ConTeXt. I don't know
   how to get this to work. latexmlmath only returns the first row of
   `align` environments (for me anyway). Also, this would require users
   to install another program.
2. Typeset equations with LaTeX as standalone pages and then include
   them as images. This will typeset everything with LaTeX defaults.
   Also, either equation alignment or equation numbering will break.
3. Hack every math environment I can think of to accept LaTeX syntax
   (see https://wiki.contextgarden.net/LaTeX_Math_in_ConTeXt). Lots
   of work, lots of problems as described in the article. End-users
   could add their own hacks to the template preamble for cases I
   don't get to.
4. Manually parse and convert every LaTeX math environment to ConTeXt
   before exporting. Basically a non-starter.

I'm wondering what's the best way to go about this. Surely others have
run into the same problem?

Thanks,

Jason
___
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
___