3

I found when adding the line \usepackage{newtxtext,newtxmath} breaks mathml generated by tex4ht and hence the math looks bad when viewed in the browser. It seems to be a font issue.

I am using texlive 2014, and I've updated it weeks ago. Here is MWE

\documentclass[10pt,notitlepage]{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}
\usepackage{etex}    
\begin{document}
\[
  \int \sin(x) \, dx
\]
\end{document}

I build this to mathml with mathjax support using standard .cfg. I will show the command used, the HTML output and the .cfg I am using.
To compile the above:

htlatex foo.tex "nma.cfg,charset=utf-8" " -cunihtf -utf8"

(/usr/local/texlive/2014/texmf-dist/fonts/tfm/public/newtx/ntxmia.tfm)
--- warning --- Couldn't find font `ntxmia.htf' (char codes: 0--255)
(/usr/local/texlive/2014/texmf-dist/fonts/tfm/public/newtx/ntxmia.tfm)
--- warning --- Couldn't find font `ntxmia.htf' (char codes: 0--255)
....

The HTML generated is

Mathematica graphics

The source code for the above HTML is

<!DOCTYPE html> 
<html> 
<head> <title></title> 
<meta charset="UTF-8" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true }, "HTML-CSS": { availableFonts: ["TeX"] } }); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><style type="text/css"> .MathJax_MathML {text-indent: 0;} </style></head><body 
>
   <div class="par-math-display"><!--l. 8--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" ><mrow 
>
                                                           <mo 
class="MathClass-op">Z
<!--nolimits--></mo><!--nolimits--><mo class="qopname"> sin</mo><!--nolimits--><mrow ><mo 
class="MathClass-open">}</mo><mrow><mo 
class="MathClass-op">x</mo></mrow><mo 
class="MathClass-close">~</mo></mrow><mspace width="0.3em" class="thinspace"/><mrow ><mo 
class="MathClass-open">d</mo><mrow><mo 
class="MathClass-op">x</mo>
</mrow></math></div>
<!--l. 10--><p class="nopar" >  
</body> 
</html>

Now when commenting %\usepackage{newtxtext,newtxmath} and running the same compile command above, this is the result

Mathematica graphics

And the HTML source code is

<!DOCTYPE html> 
<html> 
<head> <title></title> 
<meta charset="UTF-8" /> 
<meta name="generator" content="TeX4ht (http://www.cse.ohio-state.edu/~gurari/TeX4ht/)" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
<script type="text/x-mathjax-config"> MathJax.Hub.Config({ extensions: ["tex2jax.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true }, "HTML-CSS": { availableFonts: ["TeX"] } }); </script> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><style type="text/css"> .MathJax_MathML {text-indent: 0;} </style></head><body 
>
   <div class="par-math-display"><!--l. 8--><math 
 xmlns="http://www.w3.org/1998/Math/MathML"  
display="block" ><mrow 
>
                                             <mo 
class="MathClass-op">∫
 <!--nolimits--></mo><!--nolimits--><mo class="qopname">sin</mo><!--nolimits--><mrow ><mo 
class="MathClass-open">(</mo><mrow><mi 
>x</mi></mrow><mo 
class="MathClass-close">)</mo></mrow><mspace width="0.3em" class="thinspace"/><mi 
>d</mi><mi 
>x</mi>
</mrow></math></div>
<!--l. 10--><p class="nopar" >  
</body> 
</html>

The nma.cfg file I used in the compile command is:

\Preamble{mathml} 
\Configure{VERSION}{}
  \Configure{DOCTYPE}{\HCode{<!DOCTYPE html>\Hnewline}}
  \Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
  \Configure{@HEAD}{}
  \Configure{@HEAD}{\HCode{<meta charset="UTF-8" />\Hnewline}}
  \Configure{@HEAD}{\HCode{<meta name="generator" content="TeX4ht
  (http://www.cse.ohio-state.edu/\string~gurari/TeX4ht/)" />\Hnewline}}
  \Configure{@HEAD}{\HCode{<link
           rel="stylesheet" type="text/css"
           href="\expandafter\csname aa:CssFile\endcsname" />\Hnewline}}

  \Configure{@HEAD}{\HCode{%
     <script type="text/x-mathjax-config">
       MathJax.Hub.Config({
         extensions: ["tex2jax.js"],
         jax: ["input/TeX", "output/HTML-CSS"],
         tex2jax: {
           \unexpanded{inlineMath: [ ['$','$'], ["\\(","\\)"] ],}
           \unexpanded{displayMath: [ ['$$','$$'], ["\\[","\\]"] ],}
           processEscapes: true
         },
         "HTML-CSS": { availableFonts: ["TeX"] }
       });
     </script>
  }}

  \Configure{@HEAD}{\HCode{<script type="text/javascript"
    src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>}}

  \Configure{@HEAD}{\HCode{<style type="text/css">
    .MathJax_MathML {text-indent: 0;}
  </style>}}
\begin{document}
\EndPreamble
  • 1
    \ifdefined\HCode\else\usepackage{newtxtext,newtxmath}\fi The problem is that there are no .htf files for the NewTX fonts. – egreg Jan 3 '15 at 23:22
  • 1
    even if there were .htf fonts to support newtx in tex4ht I don't think it would help with this configuration as mathjax can not use those fonts (unless you go to the effort of contributing web font versions and font data of the format mathjax needs) so simply not using the package when using tex4ht seems the correct thing to do. – David Carlisle Jan 4 '15 at 0:00
2

The issue is that there are missing mapping files between newtx fonts and Unicode. Such mapping file, with .htf extension must exist for every font which should be supported by tex4ht.

These mappings had to be created by hand, which is quite tedious work. Here is a sample of such mapping:

ntxmia 0 255
'&#x0393;' '' Gamma 0
'&#x2206;' '' Delta 1
'&#x0398;' '' Theta 2
'&#x039B;' '' Lambda 3
'&#x039E;' '' Xi 4
'&#x03A0;' '' Pi 5
'&#x03A3;' '' Sigma 6
'&#x03A5;' '' Upsilon 7
'&#x03A6;' '' Phi 8
'&#x03A8;' '' Psi 9
....
Much more lines

The first line contains the font name, number of first character and number of the last character supported by the font. Then starts the actual mappings. It starts from the first character number until the last character. The line contains three records - first is the mapping used for the character, the second specifies if it should be converted to picture and the rest is a comment, usually glyph name and character number. The mapping contains XML entity of the character or ASCII string in the single quotes. More details about the htf format can be found in the tex4ht documentation.

Anyway, I've created a tool for automatic htf file generation, called Htfgen. I started the development at the time this question was posted and developed bunch of scripts and libraries that tried to achieve this target. After almost four years, the results finally seem to be interesting. I've created a new library, which can take a font name, detect if it is real or virtual font, find all used glyphs and find Unicode characters for them. This library is used by new script dvitohtf, which can detect all used fonts in a dvi file and generate TeX file which will generate .htf files for all fonts which don't have one yet.

It can be used like this

 dvitohtf foo.htf > newtx.tex
 tex newtx.tex

This will generate bunch of htf files. Note that there is lot of messages like this in the newtx.tex file:

 Missing glyph npropersuperset 

This message means that there is no known mapping from this glyph to Unicode. There is lot of such missing glyphs in the Newtx fonts, the support for them must be added to Htfgen, once correct Unicode mapping is found. If it exist.

The nextxt.tex file is too large to be posted here, so you can download it here.

This is your sample with the new htf files:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.