I’ve been looking for a solution to this problem for sometime, and I finally found it.
Letters with all kinds of marks above them, called diacritical marks, are used very often in courses based on maths. The marks have interesting names like bar, hat, curl, cup, etc. Added on the letter x, for instance, they would look like this: x̄ x̃ x̂ x̅ x̆ ẋ ẍ x̊ x̋ x̌ x̍ x̎ x̐ x̑.
Here’s how I do it on my computer, which runs Kubuntu, a system based on the Debian distribution of Linux/GNU:
Type the letter you want (x, for example).
Press alt-I P to insert special characters.
You’ll find OK on the upper right corner of the window, as usual.
To the left of OK, you’ll find a choice of character sets: Basic Latin, Basic Greek, Arabic, Cyrillic, etc. What you want is the set that says Combining Diacritical Marks.
If you choose any of these diacritical marks, they will appear not after the preceding letter, but above it. Like magic.
Make sure you stay within the Combining Diacritical Marks set. I got confused because another set of similar marks comes before this set, but this set is called Spacing Modifier Letter, which doesn’t work.
The method I describe above works on Kubuntu/Debian v8.04. Please leave a comment if it works on your Linux/GNU distribution too.