Last modified: 2014-09-23 22:41:41 UTC
that the default settings of the mediawiki (monobook) stylesheet should give
correctly centered math formulas when used inline in the middle of a sentence of
normal wikitext. The example given does indeed center properly, but some other
kinds of formulas do not. For instance: this formula: <math>2 \cdot 2 =
4</math> renders about 15% below the text line (the dot is aligned with the
bottom of the text line), which looks completely wrong. This can be fixed by
putting font tags into the wikitext, but this is extremely tedious.
This is an texvc issue --> changing product/component
[[w:en:User:Random832/Math baseline]] demonstrates a hypothetical fix using CSS vertical alignment (texvc would need to determine where the baseline is located in the image, and generate an appropriate pixel value for the vertical-align, to be applied via style="" to the img tag)
The correct address is [[User:Random832/Math baseline]] - I'd assumed wikilinks were relative to meta rather than enwiki.
I wrote a fix for this bug. Random832's suggestion is good (use vertical-align to set the baseline for math formulas rendered as images), but the question is: how do you compute the baseline? My idea is this: (1) underline the formula, on the baseline, in red, (2) write a tool invoked by texvc to find the underline (= baseline) in the image, and (3) call ImageMagick to strip out the underline in the final image, and (4) store the baseline in the math table for use when generating HTML linking to the image.
The result looks really good. These changes are mixed with a bunch of others in a live wiki, but hopefully next week I'll have time to extract them and post diffs.
Created attachment 6757 [details]
Changes to fix vertical alignment of png-rendered math formulas
Here are my proposed changes. There is one thing I did not deal with properly: the program that computes the baseline uses libpng and is written in C. I added a naive target to math/Makefile to build it using gcc, but a proper, portable build script is beyond me. Maybe someone familiar with autoconf would be willing to contribute such a thing? Although, honestly, expecting gcc and libpng to be installed seems less onerous than expecting ocaml to be installed.
(In reply to comment #4)
> I wrote a fix for this bug. Random832's suggestion is good (use vertical-align
> to set the baseline for math formulas rendered as images), but the question is:
> how do you compute the baseline? My idea is this: (1) underline the formula,
> on the baseline, in red, (2) write a tool invoked by texvc to find the
> underline (= baseline) in the image, and (3) call ImageMagick to strip out the
> underline in the final image, and (4) store the baseline in the math table for
> use when generating HTML linking to the image.
> The result looks really good. These changes are mixed with a bunch of others
> in a live wiki, but hopefully next week I'll have time to extract them and post
There is a very simple way to compute baseline position. LaTeX has a standard package called preview http://www.gnu.org/software/auctex/manual/preview-latex.html#Package-options.
If a formula is in preview section latex put information about baseline to dvi file. Then it can be extracted by dvipng with -depth option.
assaron@assaron:~/tmp$ cat ex.tex
assaron@assaron:~/tmp$ latex ex.tex
This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
restricted \write18 enabled.
entering extended mode
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, bulgarian, ukrainian, russian, loaded.
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
Preview: Fontsize 10pt
 (./ex.aux) )
Output written on ex.dvi (1 page, 280 bytes).
Transcript written on ex.log.
assaron@assaron:~/tmp$ dvipng -T tight -depth ex.dvi
This is dvipng 1.12 Copyright 2002-2008 Jan-Ake Larsson
This bug is always open : some formulas are correctly aligned but with two or more in whole line, there is some misalignments...
The solution found by Aleksey Sergushichev seems to be pretty.
Can someone take care of this issue ?
I'm duping this to bug 32694, where there's some work in progress using the preview package and -depth option on dvipng. This has a more recent patch, and I trust that method better than the pixel scan used in the original patch here.
*** This bug has been marked as a duplicate of bug 32694 ***
Cotton Seed -- just wanted to say, thanks for the patch.