3

I have long equations that I want LaTeX to break automatically. After some extensive searching I have been unable to work out how to achieve this effect. I have breqn in my package list, however it doesn't break the equations I have in the equation environment or math mode (or caption mode). For example it doesn't break:

A[A, k_a](M(\Box_0)) | I[k_a, d_k] | R(K[K, d_k, x]) \rightarrowtriangle A[A,k_a](M(\Box_0 | T[k_t])) | I[k_a,d_k] | I[k_t, d_k] | R(K[K,d_k,x])

I think this means I want to add \mathpunct for the \rightarrowtriangle and | symbols and only allow breaking of depth one. However I can't actually make this happen. I can't work out how to use the \mathpunct command or find what the symbol numbers of \rightarrowtriangle or | are.

Edit:

A minimal working example:

\documentclass{report}
\usepackage{stmaryrd}
\usepackage{amssymb}
\usepackage{breqn}
\begin{document}
\begin{dmath}
  A[A, k_a](M(\Box_0)) | I[k_a, d_k] | R(K[K, d_k, x]) \rightarrowtriangle A[A,k_a](M(\Box_0 | T[k_t])) | I[k_a,d_k] | I[k_t, d_k] | R(K[K,d_k,x])
\end{dmath}
\end{document}
4
  • 1
    Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Herr K.
    May 10, 2013 at 20:38
  • Also, it would be helpful to mention that your code snippet requires the stmaryrd package.
    – Herr K.
    May 10, 2013 at 20:40
  • You have to use the environments provided by breqn (see the manual) to get automatic line breaking, it doesn't change the behaviour of existing environments such as equation. Please add a minimal example, as suggested by Kevin. May 10, 2013 at 21:30
  • Hi @KevinC , I've added the MWE, but TBH there really isn't anything in it bar what I put.
    – jhoyla
    May 12, 2013 at 12:03

1 Answer 1

2

Define \rightarrowtriangle in such a way it's understood by breqn; then add a level of bracing and tell breqn to break only at level 0. I used \mid, perhaps you prefer \vert for the vertical bar.

\documentclass{report}
\usepackage{amssymb,amsmath}
\usepackage{breqn}
\usepackage{stmaryrd}

\makeatletter
\ExplSyntaxOn
\cs_gset:cpx{mg@stmry}{\hexnumber@\symstmry}%
\DeclareFlexSymbol{\rightarrowtriangle}{Rel}{stmry}{5F}
\makeatother
\ExplSyntaxOff

\begin{document}
\begin{dmath}[breakdepth=0]
  \left.
  A[A, k_a](M(\Box_0)) \mid I[k_a, d_k] \mid R(K[K, d_k, x])
  \right.
  \rightarrowtriangle
  \left.
  A[A,k_a](M(\Box_0 \mid T[k_t])) \mid I[k_a,d_k] \mid I[k_t, d_k] \mid R(K[K,d_k,x])
  \right.
\end{dmath}
\end{document}

enter image description here

Actually there should be a stmaryrd.sym file for turning the definitions of stmaryrd.sty into something good for breqn. There isn't, at the moment.


Such an example confirm my opinion that it's a bad idea trying to automatize line breaks in equations.

The breqn package doesn't like |; one should use \vert, \lvert, \rvert or \mid, depending on the mathematical meaning of the bar. In this case one should use \mid; well, if one does it and makes the proper definition for \rightarrowtriangle, the result is as follows:

enter image description here

This is clearly unacceptable. If one uses \vert, no break can be taken. This works "automatically":

\documentclass{report}
\usepackage{amssymb}
\usepackage{breqn}
\usepackage{stmaryrd}

\makeatletter
\ExplSyntaxOn
\cs_gset:cpx{mg@stmry}{\hexnumber@\symstmry}%
\DeclareFlexSymbol{\rightarrowtriangle}{Rel}{stmry}{5F}
\makeatother
\ExplSyntaxOff

% breqn doesn't like |
\newcommand{\OR}{\hiderel{\mid}}


\begin{document}
\begin{dmath}
  A[A, k_a](M(\Box_0)) \OR I[k_a, d_k] \OR R(K[K, d_k, x])
  \rightarrowtriangle
  A[A,k_a](M(\Box_0 \OR T[k_t])) \OR I[k_a,d_k] \OR I[k_t, d_k] \OR R(K[K,d_k,x])
\end{dmath}
\end{document}

and produces

enter image description here

I'm asking myself where's the advantage over writing

\begin{equation}
\begin{aligned}
& A[A, k_a](M(\Box_0)) \mid I[k_a, d_k] \mid R(K[K, d_k, x]) \\
& \quad {} \rightarrowtriangle
  A[A,k_a](M(\Box_0 \mid T[k_t])) \mid I[k_a,d_k] \mid I[k_t, d_k] \mid R(K[K,d_k,x])
\end{aligned}
\end{equation}

that produces essentially the same result.

8
  • The value of automating it is that I have close to 40 pages of these for my dissertation. I can't go through all of them and add hundreds of \penalty0 things at every point. Especially as some of these occur in captions and thus would require substantial fiddling to get right.
    – jhoyla
    May 12, 2013 at 13:20
  • @jhoyla I can understand; but if this "automation" doesn't work, it's worse than doing it manually. In my book I have 300+ pages with many long displayed equations involving big matrices: yes, I split them manually.
    – egreg
    May 12, 2013 at 13:26
  • Is there really no way to have it split at a sensible place, and only split to an appropriate depth? Also I can't make your example work, I get an undefined control sequence on cs. What package am I missing? (I tried latex3 but I already have that.)
    – jhoyla
    May 12, 2013 at 13:32
  • @jhoyla Try the new version. If you get undefined control sequence messages, then you have an outdated TeX distribution, probably.
    – egreg
    May 12, 2013 at 13:35
  • You were right, my TeX distribution was from 2009, upgrading fixed it. Can I make just the \rightarrowtriangle break automatically without \penalty0
    – jhoyla
    May 12, 2013 at 14:33

You must log in to answer this question.

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