Skip to content
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

Line breaks sometimes happen immediately after an inline KaTeX block #1233

Open
akalin opened this issue Mar 21, 2018 · 5 comments

Comments

@akalin
Copy link

commented Mar 21, 2018

This is undesirable if e.g. a comma follow an inline equation.

This seems to happen to me most often on Chrome for Linux (Ubuntu 17.10), but I'm not 100% sure I haven't seen it on Chrome for Mac.

Example gist with display. If you adjust the right border of the browser window, you can get it to break between "A = (ε_0 + H)/2" and its following comma.

I'm not sure if KaTeX has much control over this behavior, but I figure I'd report it in case anyone has any ideas.

Screenshot:

screenshot from 2018-03-20 23-36-23

@akalin

This comment has been minimized.

Copy link
Author

commented Mar 21, 2018

Writing the equation as "A = (ε_0 + H)/2\text{,}" does work in this case, but it would be nice not to have to do that. (Also, I'm not 100% sure that it sometimes doesn't break between the two anyway.)

@edemaine

This comment has been minimized.

Copy link
Member

commented Mar 21, 2018

I've encountered this too, and tweaked my own KaTeX preprocessor to put following punctuation inside any math blocks. This definitely works, as KaTeX doesn't support any line breaks within a math block.

It'd be nice if there'd be a pure CSS workaround... Alternatively, auto-render and a solution to #604 (which I'm imagining roughly following the code linked above) could implement this hacky solution.

@akalin

This comment has been minimized.

Copy link
Author

commented Mar 22, 2018

Ah, cool, glad to hear this is a known thing. I was considering modifying auto-render, too, but I don't quite understand what #604 has to do with it. My idea would be as follows:

  1. After autorender splits up a piece of text into a list of text and math blocks, but before it renders the math...
  2. For each text block following an inline math block, if some option is set with a string of punctuation, or a regexp or something...
  3. If the beginning of the text block matches the punctuation string/regexp, wrap it in a \text{...} fragment and append it to the previous inline math block. Looks like you use a nobr span; that might work, too.

Would this be something that would be useful to have in auto-render (i.e., would a patch be accepted), or should I expect to just have it for myself?

@kevinbarabash

This comment has been minimized.

Copy link
Member

commented Apr 4, 2018

I'm surprised/disappointed that browsers don't keep the punctuation on the same line unless it follows a space.

@Reedbeta

This comment has been minimized.

Copy link

commented Sep 24, 2018

I'm seeing this issue too. From a bit of experimentation in Firefox dev tools, it appears this is related to the use of display: inline-block on KaTeX spans. If I remove that property from .katex .base, then the browser no longer puts line breaks between inline math and punctuation.

However, removing display: inline-block also messes with the vertical spacing around math blocks (both display and inline), so that's not a complete fix in itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.