user202729 / TeXlib

Miscellaneous TeX libraries.
7 stars 0 forks source link

unicode-math-input: ensuremath option #7

Open mstarodub opened 1 month ago

mstarodub commented 1 month ago

First of all, thank you for this amazing package.

I would like to be able to use unicode characters without having to enclose them in $ ... $. (The argument against this boils down to personal preference and "it teaches the user bad habits", which I do not subscribe to.)

Would it be possible to provide an option in unicode-math-input that wraps everything in ensuremath? Alternatively, what would be the best way to patch (patchcmd) it, in your opinion?

user202729 commented 1 month ago

I guess there's https://tex.stackexchange.com/questions/70629/why-are-so-many-symbols-restricted-to-math-mode as well. For comparison I guess it's something like Python forcing you to wrap all strings into double quotes instead of interpreting any undefined names as a string (like Mathematica)…?

Anyway, I'll take a look.

user202729 commented 1 month ago

There are quite a few things that need to be rewritten. So it's not as simple as a few patchcmd.

Experiment: unicode-math-input.zip

Notice that if you write ½ outside math mode then the output will be different with and without the package (without the package the symbol ½ in the current font would be printed, which if compiled with pdflatex and \usepackage[T1]{fontenc} there would actually be such a character).

There's a caveat that if you write ² outside math mode then the following space will be deleted. This needs some serious rewrite of the super/subscript lookahead logic to fix. and doesn't work in text mode either.

mstarodub commented 1 month ago

Thank you so much, this works like a charm. Tested it with my thesis. Would love to have this on the CTAN, so I'll leave this issue open.