3

In horizontal mode, the pre-break, post-break and no-break texts of a \discretionary can contain any combination of characters, boxes and kerns. In math mode, however, the no-break text must be void.

Is there any objective reason for this annoying constraint? And is there any hope to see it relaxed in a future version of LaTeX? (And, let us make a wish, if \hyphenchar could also call a macro instead of a character of the same font only...)

This is maybe possible with LuaTeX or XeTeX, but I would like to stick to standard (pdf)LaTeX (including e-TeX).

1
  • 1
    I'm not aware of any plans to extend (pdf)etex other than bug fixes so I fear that there is little hope of this changing given the restrictions you place. Commented Feb 27, 2017 at 13:52

1 Answer 1

4

I suspect that this is unlikely to change, however since line breaking can only happen at the top level in inline math, not inside any group, you can often just avoid the restriction by breaking the math list, so

\documentclass{article}

\def\mdiscretionary#1#2#3{%
{}$\discretionary{\hbox{$#1$}}{\hbox{$#2$}}{\hbox{$#3$}}${}}
\begin{document}


aaa\discretionary{X}{Y}{Z}aaa

\bigskip

\parbox{1cm}{\raggedright aaa\discretionary{X}{Y}{Z}aaa}

\bigskip


$aaa\mdiscretionary{X}{Y}{Z}aaa$

\bigskip

\parbox{1cm}{\raggedright $aaa\mdiscretionary{X}{Y}{Z}aaa$}



\end{document}

shows unbroken text with text Z and broken text with text X and Y, and then the same with math.

enter image description here

The code that implements the restriction in the tex.web source of tex is documented as

@ The three discretionary lists are constructed somewhat as if they were hboxes. A subroutine called build_discretionary handles the transitions.

(This is sort of fun.)

Which doesn't give a lot of insight into why the restriction is there, unfortunately.

4
  • This is a solution, but not a very convenient one because, when you switch to horizontal mode and back to math mode, you lose the default spacing between math atoms. Commented Mar 1, 2017 at 10:39
  • Regarding tex.web, a few lines below the one you mention, one finds the warning message obtained when compiling: "Sorry: The third part of a discretionary break must be empty, in math formulas. I had to delete your third part." Still, this does not explain why this is so. I was wondering if there was some technical constraint in math mode, but it looks more like a stylistic choice. Commented Mar 1, 2017 at 10:45
  • @MichelFioc I didn't chase down the details but I would guess there was a complication in "appendix G" converting the math list that he wanted to avoid. If the no-break text can be non empty then the possibilities for the relative lengths of the text with or without a break can be a bit more interesting, but as I say I didn't check exactly if anything would go wrong Commented Mar 1, 2017 at 11:03
  • @MichelFioc agreed it's not that convenient but without changing tex-the-program it's probably as convenient as there is:-) I added {} to the broken math lists which make mathords so the spacing of the re-constructed expression will be as if the discretionary was a mathord. That may or may not be what is required, of course you could give \mdiscretionary some options to control that, perhaps... Commented Mar 1, 2017 at 12:32

You must log in to answer this question.

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