# Using OverBarred variables

Mathematica does not seem to treat variables as a unit. Consider the following:

rule = a -> Function[{x}, OverBar[a][x]]
test = a[x] /. rule;
test /. rule


It seems to apply the rule again on the last line, which of course is not what I want (in the sense that a and OverBar[a] are supposed to be different things). I tried to use the Notation package but was rather unsuccessful. Is there a way to make this work?

You want to replace a with Overbar[a], but only if it isn't already inside Overbar. So make Overbar[a]->Overbar[a] your first replacement rule, and it will be protected from further replacements:
rules = {OverBar[a] -> OverBar[a], a -> OverBar[a]};