Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like text like

\((\abcdefghij,\abcdefghij)\)-pair

(with \abcdefghij defined as \textit{abc\-defg\-hij}) to be hyphenated as

(abc·defg·hij,·abc·defg·hij)-·pair

("·" indicates all possible linebreak points; there would of course need to be hyphens if the adjacent characters on both sides are letters). Let's assume that I need a macro like \abcdefghij in many places in the document. How can I achieve the intended hyphenation?

share|improve this question
1  
Don't. If it's hyphenatable, it's not math. –  egreg Feb 2 '13 at 11:04
    
@egreg Good point. I think the cases where I'd like to do this are defensible because they are a certain type of textual material. But I wouldn't hyphenate numbers, because that just might lead to trouble ;-) –  Lover of Structure Feb 3 '13 at 11:54

2 Answers 2

up vote 5 down vote accepted

Hyphenation works in math as long as you are not inside a {} group which is essentially an \hbox in math mode. \begingroup groups are OK though.

As you did not provide a MWE (grumble) I stole one from Hendrik's answer.

enter image description here

\documentclass{article}
\newcommand*\abcdefghij{%
  \begingroup\mathit{\xdef\tmp{\fam\the\fam\relax}}\tmp
  abc\-defg\-hij\endgroup}

\begin{document}
\noindent
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and to end with, one last
\((\abcdefghij,\abcdefghij)\)-pair.
\end{document}
share|improve this answer
    
+1, this is for sure better than what I propose. (By the way, I noticed that often you don't crop your images. Is this on purpose?) –  Hendrik Vogt Feb 3 '13 at 7:22
    
Thanks! If I replace \mathit by \textnormal or \texttt{\textit{[...]}} or \textrm{\sbfont\selectfont[...]}, I can't get it to work. I looked for other TeX primitives like \fam but couldn't find any. Any thoughts? –  Lover of Structure Feb 3 '13 at 9:14
    
the \text... commands are \hbox so don't allow line breaking, nothing special about \mathit there though \mathrm or \mathsf etc will all work. –  David Carlisle Feb 3 '13 at 10:34
    
@HendrikVogt well I crop by eye normally in an editor, often I pick up the page margins just to show layout, here I seem to have been a bit generous with white space for no particular reason:-) –  David Carlisle Feb 3 '13 at 10:36

One way to achieve the intended hyphenation is to put the "syllables" into separate \textit commands, separated by discretionary breaks \-. (This interferes with the kerning in abcdefghij, but works reasonably well.) To allow a line break after the comma, you can use the code from this answer by egreg.

output

Note that I put an italic correction \/after the j so that it's not that close to the closing parenthesis anymore.

\documentclass{article}
\newcommand*\abcdefghij{\textit{abc}\-\textit{defg}\-\textit{hij\/}}
\AtBeginDocument{%
  \mathchardef\mathcomma\mathcode`\,
  \mathcode`\,="8000 
}
{\catcode`,=\active
  \gdef,{\mathcomma\discretionary{}{}{}}
}
\begin{document}
\noindent
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and a 
\((\abcdefghij,\abcdefghij)\)-pair and to end with, one last
\((\abcdefghij,\abcdefghij)\)-pair.
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.