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 find the question and accepted answer to Allowing line break at ',' in inline math mode? very useful, BUT I would like to make an environment (e.g. "allowbreaks"} out of it. The problem is that I'm not able. Let me explain the idea:

\begin{allowbreaks}
Commas are modified in such a way that they allow breaks in
inline mathmode $(a,b,c)$ only within this environment.
\end{allowbreaks}

Is it possible somehow, please?

edit: I renamed the environment to allowbreaks, because of naming conflicts with the command allowbreak.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can locally modify the behavior of the comma, allowing a break. The trick is to make it "math active":

\documentclass{article}
\newenvironment{allowbreaks}
  {\mathactivatecomma
   \mathcode`\,=\string"8000
   \ignorespaces}
  {\ignorespacesafterend}

\newcommand{\mathactivatecomma}{%
  \begingroup\lccode`~=`\,
  \lowercase{\endgroup\edef~}{\mathchar\the\mathcode`\,\penalty0 }}

\begin{document}
\parbox{1cm}{abc def
\begin{allowbreaks}
$a,b,c,d,0,1,2,3,4,5,6,7$
\end{allowbreaks}
haaa 
$a,b,c,d,0,1,2,3,4,5,6,7$}
\end{document}

You'll see that the first math formula is broken, while the second one isn't.

However, the method proposed in this answer of mine is, in my opinion, better: use \mathlist{a,b,c,d} for a list of math variables that can be broken at commas.

share|improve this answer
    
Thanks, but @Herbert's method seems to perform slightly better at formatting. The \mathlist option is surely very interesting and I'll probably end up using it some other time, but at the moment possibly breaking at every comma is exactly what I want to achieve, since the variables I'm listing are quite long tuples. –  Riccardo Jun 11 '12 at 13:35
1  
Herbert's solution seems slightly better at formatting. Actually it isn't. –  egreg Jun 11 '12 at 13:55
add comment
\documentclass{article}
\newenvironment{allowbreaks}
  {\mathcode`\,="213B}
  {}

\begin{document}
\rightskip=11cm
foo $1,2,3,4,5,6,7,8,9$
foo bar baz

\begin{allowbreaks}
foo $1,2,3,4,5,6,7,8,9$
foo bar baz
\end{allowbreaks}

foo $1,2,3,4,5,6,7,8,9$
foo bar baz

\end{document}

enter image description here

share|improve this answer
    
Cool, it looks just perfect. Thanks! –  Riccardo Jun 11 '12 at 13:36
    
This adds spaces on both sides of the comma; they don't appear here because the formulas are shrinked at their maximum. –  egreg Jun 11 '12 at 13:56
    
Woops... thanks for pointing it out @egreg, I didn't noticed it before! –  Riccardo Jun 11 '12 at 13:59
add comment

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.