ChHecker / unify

Format numbers, units, and ranges in Typst correctly.
MIT License
23 stars 17 forks source link

Adding Imperial Units #30

Closed schmic41 closed 4 months ago

schmic41 commented 5 months ago

(For context, I submitted an "add imperial units" PR a few weeks ago, and the maintainer asked if it could be used with the new language feature.)

Having looked at the new code, imperial units can be added. It would consist of adding an imperial entry to the existing lang-db, and parsing a corresponding imperial.csv file. Since there is currently no language referred to as imperial, there is no risk of a namespace clash when more languages are added.

This does not exactly copy siunitx's behavior (there, the "preferred solution" is to use \DeclareSIUnit; here, that would require either downloading a local copy of the package or going through some complex state.update maneuvers). However, it does not create any conflicts with existing code, and it is unlikely to create namespace collisions with future code.

If there is interest in adding imperial units, I can create a PR.

I am interested to read any thoughts on this. Please let me know if you need any additional information. Thanks!

ChHecker commented 5 months ago

This would require changing the language of the whole language, right? Wouldn't that mess up other locales?

schmic41 commented 5 months ago

You are right, it would. I was imagining switching between locales working something like:

#set text(lang: "imp") 
$ qty("3.141", "lb/in")$
#set lang(lang: "ru")
[...]

but, after looking deeper into how Typst handles locales, it looks like doing this would break too much -- hyphenations, decimal separators -- even in that small region of code.

That leaves two options: first, they could be added to the main units.csv file, manually prefixed to avoid conflicts with metric units: imp-in, imp-ft, imp-mi, and so on. Or, I can just bite the bullet and look into forking the code.