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

Error with single backslash at end of line #2860

Closed
pdmosses opened this issue Mar 27, 2021 · 2 comments · Fixed by #2877
Closed

Error with single backslash at end of line #2860

pdmosses opened this issue Mar 27, 2021 · 2 comments · Fixed by #2877

Comments

@pdmosses
Copy link

Describe the bug:
(Copying from a fixed pandoc issue:)

In LaTeX you can use a backslash \ followed by any whitespace to produce a regular space, as opposed to an inter-sentence space. The whitespace needn't be a space; it could be a line break.

KaTeX treats a single \ at the end of the line as an error.

To Reproduce:
Steps to reproduce the behavior:

  1. Go to https://katex.org
  2. Type a single \ followed immediately by a line break.
  3. See KaTeX parse error: Undefined control sequence: \ at position 1: \̲ ̲.

Expected behavior:
It should produce a regular space instead of a parse error.

Screenshots:

Screenshot

Environment:

  • KaTeX Version: 0.13.0

Additional context:
MathJax allows a single backslash at the end of the line.

@pdmosses pdmosses added the bug label Mar 27, 2021
@pdmosses
Copy link
Author

The missing control sequence can be defined as equivalent to \ :

'\\\n': '\\ ',

A backslash followed by a tab character also gives a parse error, and could presumably be defined as a macro too...

However, line breaks and tabs should be equivalent to spaces not only in source text, but also in macro definitions. Perhaps \n and \t should be prohibited in macro names?

edemaine added a commit that referenced this issue Apr 3, 2021
LaTeX parses `\` followed by whitespace including up to one newline
as equivalent to `\ `.  (With multiple newlines, you get paragraph
breaks.)

Fix #2860.
ronkok added a commit that referenced this issue May 6, 2021
* fix: Correctly parse \ followed by whitespace

LaTeX parses `\` followed by whitespace including up to one newline
as equivalent to `\ `.  (With multiple newlines, you get paragraph
breaks.)

Fix #2860.

* Improve comments

* Avoid second RegExp match in control words

* Document capturing groups

Co-authored-by: Ron Kok <ronkok@comcast.net>
KaTeX-bot added a commit that referenced this issue May 6, 2021
## [0.13.6](v0.13.5...v0.13.6) (2021-05-06)

### Bug Fixes

* Correctly parse \ followed by whitespace ([#2877](#2877)) ([c85250d](c85250d)), closes [#2860](#2860)
@KaTeX-bot
Copy link
Member

🎉 This issue has been resolved in version 0.13.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants