bugtex4ht - Bugs: bug #488, \over does not give the same...

 
 
Show feedback again

You are not allowed to post comments on this tracker with your current authentification level.

bug #488: \over does not give the same result as equivalent \frac

Submitted by:  Patrice Dumas <pertusus>
Submitted on:  Mon Oct 26 19:08:38 2020  
 
Category: NonePriority: 5 - Normal
Severity: 3 - MinorStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Sun Nov 1 22:21:26 2020, comment #5:

I've done some more experiments and come with an interesting solution: convert MathML to HTML and render it using CSS. I've used this project as the basis for CSS: https://github.com/fred-wang/mathml.css/

Not everything is good. Fractions look OK, ordinary inline math too, but for example integrals are completely wrong. I've tried to set fence sizes using some simple heuristics, I am not sure how well it works for a more complicated stuff.

Anyway, sample.tex contains some dummy examples, sample.mk4 code for make4ht that does the conversion, and mathml.css is a modified version of Fred Wang's CSS file.

sample.tex can be compiled using the following command:

make4ht -m draft sample.tex "mathml"

(file #366, file #367, file #368)

Michal Hoftich <michal_h21>
Project Member
Tue Oct 27 23:03:34 2020, comment #4:

Ok. It looks much better now. Maybe the fraction bar could be a little more up, but even without that change it seems ok to me.

When the numerator is larger than the denominator, the bar is short, using the numerator width instead of the max. For example

${x^i \over \tan y}$

Patrice Dumas <pertusus>
Tue Oct 27 20:24:36 2020, comment #3:

I've modified the CSS code to produce a better result - the fractions are now vertically aligned and font sizes are better:

------
\Preamble{xhtml}
\catcode`\:=11
\def\IgnoreRule{\ht:special{t4ht@\string_}}
\def\EndIgnoreRule{\ht:special{t4ht@\string_\string_}}
\def\a:mathml{}
% \Configure{over}
% {\Send{GROUP}{0}
% {<\a:mathml mfrac><\a:mathml mrow>}\HCode{</\a:mathml mrow>}}
% {\HCode{<\a:mathml mrow>}\Send{EndGROUP}{0}
% {</\a:mathml mrow></\a:mathml mfrac>}}
\Configure{over}
{\Send{GROUP}{0}{<span class="fraction"><span class="top">}\IgnoreRule\HCode{</span>}}
{\HCode{<span class="bottom">}\EndIgnoreRule\Send{EndGROUP}{0}{</span></span>}}

\Css{
.fraction {
display: inline-flex;
flex-direction: column;
padding: 0 2px;
align-items: center;
font-size:70\%; % to get correct box size
vertical-align: 50\%;
}}

% reset font size, it will be downsized to 70% by HT fonts
\Css{.fraction span{font-size:1rem;}}

\Css{.top {
border-bottom: 2px solid grey;
}}

\Configure{$}{\HCode{<span class="math-inline">}\DviMath}{\EndDviMath\HCode{</span>}}{}
\catcode`\:=12
\begin{document}
\EndPreamble
-----------

We will definitely add this to TeX4ht sources once we find a good CSS that works in all cases. We may use this method also for \frac and other more complicated formatting that uses images at the moment. It should result in much better inline math than in the current state, where text and images are used. We may even try to use it for display math, where we use images by default.

Michal Hoftich <michal_h21>
Project Member
Tue Oct 27 17:01:37 2020, comment #2:

I can do what you propose, the inline result is ok even though the alignment is not perfect. But I would prefer if it could be handled natively in tex4ht. In particular I won't be able to debug whenever something break, in particular it seems to me that you use some "internal" tex4ht macros.

Patrice Dumas <pertusus>
Mon Oct 26 22:35:17 2020, comment #1:

The simplest thing you can do is to convert your whole inline math to image, using for example:

httex filename "xhtml,html5,pic-m"

Also, it works in MathML:

htttex filename "xhtml,html5,mathml,mathjax"

As it works in MathML, it is obvious that it is possible to configure \over to produce sensible output in plain HTML. Here is a sample HTML document:

\documentclass{article}
\begin{document}
${a+2 \over b} $

$ 1 + \begingroup a \over b \endgroup + 2$

$ 1 + \bgroup a \over b \egroup + 2$

$ 1 + { a \over b \egroup + 2$

$ 1 + \bgroup a \over b } + 2$
\end{document}

And here is a config file:


\Preamble{xhtml}
\catcode`\:=11
\def\IgnoreRule{\ht:special{t4ht@\string_}}
\def\EndIgnoreRule{\ht:special{t4ht@\string_\string_}}

\Configure{over}
{\Send{GROUP}{0}{<span class="fraction"><span class="top">}\IgnoreRule\HCode{</span>}}
{\HCode{<span class="bottom">}\EndIgnoreRule\Send{EndGROUP}{0}{</span></span>}}

\Css{
.fraction {
display: inline-flex;
flex-direction: column;
padding: 0 2px;
align-items: center;
font-size:130\%;
}}
\Css{.top {
border-bottom: 2px solid grey;
}}

\Configure{$}{\DviMath}{\EndDviMath}{}
\catcode`\:=12
\begin{document}
\EndPreamble


It uses CSS flex box to render fractions.

I don't really understand how \Send command works, as it is not really documented anywhere in TeX4ht sources. But it can be used in these cases to insert HTML code at beginning and end of the current group. It works only in \DviMath mode, which is why the following configuration is necessary:

\Configure{$}{\DviMath}{\EndDviMath}{}

I don't know if it will have any side effects on other math configurations, hopefully not.

Compile the example using

make4ht -c config.cfg sample.tex

Michal Hoftich <michal_h21>
Project Member
Mon Oct 26 19:08:38 2020, original submission:

{a \over b} does not give the same output as \frac{a}{b}, processed by htlatex (or httex, though there is no real comparison possible as \frac is not available in plain TeX), in inline math, like ${a \over b}$. \frac is formatted as an image, ${a \over b}$ becomes
a_ b

which corresponds actually to html code

<span
class="cmmi-7">a</span>_
<span
class="cmmi-7">b</span>

In displaymath $$ the results is the same with \over and \frac, with images in both cases.

Patrice Dumas <pertusus>

 

Attached Files
file #366:  sample.tex added by michal_h21 (844B - text/x-tex)
file #367:  sample.mk4 added by michal_h21 (2kB - application/octet-stream)
file #368:  mathml.css added by michal_h21 (6kB - text/css)
file #365:  t.tex added by pertusus (130B - text/x-tex - example file)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by michal_h21 (Posted a comment)
  • -unavailable- added by pertusus (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    4 latest changes follow.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun Nov 1 22:21:26 2020michal_h21Attached File-=>Added sample.tex, #366
      Attached File-=>Added sample.mk4, #367
      Attached File-=>Added mathml.css, #368
    Mon Oct 26 19:08:38 2020pertususAttached File-=>Added t.tex, #365
    Show feedback again

    Back to the top


    Powered by Savane 3.1-cleanup+gray