2

Given a command like this

\newcommand{\AB}{$\textsf{A} \subseteq \textsf{B/string}$}

is it possible to have the string evaluate to something like

\newcommand{\ABhyp}{\textsf{A} is contained in \textsf{B/string}}

if TeX determines to hyphenate \AB or if there will be an overfull box using \AB?

1
  • I don't know how to answer your question. However, you might consider preventing hyphenation in \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. Commented Aug 13, 2015 at 14:35

1 Answer 1

3

This is by no means ideal, but you could define the breakpoint as a \discretionary{<pre-break>}{<post-break>}{<no-break>}:

enter image description here

\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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .