fast-reflexes / better-react-mathjax

MIT License
124 stars 16 forks source link

How to get the width of MathJax Render? #40

Closed nioclass closed 1 year ago

nioclass commented 1 year ago

Is there a way to get the width of a mathjax expression? (In pixels or character count for example? ) I want to know if the expression will fit on the screen without a horizontal scroll.

fast-reflexes commented 1 year ago

Hi!

I think this is a general HTML question rather than a MathJax or better-react-mathjax question. There are multiple ways of getting the width of an HTML element, all with its own perks. You can Google it and you'll find a lot of answers which might teach you about how they differ. The one I usually use is <ELEMENT>.getBoundingClientRect().width. To apply it in your scenario you either:

I've added an example with how to measure it using the first method in a codesandbox: https://codesandbox.io/s/better-react-mathjax-40-lrzok5

Good luck!

fast-reflexes commented 1 year ago

Feel free to reopen if you need further assistance! Best of luck!