[l2h] Workarounds for two bugs (equations with white margins, and more)

Daniel Clemente n142857 at gmail.com
Sat Apr 2 18:52:42 CEST 2005


   Hi,

>You are assuming that there is only one possible value for
>the depth of an image, coming only from descenders on letters.
>This is completely forgetting about things like fractions,
>integral signs, summation operators and other mathematical
>notations. Indeed simply adding a subscript can create a larger
>depth than that of a letter such as 'y'.

   True... and computing the height of the tallest image in the
document and making all images of the same height would only be worse.
Some browsers can't don neither CSS nor HTML ALIGN and show all the
padding, which can be messy. Example: 
http://www.danielclemente.com/linux/dillo-paddings.png


>As for the "problem" of the padding beneath an image causing
>lines to spread unduly, this is easily solved using a CSS rule:
>e.g.
>    P  { line-height : 18pt }

   I have added it on my web. This should work for not very tall images.




>>   img[align="bottom"] { vertical-align: baseline !important; }
>Isn't this the default behaviour anyway,
>when there is no descender, depth or padding ?
>
>Which browsers get this wrong, if any ?

  Yes, it is the default; in fact, ALIGN="BOTTOM" and "vertical-align:
baseline;" are both the default values, so there is no need to write
them. I added it only to clarify and test other values; now I updated
that.
  They work in all browsers with no bugs. And the !important shouldn't
be really needed as that CSS rule has specificty 11 against the 0 from
the HTML (although in Firefox I had some problems with that).


>>   img[align="middle"] { vertical-align: middle !important; }
>
>Isn't this what the "bad" browsers do currently ?
>So now you are making those that currently "get it right" to change
>behaviour to match those that do it incorrectly.
>
  Well, that's the best I could achieve with CSS. I think CSS is the
only way to solve the alignment issues in modern browsers (since with
HTML they have bugs); but CSS "vertical-align: middle;" isn't very
good anyway.

>For this to work properly, the images must be prepared with less padding
>than at present; i.e. removing the amount of x-height, so that the 
>middle
>appears to be raised by .5 x-height within the contents of the image.

   I already removed the bottom padding from most images, with a
"patch" in latex2html code, but not following this metrics.
   The solution I wanted was to add less padding at the bottom and use
CSS vertical-align:middle to center these images.

>Unfortunately, this is not practical, since the x-height is a variable
>that the user can set when choosing the font-size to view the webpages.

   Maybe the padding can be always the same, not depending on the font
size which the user wants, but on the font size used to render the
formulas. This one doesn't change from browser to browser.

>One possible solution is to have a CSS rule that fixes the font-size,
>and image calculations then use this value, assuming that the CSS rules
>will apply when the page is viewed.
>Of course this now removes the user's convenience of selecting an
>appropriate font-size to view the HTML pages.

   Well, this isn't appropriate. But anyway, for big fonts, which is
considered "nicer"? Putting the formula on the baseline, or in the
middle (vertical midpoint) of the line? For subscripts like P_{x}, I
would prefer them on the baseline, but fractions would be better in
the middle. Probably a single value can't work for all cases.
   For normal-sized fonts or very small ones, there's no much difference.


>Another possibility is to scale images in the browser when the font-size
>changes. This can be done with CSS rules, but the scaling really
>upsets the bitmapped images. They are not vector-graphics.
>We would need to be using SVG format to have this work OK.
>But conversion of TeX output to SVG is really hard, and would require
>subsetting fonts for inclusion. That's really not practical at present.
>Besides, PDF is a much better format for this anyway.

  I think that writing them to a PNG works very well, better than
MathML/CSS/SVG/Unicode at the moment.


>BTW, did you experiment with the rule:
>
>         img[align="middle"] {vertical-align: -.5ex}
>
>This ought to mean "lower the image by 1ex from where you would
>otherwise put it", namely using 'middle' alignment.

   With the bottom padding that the current latex2html adds, I
couldn't find a value which worked for all font sizes (neither with
em, ex, nor percentages).

>Or maybe it needs to be one of:
>       img[align="middle"] {vertical-align: middle -.5ex}
   This isn't accepted; and if I put a CSS relative value it would be
better to remove the buggy HTML ALIGN. So the values would be relative
to the baseline (the CSS2 spec. says so).

>       img[align="middle"] {vertical-align: middle -.5ex !important}
   No, and {vertical-align: middle; vertical-align: -.5ex;} isn't
accepted neither. Anyway, the middle of the line can be reached from
the baseline with 0.5ex, I think, so this is not a problem.


   With the padding it does not work. I have checked the same with the
images generated after my patch (which somehow, removed bottom
margin), and the results seems better:

   Using  img[align="middle"] {vertical-align: -.5ex}  :
   -For those formulas with a small descendent (for example, a
subscript), the rule lowers the image a bit, so its baseline is now at
the level of the baseline of the text (this works well).
   -But if the formula is very tall, for example, a fraction
(1/2)/(1/5), lowering it 0.5ex doesn't make a difference: the fraction
line continues being far above the vertical midpoint.

   So this would require a different value for each image; this is useless.

>What do different browsers do with these rules?
   Something similar to seeing the page with a CSS-disabled browser.


Conclusions:

 -Is it possible to always use "vertical-align: middle" with some
images, adding only the required padding?
 -HTML ALIGN="MIDDLE" is a very good solution. So it's easier to fix
the browsers.
 -For Gecko, there's a patch, but someone has to check it in.
Konqueror and Opera work well. IE might (I haven't tested it). Dillo,
Links and Amaya don't support HTML ALIGN, so they will show all the
padding of the images.



>>About http://www.danielclemente.com/linux/l2h.html#within_preamble

>>   +          # added by DCL (patch from Ross Moore).
>>   +         # See 
>> http://www.tug.org/pipermail/latex2html/2004-February/002640.html
>>   +         #
>>   +         # after the first segment we should no longer be in the 
>> preamble.
>>   +         $within_preamble = 0;


>That comment about "should no longer be in the preamble" may be
>appropriate for your situation, but cannot be assumed to be true
>in general.

  Well, you explained the problem, see
http://www.tug.org/pipermail/latex2html/2004-February/002640.html

  A testcase is this: http://www.danielclemente.com/linux/tabular.tex
  Lyx generates similar files, with a command substitution which does
not take place:
  \providecommand{\tabularnewline}{\\}

  I will try to look into this.


  Thanks,

  Daniel



More information about the latex2html mailing list