9

So, here's the code I have:

\usepackage{amsthm}

\begin{theorem}
...could be now considered as an algebraic structure $DB_E =
\left\langle \mathbb{S},\allowbreak \mathbb{E},\allowbreak
f,\allowbreak \mathbb{V},\allowbreak \mathbb{R},\allowbreak
\mathbb{C},\allowbreak Op_a,\allowbreak Op_c,\allowbreak
Op_m \right\rangle$.
\end{theorem}

and here is the result (grey area denotes the edge of the page):

enter image description here

Obviously, \allowbreak does not do anything. Why is it?

  • Perhaps try '\mathlist' as shown here: tex.stackexchange.com/questions/19094/allowing-line-break-at-in-inline-math-mode-breaks-citations – rickhg12hs Jun 18 '13 at 7:14
  • 4
    Just don't use \left and \right, which in this case do nothing. Then \allowbreak will work. – egreg Jun 18 '13 at 7:51
  • 1
    Welcome to TeX.SE! I have two requests: Given the answer, could you edit the question title so that other people with a similar problem will find your question more easily? Could you also insert a few linebreaks in your code so that it will be easier for someone else to get an overview of your formula/text? :-) – Lover of Structure Jun 18 '13 at 8:34
12

This is another case for which \left and \right are not appropriate:

  1. there is no delimiter to increase the size of;

  2. the spaces after commas cannot participate to stretching or shrinking together with the other spaces in the same line;

  3. the formula is not breakable across lines under any circumstance.

So the first step to do is to remove \left and \right (and to disable any automatic feature in the editor). Then a carefully placed \linebreak[0] will help in the pagination.

\documentclass[a4paper]{article}
\usepackage{amsfonts,amsthm}
\newtheorem{theorem}{Theorem}


\begin{document}

\noindent\parbox{4cm}{
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \langle
  \mathbb{S},\mathbb{E},f,
  \mathbb{V},\mathbb{R},\mathbb{C},\linebreak[0]
  Op_a,Op_c,Op_m \rangle$.
\end{theorem}
}

\noindent\parbox{6.5cm}{
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \langle
  \mathbb{S},\mathbb{E},f,\linebreak[0]
  \mathbb{V},\mathbb{R},\mathbb{C},
  Op_a,Op_c,Op_m \rangle$.
\end{theorem}
}

\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \langle
  \mathbb{S},\mathbb{E},\linebreak[0]
  f,\mathbb{V},\mathbb{R},\mathbb{C},
  Op_a,Op_c,Op_m \rangle$.
\end{theorem}

\end{document}

enter image description here

| improve this answer | |
  • Note that, by default, there's no stretching or shrinking of the spaces after commas (\thinmuskip) in math. – Hendrik Vogt Jun 18 '13 at 15:31
  • @HendrikVogt There could be. ;-) – egreg Jun 18 '13 at 16:35
1

You could try the following middlebreak macro:

[not using at all \left and \right was better in your posted case, as pointed out in comments; but then look at the second proposal below for more general usage]

\documentclass{article}
\usepackage{amsfonts,amsthm}
\newtheorem{theorem}{Theorem}

% to be used within a \left \right pair
\def\middlebreak {\nulldelimiterspace0pt
\right.\allowbreak\mskip 0mu plus .5mu \nulldelimiterspace0pt\left.}%

\begin{document}

{%
\hsize 3cm
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \left\langle
  \mathbb{S},\middlebreak \mathbb{E},\middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},\middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m \right\rangle$.
\end{theorem}
}%

{%
\hsize 7cm
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \left\langle
  \mathbb{S},\middlebreak \mathbb{E},\middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},\middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m \right\rangle$.
\end{theorem}
}%

\begin{theorem}
...could be now considered as an algebraic structure $DB_E = \left\langle
  \mathbb{S},\middlebreak \mathbb{E},\middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},\middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m \right\rangle$.
\end{theorem}

\end{document}

middlebreak

\documentclass{article}
\usepackage{amsfonts,amsthm}
\newtheorem{theorem}{Theorem}


\newlength{\IrresponsibleFantasy}

\newcommand*{\ReserveVerticalSpace}[1]
   {\setlength{\IrresponsibleFantasy}{#1}\global\IrresponsibleFantasy=\IrresponsibleFantasy
    \parbox{0pt}{\rule{0pt}{\IrresponsibleFantasy}}}

\newcommand*{\middlebreak}{\nulldelimiterspace0pt
\right.\allowbreak\mskip 0mu plus .5mu \nulldelimiterspace0pt
\left.\parbox{0pt}{\rule{0pt}{\IrresponsibleFantasy}}}%

\begin{document}

{%
\hsize 3cm
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = 
\left\langle\ReserveVerticalSpace{1cm}
  \mathbb{S},\middlebreak \mathbb{E},
  \middlebreak {X^X}^X, \middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},
  \middlebreak {q_q}_q, \middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m 
\right\rangle$.
\end{theorem}
}%

{%
\hsize 7cm
\begin{theorem}
...could be now considered as an algebraic structure $DB_E = 
\left\langle\ReserveVerticalSpace{1cm}
  \mathbb{S},\middlebreak \mathbb{E},
  \middlebreak {X^X}^X, \middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},
  \middlebreak {q_q}_q, \middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m 
\right\rangle$.
\end{theorem}
}%

\begin{theorem}
...could be now considered as an algebraic structure $DB_E = 
\left\langle\ReserveVerticalSpace{1cm}
  \mathbb{S},\middlebreak \mathbb{E},
  \middlebreak {X^X}^X, \middlebreak f,\middlebreak
  \mathbb{V},\middlebreak \mathbb{R},\middlebreak \mathbb{C},
  \middlebreak {q_q}_q, \middlebreak
  Op_a,\middlebreak Op_c,\middlebreak Op_m 
\right\rangle$.
\end{theorem}


\end{document}

middlebreakII

| improve this answer | |
  • 3
    You did test that right? try adding \test before \right\rangle, where \test is \def\test{x^{(2)}}. Now \rangle and \langle is scalled differently. Best solution is never to use \left...\right in text-mode math. – daleif Jun 18 '13 at 8:14
  • @daleif Well then add a phantom of the required height/depth. Removing the use of \left and \right was I admit the first thing to recommend to the OP in the case at hand; I didn't look at the actual enclosed contents. If items had varied more in height and depth I would have adjusted the method. – user4686 Jun 18 '13 at 9:03
  • Another point is that in many cases \left...\right in the text create unnecessary large fences disrupting the line spacing. I general: don't encourage users to use it in the text – daleif Jun 18 '13 at 9:55
  • @jfbu your second proposal is truly neat. But bad bad you not to have added a strut among the first words of the text before the math group: look at your second example the one with \hsize7cm! – user4686 Jun 18 '13 at 9:58
  • i haven't researched \middlebreak, but it appears that it causes the paragraph to be set ragged right, which wasn't requested. – barbara beeton Jun 18 '13 at 16:36
1

You could rewrite the token stream associated with your algebraic structure to automatically append \allowbreak after each comma and wrap its elements with an auto-sizing pair of angle brackets (excluding \left...\right):

enter image description here

\documentclass[preview]{standalone}
\usepackage{amsmath,amsfonts,amsthm}
\usepackage{expl3,xparse}

\newtheorem{theorem}{Theorem}

\ExplSyntaxOn
\NewDocumentCommand{\mstruct}{m}{%
  \group_begin:
  \tl_set:Nn \l_tmpa_tl {#1}
  \hbox_set:Nn \l_tmpa_box {\ensuremath{\l_tmpa_tl}}
  \dim_set:Nn \l_tmpa_dim {\box_ht:N \l_tmpa_box}
  \dim_add:Nn \l_tmpa_dim {\box_dp:N \l_tmpa_box}
  \dim_add:Nn \l_tmpa_dim {0.3em}
  \dim_set:Nn \l_tmpb_dim {1.2\l_tmpa_dim}
  \tl_replace_all:Nnn \l_tmpa_tl {,} {,\allowbreak}
  \ifmmode%
    \text{\fontsize{\l_tmpa_dim}{\l_tmpb_dim}\selectfont$\langle$}
  \else%
    {\fontsize{\l_tmpa_dim}{\l_tmpb_dim}\selectfont$\langle$}
  \fi
  \ensuremath{\l_tmpa_tl}
  \ifmmode%
    \text{\fontsize{\l_tmpa_dim}{\l_tmpb_dim}\selectfont$\rangle$}
  \else%
    {\fontsize{\l_tmpa_dim}{\l_tmpb_dim}\selectfont$\rangle$}
  \fi
  \group_end:
}
\ExplSyntaxOff

\begin{document}

\mstruct{\text{my}^{\text{very}^{\text{very}^{\text{very}^{\text{big}^\text{object}}}}}}

\mstruct{this,is,a,very,very,very,very,very,very,very,very,very,very,very,very,very,long,sentence,because,I'm,testing,mstruct,against,very,long,text,with,\text{my}^{\text{very}^{\text{very}^{\text{very}^{\text{big}^\text{object}}}}}}

\begin{theorem}
$\mstruct{\text{my}^{\text{very}^{\text{big}^\text{object}}}}_a^b$
\end{theorem}

\begin{theorem}
...could be now considered as an algebraic structure $DB_E =
\mstruct{\mathbb{S}, \mathbb{E}, f, \mathbb{V}, \mathbb{R}, \mathbb{C}, Op_a,
Op_c, Op_m}$.
\end{theorem}

\end{document}
| improve this answer | |
  • 1
    I'm not sure what's \vbox_set:Nn \l_tmpa_box {\tl_to_str:N \l_tmpa_tl} for. You're measuring the height of the string \l_tmpa_tl, not the height of the formula stored in the token listo. You could have a very big object in the argument, but this wouldn't lead to differently sized delimiters. – egreg Dec 12 '18 at 9:01
  • You're right, I think I got lucky because of a newline. I was thinking that \box_ht:N returned the height of the rendered box, that needed to be initialized with the text of the token list because I could not initialize it with the token list directly. I've updated my answer to use the calc package. – Dylon Dec 12 '18 at 9:54
  • I found another way to do it without calc. If you would, please review my latest solution. – Dylon Dec 12 '18 at 10:04
  • It should be \hbox_set:Nn to begin with. – egreg Dec 12 '18 at 10:15
  • Why hbox instead of vbox? The documentation for \vbox_set:Nn states, "Typesets the <contents> at natural height and then stores the result inside the <box>". The documentation for \hbox_set:Nn states, "Typesets the <contents> at natural width and then stores the result inside the <box>". Since I'm interested in the height of the rendered text it seems like I should use \vbox_set:Nn. – Dylon Dec 12 '18 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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