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

Add support for % comments #20

Closed
xymostech opened this issue Aug 30, 2014 · 21 comments
Closed

Add support for % comments #20

xymostech opened this issue Aug 30, 2014 · 21 comments
Assignees
Milestone

Comments

@xymostech
Copy link
Contributor

No description provided.

@xymostech xymostech self-assigned this Aug 30, 2014
@xymostech xymostech added this to the Version 1.0 milestone Aug 30, 2014
@sophiebits
Copy link
Contributor

mrrh?

@xymostech xymostech modified the milestones: Version 1.0, Version 1.1 Sep 3, 2014
@alexirpan
Copy link

Poking this. It turns out the kramdown engine turns 0 < 1 into

% <![CDATA[
0 < 1 %]]> 

The intention is that it gets wrapped to properly escape the < sign, and the wrapping gets commented out in the rendering.

kramdown is the main markdown engine for Github Pages, so this is a barrier for setting up KaTeX on blogs hosted there.

@sophiebits
Copy link
Contributor

That's clever. CDATA isn't even valid in HTML5 though (only SVG and MathML): https://html.spec.whatwg.org/#cdata-sections.

@meygerjos
Copy link

Kramdown has a workaround now. But KaTeX should still fix this.

@kevinbarabash
Copy link
Member

I was thinking of pre-processing the input to remove the comments, but we probably don't want to do that b/c then an error reporting would have the wrong position information.

@edemaine
Copy link
Member

Can't this be done in the Lexer? Just add comment pattern to the regex, but don't return upon a comment match.

@kevinbarabash
Copy link
Member

I think %[^\n]*\n should do the trick.

@xsznix
Copy link
Collaborator

xsznix commented Sep 14, 2017

Perhaps %[^\n]*(?:\n|$) so that it allows comments at the end of the expression?

@sophiebits
Copy link
Contributor

%.*?\n? is also equivalent to @xsznix's in case you need more ways to do this.

My "mrrh?" comment was ambivalence about the correct answer. I'm not sure it makes sense to allow it at the end of an expression – since you can't do $x%y$ in TeX without a newline. Maybe it does.

@kevinbarabash
Copy link
Member

kevinbarabash commented Sep 14, 2017

pdflatex throws an error in that situation which means that people copy TeX code into KaTeX won't be include code with comments like that. Things might go wrong copy/pasting a KaTeX string back into a .tex file, but users will have to modify the string anyways by add $. If we support comments a person should be able to type a^2 + b^2 = c^2 %% Pythagoras' theorem into a text input and have that work without having to add a newline at the end of it before they pass it to katex. My vote would be to allow comments without a newline at the end of the string.

@sophiebits
Copy link
Contributor

The fact that this exists feels like a small argument in favor of not supporting ending comments:

https://github.com/Khan/KaTeX/blob/a358c5a94c86a13bd3381334c9ad4ca23cd57781/dockers/texcmp/texcmp.js#L62

@kevinbarabash
Copy link
Member

We could change that to

let tex = "$" + itm.tex + "\n$"

😛

@sophiebits
Copy link
Contributor

Yes, but only if you're expecting this behavior! The fact that it isn't that already indicates that you wouldn't. Someone else might equally try to build a web writing interface that accepts KaTeX and turns into a full TeX document later and be bitten by this.

@kevinbarabash
Copy link
Member

We could have an option to allow comments without newlines, but have the default be strict LaTeX compliance.

@sophiebits
Copy link
Contributor

sophiebits commented Sep 14, 2017

In Perseus (or auto-render), I also wouldn't want typing $x%y$ to render a mathy x. It's confusing.

What's the value in allowing comments without newlines? If you really want to do that you can always just tack on a newline to the input expression when calling KaTeX.

@edemaine
Copy link
Member

IMHO, if $x%y$ causes x%y to get passed into KaTeX, then that's a mistake: that second $ shouldn't be considered a terminator when it's hidden by the comment. Of course, that is how it works now with auto-render, but in my opinion that's a bug in auto-render.

I guess I can't imagine a setting where x%y really makes sense as input to KaTeX, so I'd be OK with requiring a \n at the end of the comment regex.

@kevinbarabash
Copy link
Member

I'm okay with that too. The best justification I could come up with is that it would all writing comments in our test app, but that isn't much of a justification. Our test app should be modified to use a <textarea> instead so that it's easy to test comments locally.

@xsznix
Copy link
Collaborator

xsznix commented Sep 15, 2017

Yeah, it sounds like allowing a comment to end a math expression would not be expected behavior. I rescind my suggestion.

@kevinbarabash
Copy link
Member

I'm going to give this a shot.

@kevinbarabash
Copy link
Member

screen shot 2017-09-15 at 12 32 45 am

kevinbarabash added a commit that referenced this issue Sep 15, 2017
@edemaine
Copy link
Member

edemaine commented Sep 15, 2017

@kevinbarabash <textarea> would be very handy when testing arrays and such, thanks!

You should test spacing behavior:

\text{hello% comment
world}

should parse like \text{helloworld}, but not like

\text{hello% comment

world}

(oops, moving this discussion to #884)

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

No branches or pull requests

7 participants