3

I am learning context a little, so I can compare its output to HTML with tex4ht. I know very little about context.

I found the most simple example in this answer ConTeXt to HTML conversion for multiple math-heavy documents

I followed exactly the same instruction and using the same code shown there. All using TL 2023 on linux.

But when I view the generated HTML, I get this output

enter image description here

While the output that should show up, taken from the answer above is

enter image description here

The source code is exactly the same. Here it is again:

A.tex

\setupbackend[export=yes]
\starttext

Here is a sample of a math document which has some random $x = a +
\sqrt{\frac{1}{2}}$ inline math and some random display math
\startformula
  A = B + C + \frac{A}{B} + \binom{C}{D} 
\stopformula

\stoptext

I compiled the above using the command context A.tex

>context A.tex

resolvers | formats | executing runner 'run luametatex format': /usr/local/texlive/2023/bin/x86_64-linux/luametatex --jobname="./A.tex" --socket --shell-escape --fmt=/home/me/.texlive2023/texmf-var/luametatex-cache/context/1b4da46d1f340757f9984eae810b1464/formats/luametatex/cont-en.fmt --lua=/home/me/.texlive2023/texmf-var/luametatex-cache/context/1b4da46d1f340757f9984eae810b1464/formats/luametatex/cont-en.lui --c:currentrun=1 --c:fulljobname="./A.tex" --c:input="./A.tex" --c:kindofrun=1 --c:maxnofruns=9 --c:texmfbinpath="/usr/local/texlive/2023/bin/x86_64-linux" system > system > ConTeXt ver: 2023.05.05 18:36 LMTX fmt: 2023.10.5 int: english/english system > system > 'cont-new.mkxl' loaded open source > level 1, order 1, name '/usr/local/texlive/2023/texmf-dist/tex/context/base/mkxl/cont-new.mkxl' system > beware: some patches loaded from cont-new.mkiv close source > level 1, order 1, name '/usr/local/texlive/2023/texmf-dist/tex/context/base/mkxl/cont-new.mkxl' system > 'cont-sys.mkxl' loaded open source > level 1, order 2, name '/usr/local/texlive/2023/texmf-dist/tex/context/texlive/cont-sys.mkxl' open source > level 2, order 3, name '/usr/local/texlive/2023/texmf-config/tex/context/user/context-papersize.tex' close source > level 2, order 3, name '/usr/local/texlive/2023/texmf-config/tex/context/user/context-papersize.tex' close source > level 1, order 3, name '/usr/local/texlive/2023/texmf-dist/tex/context/texlive/cont-sys.mkxl' system > files > jobname './A', input './A.tex', result './A' fonts > latin modern fonts are not preloaded languages > language 'en' is active open source > level 1, order 4, name './A.tex' backend > export > enabling export to xml backend > backend > fonts > preloading latin modern fonts (second stage) mathematics > tweak > 'LatinModernMath-Regular', size 6, math size 3, version 'Version 1.959' found, version 'Version 1.958' expected fonts > 'fallback modern rm 12pt' is loaded backend > export > fuzzy paragraph: (U+1D434) = (U+0003D) (U+1D435) + (U+0002B) (U+1D436) + (U+0002B) + (U+0002B) backend > xmp > using file '/usr/local/texlive/2023/texmf-dist/tex/context/base/mkiv/lpdf-pdx.xml' pages > flushing realpage 1, userpage 1, subpage 1 backend > export > backend > export > exporting xml, xhtml, html and css files backend > export > backend > export > using cretated export path 'A-export' backend > export > using cretated images path 'A-export' backend > export > using cretated styles path 'A-export' backend > export > adding css reference 'styles/A-defaults.css' backend > export > adding css reference 'styles/A-images.css' backend > export > adding css reference 'styles/A-styles.css' backend > export > saving xml data in 'A-export/A-raw.xml' backend > export > saving css image definitions in 'A-export/styles/A-images.css' backend > export > saving css style definitions in 'A-export/styles/A-styles.css' backend > export > saving css template in 'A-export/styles/A-templates.css' backend > export > saving xhtml variant in 'A-export/A-tag.xhtml' backend > export > saving specification in 'A-export/A-pub.lua' backend > export > saving div based alternative in 'A-export/A-div.html' backend > export > backend > export > create epub with: mtxrun --script epub --make "A" [--purge --rename --svgmath] backend > export > close source > level 1, order 4, name './A.tex' mkiv lua stats > used config file: selfautoparent:/texmf-dist/web2c/texmfcnf.lua mkiv lua stats > used cache path: readable+writable: '/home/me/.texlive2023/texmf-var/luametatex-cache/context/1b4da46d1f340757f9984eae810b1464' mkiv lua stats > resource resolver: loadtime 0.043 seconds, 1 scans with scantime 0.004 seconds, 0 shared scans, 15 found files, scanned paths: /mnt/g/public_html/styles/texmf mkiv lua stats > stored bytecode data: 510 modules (0.119 sec), 105 tables (0.005 sec), 615 chunks (0.124 sec) mkiv lua stats > traced context: maxstack: 1698, freed: 0, unreachable: 1698 mkiv lua stats > cleaned up reserved nodes: 74 nodes, 7 lists of 435 mkiv lua stats > node memory usage: 11 attribute, 1 glue, 122 gluespec, 3 kern, 645 mathspec, 2 penalty, 2 temp mkiv lua stats > node list callback tasks: 16 unique task lists, 11 instances (re)created, 71 calls mkiv lua stats > inserted spaces in output: 16 mkiv lua stats > used backend: pdf mkiv lua stats > jobdata time: 0.000 seconds saving, 0.000 seconds loading mkiv lua stats > callbacks: file: 110, saved: 238, direct: 3, function: 1086, value: 2, message: 0, bytecode: 615, late 0, total: 2054 (2054 per page) mkiv lua stats > randomizer: resumed with value 0.47764243869862 mkiv lua stats > loaded patterns: en::1, load time: 0.000 mkiv lua stats > structure elements: 55 element chains identified mkiv lua stats > loaded fonts: 2 files: latinmodern-math.otf, lmroman10-regular.otf mkiv lua stats > font engine: otf 3.133, afm 1.513, tfm 1.000, 7 instances, 3 shared in backend, 3 common vectors, 0 common hashes, load time 0.092 seconds mkiv lua stats > math tweaking time: 0.026 seconds, 12 math goodie tables mkiv lua stats > font embedding time: 0.002 seconds, 2 fonts mkiv lua stats > result saved in file: A.pdf, compresslevel 1, objectcompresslevel 3 mkiv lua stats > positions: 7 collected, 0 deltas, 2 shared partials, 2 partial entries mkiv lua stats > used platform: linux-64, type: unix, binary subtree: bin mkiv lua stats > used engine: luametatex version: 2.1008, functionality level: 20230426, format id: 689, compiler: gcc mkiv lua stats > tex properties: 806391 hash slots used of 2097152, 50251 control sequences, approximate memory usage: 41 MB mkiv lua stats > lua properties: engine: lua 5.4, used memory: 94 MB, ctx: 91 MB, max: 99 MB, symbol mask: utf (τεχ) mkiv lua stats > runtime: 0.279 seconds, 1 processed pages, 1 shipped pages, 3.580 pages/second system | total runtime: 0.290 seconds of 0.368 seconds

>

It then created a folder called A-export/ below where A.tex is.

>ls -lrt A-export
total 13
drwxrwxrwx 1 me autologin    0 Oct 10 01:12 images
-rwxrwxrwx 1 me autologin 1954 Oct 10 01:12 A-raw.xml
drwxrwxrwx 1 me autologin    0 Oct 10 01:12 styles
-rwxrwxrwx 1 me autologin 1962 Oct 10 01:12 A-tag.xhtml
-rwxrwxrwx 1 me autologin  432 Oct 10 01:12 A-pub.lua
-rwxrwxrwx 1 me autologin 2185 Oct 10 01:12 A-div.html

And here is the A-div.html file. You see, it has funny characters

>cat A-export/A-div.html
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<!--

input filename   : A
processing date  : 2023-10-10 01:12:39-05:00
context version  : 2023.05.05 18:36
exporter version : 0.35

-->

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">

&lt;head&gt;

    &lt;meta charset=&quot;utf-8&quot;/&gt;

    &lt;title&gt;A&lt;/title&gt;

<link type="text/css" rel="stylesheet" href="styles/A-defaults.css" /> <link type="text/css" rel="stylesheet" href="styles/A-images.css" /> <link type="text/css" rel="stylesheet" href="styles/A-styles.css" />

&lt;/head&gt;
&lt;body&gt;
    &lt;div class=&quot;document&quot; xmlns=&quot;http://www.pragma-ade.com/context/export&quot;&gt;

<div class="warning">Rendering can be suboptimal because there is no default/fallback css loaded.</div>

<div> Here is a sample of a math document which has some random <math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mi></mi><mo>=</mo><mi></mi><mo>+</mo><msqrt><!-- begin m:mrow --><!-- begin m:mrow --><mfrac><mrow><mn>1</mn><merror detail="rule"> </merror></mrow><mrow><merror detail="rule"> </merror><mn>2</mn></mrow></mfrac><!-- end m:mrow --><!-- end m:mrow --></msqrt></mrow></math>⁄inline math and some random display math <div class="formula"> <div class="formulacontent n-1"> <math display="block" xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mi></mi> <mo>=</mo> <mi></mi> <mo>+</mo> <mi></mi> <mo>+</mo> <!-- begin m:mrow --> <mfrac> <!-- begin m:mrow --> <mi></mi> <!-- end m:mrow --> <!-- begin m:mrow --> <mi></mi> <!-- end m:mrow --> </mfrac> <!-- end m:mrow --> <mo>+</mo> <mrow> <!-- begin m:mo --><mo>(</mo><!-- end m:mo --> <mfrac> <!-- begin m:mrow --> <mi></mi> <!-- end m:mrow --> <!-- begin m:mrow --> <mi></mi> <!-- end m:mrow --> </mfrac> <!-- begin m:mo --><mo>)</mo><!-- end m:mo --> </mrow> </mrow> </math> </div> </div> </div>

    &lt;/div&gt;
&lt;/body&gt;

</html>

These funny characters are also in the xml file generated:

>cat A-export/A-raw.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<!--

input filename   : A
processing date  : 2023-10-10 01:12:39-05:00
context version  : 2023.05.05 18:36
exporter version : 0.35

-->

<?xml-stylesheet type="text/css" href="styles/A-defaults.css" ?> <?xml-stylesheet type="text/css" href="styles/A-images.css" ?> <?xml-stylesheet type="text/css" href="styles/A-styles.css" ?>

<document context="2023.05.05 18:36" date="2023-10-10 01:12:39-05:00" file="A" language="en" title="A" version="0.35" xmlns:m="http://www.w3.org/1998/Math/MathML"> Here is a sample of a math document which has some random <m:math display="inline"><m:mrow><m:mi></m:mi><m:mo>=</m:mo><m:mi></m:mi><m:mo>+</m:mo><m:msqrt><!-- begin m:mrow --><!-- begin m:mrow --><m:mfrac><m:mrow><m:mn>1</m:mn><m:merror detail="rule"> </m:merror></m:mrow><m:mrow><m:merror detail="rule"> </m:merror><m:mn>2</m:mn></m:mrow></m:mfrac><!-- end m:mrow --><!-- end m:mrow --></m:msqrt></m:mrow></m:math>⁄inline math and some random display math <formula> <formulacontent n="1"> <m:math display="block"> <m:mrow> <m:mi></m:mi> <m:mo>=</m:mo> <m:mi></m:mi> <m:mo>+</m:mo> <m:mi></m:mi> <m:mo>+</m:mo> <!-- begin m:mrow --> <m:mfrac> <!-- begin m:mrow --> <m:mi></m:mi> <!-- end m:mrow --> <!-- begin m:mrow --> <m:mi></m:mi> <!-- end m:mrow --> </m:mfrac> <!-- end m:mrow --> <m:mo>+</m:mo> <m:mrow> <!-- begin m:mo --><m:mo>(</m:mo><!-- end m:mo --> <m:mfrac> <!-- begin m:mrow --> <m:mi></m:mi> <!-- end m:mrow --> <!-- begin m:mrow --> <m:mi></m:mi> <!-- end m:mrow --> </m:mfrac> <!-- begin m:mo --><m:mo>)</m:mo><!-- end m:mo --> </m:mrow> </m:mrow> </m:math> </formulacontent> </formula> </document> >

I tried Chrome browser and Brave browsers, all on windows 10. I also tried firefox on linux. This is what it shows

enter image description here

>context --version
mtx-context     | ConTeXt Process Management 1.04
mtx-context     |
mtx-context     | main context file: /usr/local/texlive/2023/texmf-dist/tex/context/base/mkiv/context.mkiv
mtx-context     | current version: 2023.05.05 18:36
mtx-context     | main context file: /usr/local/texlive/2023/texmf-dist/tex/context/base/mkxl/context.mkxl
mtx-context     | current version: 2023.05.05 18:36

The question is: How to get rid of these characters? Am I doing anything wrong? What is the canonical way to convert context latex file to HTML if not the above?

Nasser
  • 20,220

1 Answers1

3

This is a side effect of using snippets instead of rules for radicals and fractions. As it is work in progress, it was not yet done for the export, and for the moment you can disable this by invoking

\setupmathfractions
  [rule=auto]

\setupmathradical [sqrt] [rule=auto]

When doing that, I see no extra Unicode stuff in the export.

PS. For this type of questions, where it is quite obvious that one does not get the intended output, it might be better to send an email to the ConTeXt mailing list where you directly reach Hans (who after all is the one who will fix this).

mickep
  • 8,685
  • I can add that there are a few things that we need to look at when it comes to export and math, so one can expect some instability in the near future. – mickep Oct 10 '23 at 15:39