We need to have enough space for the longest of the two sub-/superscripts. For that we can calculate the maximum of both sub-/superscripts' widths and make a box as wide as the maximum:
\documentclass{article}
\usepackage{fixltx2e} % For \textsubscript
\makeatletter
\newcommand{\textsubsuperscript}[2]{%
\begingroup
\settowidth{\@tempdima}{\textsubscript{#1}}%
\settowidth{\@tempdimb}{\textsuperscript{#2}}%
\ifdim\@tempdima<\@tempdimb
\setlength{\@tempdima}{\@tempdimb}%
\fi
\makebox[\@tempdima][l]{%
\rlap{\textsubscript{#1}}\textsuperscript{#2}}%
\endgroup}
\makeatother
\begin{document}
A\textsubsuperscript{x}{yyy}B
A\textsubsuperscript{xxx}{y}B
\end{document}

I refrained from using mathmode and \text
because \textsuperscript
and \textsubscript
may have more complex implementations than it would seem (see realscripts
, for example).
Your problem is not arising due to the citation, but only stems from the uses of superscripts. Whenever superscripts are used, they are intended to be short. Hence line breaks are neither nice nor possible.
The technical reason for this is, that LaTeX will wrap the text given in \superscript{}
into a box, which is the raised. This box is the treated like any other box. Depending on the given penalties, the line will break before the superscript
or not at all.
To illustrate this problem:
\documentclass{article}
\usepackage[showframe]{geometry} %to show page borders
\begin{document}
%\blindtext
The text in this a paragraph is only to show effectis of superscripting.
No linebreak is allowed in the superscript.
Hence it will extend into the margin.
Dummy text and text for dummies\textsuperscript{see this superscript here}.
And we will continue with even more dummy text.
If you reduce penalties, the line will break before \verb|\textsuperscript|.
This can be done on-the-fly with \verb|\sloppy|. (It is not a nice solution, though.)
\sloppy
The text in this a paragraph is only to show effectis of superscripting.
No linebreak is allowed in the superscript.
Hence it will extend into the margin.
Dummy text and text for dummies\textsuperscript{see this superscript here}.
And we will continue with even more dummy text.
\end{document}
This will give:

A rather nasty workaround is to use the \sloppy
command (or environment).
The more elegant way is to shorten or lengthen the sentence to fit the superscripted section onto the line. An even better way is to try to avoid long superscripts. (As far as I remember, natbib
comes with a sort+compress option.)
As far as I know, there are no right answers when it comes to citations.
However, if a citation refers to a phrase in particular, it should follow immediately. If a citation refers to a (half-) sentence, it should be referred after the punctuation.
As far as citations go, I would recommend switching to the biblatex
package, as it is much more flexible. It also provides the above mentioned behaviour out of the box.
Best Answer
without using directly math and with colors: