Atreyagaurav / litex-mode

LiTeX mode for emacs; A minor mode to convert valid lisp expressions to LaTeX
GNU General Public License v3.0
43 stars 4 forks source link

Support conversion from Greek letters to LaTeX variables #12

Closed Bu156 closed 2 years ago

Bu156 commented 2 years ago

This is not ready yet, as I made the assumption that all Greek characters have an associated LaTeX command when the reality is that some, like Α (capital α) and Ρ (capital ρ), don't due to them being visually indistinguishable from the Latin script.

Bu156 commented 2 years ago

That is now fixed, I would love to get feedback on this

Atreyagaurav commented 2 years ago

Hi it looks ok, though I guess the code became longer due to the alist.

One small addition though, would it be possible to not put \\ in the alist and only use alphabet name, and use rassoc on it to also detect the strings and then convert them into \\ thing later. with another customizable variable to decide whether to do it or not.

For example, right now it can do (+ α 2) to \alpha + 2, but what I want to add is another configurable option which can make (+ alpha 2) to \alpha + 2, since we already have the list we can do that for the members of this list only. So that people who can't input unicode can also use greek letters that way. And if they don't want it to mess up, they can just turn that off.

Bu156 commented 2 years ago

I think this should do it, works according to my tests.

One thing that I found that my code doesn't account for is if you calculate for example difference in time, Δt, that will not convert because it is a Greek glyph in a word, while I think it would be desirable to have that also be converted. I don't know yet how I'd handle this case, though.

Atreyagaurav commented 2 years ago

Oh yeah I didn't think about Δ instances for difference, god I just wish unicodes would work everywhere so we wouldn't have this hassle.

But at least one problem is down, feel free to make a pull request if you found a way though.

Bu156 commented 2 years ago

I accidentally removed the part of the diff which removes \\ from the alist. I'm not too familiar with pull requests but make sure you merge my latest commit.

Atreyagaurav commented 2 years ago

I noticed that after merging, no worries I've already edited that locally.

Also I think I might find a workaround for Δt situation, for now I have something like this: α-Δ/t-2{\\alpha}_{{\\Delta}t}_{2}. basically if you want to separate a variable to convert use / that'll make variable name valid while also making it easier to detect, and separate by - for subscripts (which was already the case). It's not that pretty but it works I think.

Test it and let me know if you have time. It's in branch https://github.com/Atreyagaurav/litex-mode/tree/9-greek-letters

Bu156 commented 2 years ago

It works well from my testing 👍‍