-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we solve \tag overlap with flexboxes? #3066
Comments
The reason we use the layout we do is that flexbox (as far as I know) cannot center the equation itself; rather, it can only center the equation within the space leftover by the tag. The plus side is that $$ x=5 $$
\begin{equation} y=5 \end{equation} is properly aligned. The downside is that the tag can overlap. It would be great to fix the latter without breaking the former. You probably want to prefix your CSS rules with |
Hi @edemaine thanks for your reply. I guess a flexbox can center both. I'd love to make some tests as soon as I have some free time. The flexbox is applied over the I guess it is also possible to center the entire flexbox ( I can not prefix my CSS rules because there is no way to differentiate between the inline equations and block equations (I'm talking about CSS path here). That's why I was suggesting to add an extra CSS class when rendering block equations. What do you think? |
|
I tried getting the correct layout with flexbox (for the nth time), using an invisible tag on the left ( Sadly, this doesn't work in the case where the left antitag + equation fit, but the right tag doesn't fit. It works when just the equation fits, or when all three fit, but not when two out of three fit. (To test, try resizing the window.) I don't see how to fix this in all three cases, but I'm open to ideas! |
I'm no doubt missing something major, but this fork of your pen appears to work: https://codepen.io/mbourne/pen/KKXdXem I commented out flex-wrap and justify-content and it gave me what I believe is wanted at all generally-used screen widths. My "overflowXauto" class is to make the horizontal scroll bar more noticeable than browser defaults. |
@mbourne Ah, good point: If we ignore the desire for the equation number to wrap when the width is small, we can at least get the tag not to overlap the equation (but still cause overflow). This is almost certainly an improvement over the current behavior, though still not perfect. (For me, perfect would include: if the screen is wide enough to fix the equation and not the tag, put the tag on a second line, and avoid overflow scrollbars. I imagine this could be fixed with some JavaScript though...) |
"... I imagine this could be fixed with some JavaScript though..." Always best to try to solve things with CSS, but there comes a point... I'm not a fan of adding any more DOM elements than necessary, so here are 2 attempts that do not use an empty tag. (1) No wrap case This addresses the issues of :
It's acceptable, I feel, even though it is a little odd right on the crossover between normal and when the scroll bar is about to appear (as you reduce screen width). But 99.99% of users don't resize the browser frantically on each page load - only developers. Here is an example page: https://bourne2learn.com/math/katex/tag-placement_nowrap.html My basic approach is to change the tag display to inline-block when the width of the equation and the tag means it's going to overflow. I allow for an imaginary tag width (without actually inserting an imaginary tag) to keep the equation in the middle as much as possible. The tweak to the equation width in the if statement ( (2) Wrap case It does make sense to try to wrap the tag (and to attempt your definition of 'perfect' for this), so I gave it a go. This time, I set the display of the equation to inline-block, and the white-space property of the parent (of the equation and the tag) to normal. It works reasonably well: https://bourne2learn.com/math/katex/tag-placement_wrap.html But it gave issues and was a lot more involved. I needed to mess with the .vlist heights and it was becoming ugly quickly. At certain screen widths, and in certain contexts, the reader may think the tag number is the answer for the equation: The other thing is the tag stays in whatever position it is on page load, so it can be in an odd place when the user scrolls the whole thing horizontally if horizontal scrolling is required at load: This could be fixed by pulling the tag out of the whole span.katex and placing it below the equation and aligning it right. This would allow the equation to be scrolled left-right, while leaving the tag in place. I'll leave this as an exercise for the reader :p Hopefully one or other approach is useful. |
Thank you, @mbourne! For those of you wanting a quick way to implement their solution in your own work, including the following in the
Then, you can write your equations like this in
|
Hi, The following css overrides work for me to make a long equation scroll horizontally and have its tag floated to the right side.
Using the :has css function we can recognise if the .katex-html element contains an inline equation or not by checking if a .tag is present. This :has function is not yet available on firefox, where the above css makes the tag still skip a line, but I can live with that. For all other browsers, this solution works (see here). |
Nota bene: Please forgive me if my ignorance in Katex internals is making me propose something dumb.
Describe the bug:
Hi guys, thanks for maintaining this package!
As you can imagine for the tittle of this issue I'm struggling with the
\tag
overlap when displaying web pages in mobile devices. For example this equation:I was trying to solve this by overriding the CSS with this:
And it works!:
Sadly, the inline math expressions break:
Before:
After:
I think it is because both, the inline and block styling, share the same CSS classes. So I want to ask you, what if you use a different CSS class for inline and block styling?
If we have different classes, we can leave inline styling as it is and use the code snippet above just for block equations.
Actually, it might be possible to just add an extra class indicator when inserting a block element, something like
katex-block
at the end of thespan
class property, like this:In this way
katex-block
will have the CSS code snnipet above.(La)TeX code:
The code of (La)TeX you tried to render:
Expected behavior:
The equation number should appear at the right of the equation, not over it.
Environment (please complete the following information):
Thanks!
The text was updated successfully, but these errors were encountered: