mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.2k stars 1.16k forks source link

Continued fractions & power #791

Closed smsti closed 10 years ago

smsti commented 10 years ago

The basic example for continued fractions $$ \cfrac{2}{1+\cfrac{2}{1+\cfrac{2}{1}}} $$ works fine.

When I do something little more complicated, the continued fraction typesetting gets into troubles. Some symbols are smaller than expected: $$ \cfrac{2}{e^{\intop 1+\cfrac{2}{1+\cfrac{2}{1}}dx}} $$

Perhaps some limitation of MathJax. Could you hint an effective way how to overcome such troubles?

pkra commented 10 years ago

Could you describe the problem you see (or post a screenshot)?

For me, MathJax rendering and TeX rendering yield similar results (see below).

MathJax rendering TeX rendering

smsti commented 10 years ago

Hello,

thank you for response. The trouble can be observed just on your screenshots.

Is it reasonable that "dx", or "integral 1 + " in front of the fraction is typeset in a smaller font than numerator/enumerator?

pkra commented 10 years ago

MathJax tries to follow TeX's layout rules very closely so this is what MathJax is supposed to do.

I understand if you want to something different from the rendering; the rendering is certainly odd but then again I don't know what your desired result would be. I don't know the TeX internals for cfrac but I'm guessing the code example is abusing cfrac by mixing it with superscripts. cfrac is designed to optimize layout of continued fractions; the code example is not a continued fraction so it's not too surprising to run into trouble. You might want to try regular \frac instead.

dpvc commented 10 years ago

Is it reasonable that "dx", or "integral 1 + " in front of the fraction is typeset in a smaller font than numerator/enumerator?

No, but this is what you have requested by using \cfrac rather than \frac. Normally, super- and subscript are rendered in a smaller size than the base (they are in \scriptstyle), but \cfrac forces the numerator and denominator into \textstyle (and adds a \strut to make the spacing more consistent). So that makes the numerator and denominator bigger in the fraction than they should be. If you used \frac instead, the sizes would be smaller and match the integral and dx better. Alternatively, you could use

\cfrac{2}{e^{\textstyle \int 1+\cfrac{2}{1+\cfrac{2}{1}}\, dx}}

to force the exponent into text style so that integral and dx are the same size as the other symbols, but it will still look ugly. Using complex fractions in exponents is always awkward and rarely leads to pleasing results. I doubt you are going to get e to such a power to read well.

I'm not sure why you are using \intop rather than the more usual \int, here. That will also affect the size and spacing of the integral. I have changed in my example above.

smsti commented 10 years ago

Thank you for your comment. I have checked the example against LaTeX and got the same result there. Next time when I have an issue I will try in LaTeX prior posting, I was not aware it is tied to LaTeX so closely.

This site and forum is really full of valuable stuff.

pkra commented 10 years ago

@smsti thanks for confirming. MathJax's rendering is based on TeX's layout algorithms and our goal is to be as close to the rendering as possible. In this case, it's similar: when we implement a well known package like amsmath, we want to be make sure people get the result they expect from TeX.