3

I've got a document where I have some issues with line breaks. I've got three pairs of math-mode terms, separated with hyphens and with parentheses around two of the terms. I want it to break only between a right parenthesis and a left parenthesis. How do I do that, and what is the most appropriate choice of hyphen, e.g., -, em, en. Also, is it better to put the outer hyphend in the Math-mode text rather than adjacent to it?

\documentclass{article}
\begin{document}
A long line of  text written in order to see where the construction breaks.
($fooleft$-$fooright$-)%
($barleft$-$barright$)%
(-$bazleft$-$bazright$)
\end{document}

Based on a suggestion from egreg I changed the markup and it almost works, but it puts extraneous space between terms:

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\donotbreak} {m}
    {
      \mbox{#1}\discretionary{}{}{}%
    }

\NewDocumentCommand{\nobreaks} {>{\SplitList{,}}m}
    {
      \ProcessList{#1}{\donotbreak}
    }

\begin{document}
A long line of  text written in order to see where the construction breaks.
\nobreaks
  {%
    ($fooleft$-$fooright$-),%
    $barleft$-$barright$,%
    -($bazleft$-$bazright$)
  }

\end{document}
1
  • You have unprotected end-of-lines in the definitions.
    – egreg
    Aug 27, 2019 at 16:52

1 Answer 1

2

Put the parenthesized parts in a box, so it can't be split; between them we can use \discretionary{}{}{} to allow a line break.

\documentclass{article}
\usepackage{xparse}

\NewDocumentCommand{\bunchofparens}{>{\SplitList{,}}m}{%
  \ProcessList{#1}{\makeparens}%
}
\NewDocumentCommand{\makeparens}{m}{%
  \mbox{(#1)}\discretionary{}{}{}%
}

\begin{document}

Text written to see where the construction breaks.
\bunchofparens{$fooleft$-$fooright$-,$barleft$-$barright$,-$bazleft$-$bazright$}

\end{document}

enter image description here

6
  • I'm already using xparse, but I hadn't looked at argument processors yet. What about the secondary question; should I be using -, or would it look better with --, --- or $-$, and should I be using the same dash within and between pairs. Thanks.
    – shmuel
    Aug 26, 2019 at 19:55
  • @shmuel That's a question of taste. No idea, without seeing a “real world” example.
    – egreg
    Aug 26, 2019 at 19:56
  • One example is arxiv.org/ftp/arxiv/papers/1906/1906.11690.pdf on page 61.
    – shmuel
    Aug 26, 2019 at 20:53
  • @shmuel Definitely a hyphen.
    – egreg
    Aug 26, 2019 at 21:37
  • Please see my edit; I'm getting extraneous space. Would it be easier to do things with a clist variable and concatenate all of the markup?
    – shmuel
    Aug 27, 2019 at 15:43

You must log in to answer this question.

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