element-hq / element-web

A glossy Matrix collaboration client for the web.
https://element.io
GNU Affero General Public License v3.0
11.01k stars 1.96k forks source link

Automatically scale LaTeX rendering to a readable font size #17326

Open HarHarLinks opened 3 years ago

HarHarLinks commented 3 years ago

Is your suggestion related to a problem? Please describe.

image

Describe the solution you'd like.

Perhaps a content-sensitive upscale could be applied, especially regarding the very commond \frac, but perhaps some others can be preset. Alternatively have a min size for "regular" elements as well as sub/superscript elements. Calculate the text size of the smallest element, and scale up the whole result based on a reference smallest allowed size.

Describe alternatives you've considered.

There are probably more, including user controlled, like a button on messages that contain latex to pop it out in a larger viewer or user definable scaling factor. The default size may be larger in latex-only messages similar to emoji-only.

dbkr commented 2 years ago

Cleaning up Help Wanted stuff and we now consider it to be mutually exclusive with x-needs-design, and I agree this needs confirmation from design that this is the right choice.

nadonomy commented 2 years ago

Going through a bunch of x-needs-design issues, on this specifically no-one on the design team is a LaTeX user so would need steering on this - if we have any references of other platforms which get this right we'd love to see them.

SimonBrandner commented 2 years ago

@HarHarLinks, after looking at this again, it looks like you should be just using the \dfrac command...

HarHarLinks commented 2 years ago

I see. Could Element's LaTeX renderer simply use displaystyle all the time in order to maintain readability? I don't think people are going to be using dfrac usually, especially when copy-pasting formulas from a document to discuss them.

On a side note, there is an issue with the proposed dfrac where it gets cut off: image

SimonBrandner commented 2 years ago

I see. Could Element's LaTeX renderer simply use displaystyle all the time in order to maintain readability? I don't think people are going to be using dfrac usually, especially when copy-pasting formulas from a document to discuss them.

I am not very familiar with that command, so I am not sure this is desirable... I am also not sure if it can be implemented easily, could you please open an issue about it?

On a side note, there is an issue with the proposed dfrac where it gets cut off: image

A new issue too, please :)

HarHarLinks commented 2 years ago

I am not very familiar with that command, so I am not sure this is desirable... I am also not sure if it can be implemented easily, could you please open an issue about it?

That would be this issue here then, applying displaystyle would be a possible solution. The idea with inline math is to scale it such that it appears inline. This works ok for small formula or bigger font size, but with element's defaults it results in a fraction being displayed very small. Displaystyle as an alternative to this inline style is (usually) for standalone blocks of formulas, allowing them to not be constrained to line height and thus formatting a lot nicer. See for an example: https://www.overleaf.com/learn/latex/Display_style_in_math_mode

My suggestion would be to simply default to this rendering mode in element by (presumably simply) telling the latex engine to use displaystyle instead of inline style.

One place where displaystyle should certainly be applied is when sending a message that is purely LaTeX, e.g. "formatted_body": "<span data-mx-maths=\"\\frac{a}{\\phi^2}\"><code>\\frac{a}{\\phi^2}</code></span>", where it currently renders as inline