-
Notifications
You must be signed in to change notification settings - Fork 4
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
Shouldn't whitespace characters be escaped as well #15
Comments
I'm not opposed to the idea, but since I haven't used LaTeX in a while I'd need some help implementing that functionality, could you give me some pointers about:
|
I'm not too deep into This would be useful not only in math mode but also in normal text if multiple whitespaces should produce multiple ones in the output. One thing I'm not sure about is if this is something that should be enabled by default or require a configuration option (like a second parameter for example). The actual escaping can be done using a regex that is applied after all previous replacements are complete. I can make a pull request if you want, once the technical details have been agreed upon. |
Thanks for the quick response, here are a few quick thoughts I have before I leave the office:
I'll mull over this a bit more this weekend, but feel free to put your thoughts here if you have any. |
Thank you for responding to me. This is your library after all. I agree with your points about different types of escaping and that they should be separate.
For replacing whitespace this isn't an issue at least, because it only requires one replace via a regex after all the previous replacements are finished. But I will have to take a closer look at your implementation again. |
And if recursion is an issue, it just has to be rewritten procedurally in a loop. It might make sense to first find all the matches, split up the string into those and then replace them one by one by a simple lookup. |
Quick progress update: I've modified the algorithm to be iterative instead of recursive and it doesn't overflow the stack anymore for very large strings. I'll tackle the different type of escapes in the next couple of days. |
I've added a param that let the user choose whether to preserve formatting or not, and also one that lets them modify the escape mapping if they so choose. At this point, we should brainstorm about which characters that should be formatted. I'll do some research about it in the next couple of days, do you have suggestions in the mean time? |
Thanks! For now I can only think of space -> |
Do you think we need one for |
Strange, for me they do. But not in math mode though. But I think it is just not possible in math mode. (at least not without doing any matrix tricks or similar. |
Sorry it took me a long time to get back to this. I've published a beta version that contains the new changes we've discussed in this issue, you can try it by running:
The README has the most up-to-date API for the library. Feel free to try it out and let me know what you think. I'll push the actual release version in about a week if nothing is wrong with the beta version. |
I just started integrating the new version and it generally works great, but there is one problem that has to be taken into account: If a word follows a tab or newline, it breaks the I think this can be fixed by adding an additional |
Thank you for spotting that! I totally forgot about that case 🤦♂️ I've pushed version |
Your beta2 doesn't actually have the fix in it! |
(either that or there is a bug in npm) |
Nope no bug on npm side, just carelessness on my part! 😊 I've pushed |
Now I've tested it and it works great. I haven't tested the functions that allows changing the escape map though. |
Ok great, I'll close this issue and release the final 1.0.0 version soon. Feel free to open another one if you need more escape characters or anything else. Thanks for the help 🥇 |
Great, thanks a lot! |
I'm not sure if this is something that you want for this library, but since I'm trying to use it to display a string mostly as is in LaTeX, it would be really useful if it would replace whitespace characters as well, because otherwise I would have to do it myself.
See josdejong/mathjs#995
The text was updated successfully, but these errors were encountered: