Why can't I type a g̃ the same way I type ñ?
From what I have read, you are out of luck using standard xkb because, as you have found, with xkb the output of a dead key combo is either zero (if the second key did not match a valid sequence) or one Unicode code point.
I do not have an Ubuntu running X to test on, so I cannot test this suggestion, but I believe the solution for you is to switch to using uim, which supports multi-codepoint outputs from dead key combos. You can read about how to set up uim
at wikibooks or from this post (but do not follow the whole post, as it is solving a different problem).
The post I referenced shows how to get 'b to output the 2 character sequence 'b
while while still allowing 'a to output the single character á
. They solved it by making ' a dead key and then configuring the sequence dead 'b explicitly, and then repeating that for the 99 other characters on the keyboard. You do not have to go so far.
You already created the .XCompose
file you need. Switching to uim
should be all that is left to do.