FYI, the built-in function GCD will compute the greatest common divisor of two numbers. It is in the manual section.
As to writing scripts, there is, again, a short description in the manual. You write them the same as you write one in a regular document. Trivial example
a = x^2
b = y^2
c = -z^3
You can then compile the MS document and then include the compiled file in other MS documents and use the scripts you compiled there. For example, say the above function is saved in a document called 'sample'. You can then compile it and when you need to refer to it, you add Include('sample') in whatever MS document you are working in.
Units in MS are a bit limited in my opinion. I know of no way of extending the unit type etc. I use my own unit conversion routine.