Keyboard layout for math I usually need to write math with LaTeX, and after seeing this question: Entering unicode math symbols. I came here with some small questions.

I find that not perfectly comfortable, and I was wondering if there is a way in which I could tell the system to differentiate between the left and right alt ⌥. So I could have much more symbols within one letter.

And, the another question is if there is a way I could turn the caps lock ⇪ into a different key (with the same use as alt ⌥, but the system should differentiate them). In this way I could use, for instance,


caps lock ⇪d to get the greek letters (in this case the letter delta δ), and
alt ⌥d to get some math symbol of my decision (in this case the partial differential symbol ∂).


This is not a great example, but more or less self explaining. Of course then caps lock ⇪ shouldn't be a turn on/turn off button. It should be turned on ONLY when pressed (exactly like alt ⌥).
I believe this is all possible. In my answer on TeX.SE, I give the MathUnicode.keylayout file that I made. Essentially, my advice is: go ahead and play around with this file. 

A couple of thoughts:


The XML specification for .keylayout files is available from Apple.
On line 22 you can see that I refer to the anyOption modifier. This refers to the left or right option key. But you can also write option or rightOption if you wish to distinguish between the two.
I'm not sure whether caps can be treated as a "hold down" key, as you want it, rather than a "press on / press off" key.