This is by no means ideal, but you could define the breakpoint as a \discretionary{<pre-break>}{<post-break>}{<no-break>}
:
\documentclass{article}
\usepackage{showframe}% Just for this example
\newcommand{\AB}{%
\textsf{A}%
\discretionary{\mbox{ is}}{\mbox{contained in }}{\mbox{${}\subseteq{}$}}%
\textsf{B/string}%
}
\begin{document}
\AB
Some text to fill the line width with characters and then we have the \AB.
\end{document}
The reason why it's not ideal is that \mbox
removes any of the inter-word spacing adjustments typical of making lines fit within the horizontal width. So, the spacing between A
and is
and contained
, in
and B/string
might be slightly different from surrounding inter-word spaces. However, this depends heavily on the context of the paragraph it's used in, and might not be visible under most conditions. Sentences with long words (having few inter-word spaces) might emphasize this.
\AB
by defining it as{\mbox{$\textsf{A} \subseteq \textsf{B/string}$}}
. It is a short-enough expression that it will hopefully not break any alignments.