Display different form of user's name to different users?
Reference: http://drupal.org/node/1194546

Basically, the easiest way to do this involves a couple steps:

First, implement hook_username_alter() in your custom module to change the username dynamically, depending on the context of the username's display (you can, for example, load the global $user object and display one form of the account in question's name to $user's with the role 'teacher', and another form to $user's with the role 'authenticated'...

Second, you will only be able to dynamically control the username as returned by $user->name or by theme('username', account) using hook_username_alter(). You can't change a username dynamically via realname, because that module stores the name in the database and caches it for performance reasons.