ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* math formula linebreak
@ 2012-08-09  7:37 Steffen Wolfrum
  2012-08-09 17:31 ` Aditya Mahajan
  2012-08-09 20:21 ` Prashanth
  0 siblings, 2 replies; 9+ messages in thread
From: Steffen Wolfrum @ 2012-08-09  7:37 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi,

for nice linebreaking we can adjust math formulas by the use of NC, NR alignment.

But if someone only wants long formulas to fit in a defined area, and want them to break automatically ... is there a handy solution?

(Below are examples that don't work)

Thanks,
Steffen
-------


\starttext


\placeformula
\startformula[9pt]
I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
+(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\}-\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
+(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
\stopformula



\defineframedtext
 [defbackground]
 [width=10cm,
  frame=on,
  location=paragraph]


\startdefbackground
\placeformula
\startformula[9pt]
I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
+(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
+(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
\stopformula
\stopdefbackground





\definelayer[mylayer]


\setlayerframed
 [mylayer]
 [x=25mm,
  y=85mm,
  height=43.5mm,
  width=10cm,align=block]
 {
 \placeformula
\startformula[9pt]
I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
+(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
+(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
\stopformula
 }

\setupbackgrounds[page][background=mylayer]






\stoptext

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09  7:37 math formula linebreak Steffen Wolfrum
@ 2012-08-09 17:31 ` Aditya Mahajan
  2012-08-09 18:19   ` Sietse Brouwer
  2012-08-09 20:21 ` Prashanth
  1 sibling, 1 reply; 9+ messages in thread
From: Aditya Mahajan @ 2012-08-09 17:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 9 Aug 2012, Steffen Wolfrum wrote:

> Hi,
>
> for nice linebreaking we can adjust math formulas by the use of NC, NR alignment.
>
> But if someone only wants long formulas to fit in a defined area, and want them to break automatically ... is there a handy solution?

Short answer: No easy solution exists.

Aditya

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 17:31 ` Aditya Mahajan
@ 2012-08-09 18:19   ` Sietse Brouwer
  2012-08-09 18:53     ` Aditya Mahajan
  0 siblings, 1 reply; 9+ messages in thread
From: Sietse Brouwer @ 2012-08-09 18:19 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Steffen Wolfrum wrote:
>> them to break automatically ... is there a handy solution?

Aditya Mahajan wrote:
> Short answer: No easy solution exists.

Is this because allowing automatic line breaks in math mode is itself
hard to implement, or is the basic mechanism possible but preventing
stupid/ugly breakpoints is hard? Because I can imagine a 70 percent
solution being a big help already.
--Sietse
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 18:19   ` Sietse Brouwer
@ 2012-08-09 18:53     ` Aditya Mahajan
  2012-08-09 19:41       ` Sietse Brouwer
  2012-08-09 21:07       ` Hans Hagen
  0 siblings, 2 replies; 9+ messages in thread
From: Aditya Mahajan @ 2012-08-09 18:53 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On Thu, 9 Aug 2012, Sietse Brouwer wrote:

> Steffen Wolfrum wrote:
>>> them to break automatically ... is there a handy solution?
>
> Aditya Mahajan wrote:
>> Short answer: No easy solution exists.
>
> Is this because allowing automatic line breaks in math mode is itself
> hard to implement, or is the basic mechanism possible but preventing
> stupid/ugly breakpoints is hard? Because I can imagine a 70 percent
> solution being a big help already.

Partly both.

The question is not so much the difficulty in choosing break-points (which 
is easy: before all \mathbin atoms, after \mathpunct if needed, etc). The 
hard part is how to align the split up portions, and choosing different 
alignments changes the line widths, and therefore affect future 
line-breaks.

The old manual of breqn (the one by Michel Jones) had some discussion on 
the different alignment of display math. They are also explained nicely in 
the book on typesetting math by AMS (I forget the author's name).

In principle, one can follow the same approach as Knuth did for 
line-breaking text (define penalties and then solve a dynamic program to 
find the layout that gives the lowest score). The breqn package does 
implement such an algorithm that works well in most cases. I wish that the 
breqn algorithm were described somethere; then one could play around 
implementing it in luatex. Trying to read breqn code to understand the 
algorithm is very difficult.

Aditya
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 18:53     ` Aditya Mahajan
@ 2012-08-09 19:41       ` Sietse Brouwer
  2012-08-09 20:31         ` Sietse Brouwer
  2012-08-09 21:07       ` Hans Hagen
  1 sibling, 1 reply; 9+ messages in thread
From: Sietse Brouwer @ 2012-08-09 19:41 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hi Aditya,

> I wish that the breqn algorithm were described somethere;
> then one could play around implementing it in luatex.

Have you seen the new User's Guide yet? It's from last May, very
recent, so it may not have been there yet when last you looked. It
includes the entire source code, and comments that quite thoroughly:
the ratio works out to 16 lines of comment per 26 lines of code. (A
page is about 42 lines.) And the comments go into the "how", and not
just the "what". Might be useful at some point in the future, if it is
indeed new.

http://ctan.unixbrain.com/macros/latex/contrib/mh/breqn.pdf

--Sietse

P.s. The lack of an index and a table of contents is criminal,
although probably due to this being a beta version (v0.98b) of the
manual. I've extracted the sections and subsection titles, albeit
without the page numbers.

== User's guide ==
1 A bit of history
2 Package loading
3 To do
4 Introduction
5 Principal features
6 Shortcomings of the package
6.1 Incompatibilities
6.2 Indention of delimited fragments
6.3 Math symbol subversion
6.4 Subscripts and superscripts
7 Incomplete
8 Package options
9 Environments and commands
9.1 Environments
9.2 Commands
10 Various environment options
11 The \@exisym package
12 Caution! Warning!
13 Examples

== Implementation ==
14 Introduction
15 Strategy
16 Prelim
17 Package options
18 Required packages
19 Some useful tools
20 Debugging
21 The \listwidth variable
22 Parameters
23 Measuring equation components
24 The dmath and dmath* environments
25 Special processing for end-of-equation
26 Preprocessing the equation body
27 Choosing optimal line breaks
28 Equation layout options
29 Centered Right-Number Equations
30 Framing an equation
31 Delimiter handling
32 Series of expressions
33 Equation groups
34 The darray environment
35 Miscellaneous
36 Wrap-up
37 To do
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09  7:37 math formula linebreak Steffen Wolfrum
  2012-08-09 17:31 ` Aditya Mahajan
@ 2012-08-09 20:21 ` Prashanth
  2012-08-09 21:14   ` Steffen Wolfrum
  1 sibling, 1 reply; 9+ messages in thread
From: Prashanth @ 2012-08-09 20:21 UTC (permalink / raw)
  To: ntg-context


[-- Attachment #1.1: Type: text/plain, Size: 2048 bytes --]


On 09/08/12 09:37, Steffen Wolfrum wrote:
> Hi,
>
> for nice linebreaking we can adjust math formulas by the use of NC, NR alignment.
>
> But if someone only wants long formulas to fit in a defined area, and want them to break automatically ... is there a handy solution?
>
> (Below are examples that don't work)
>
> Thanks,
> Steffen
> -------
>
>
> \starttext
>
>
> \placeformula
> \startformula[9pt]
> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\}-\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
> \stopformula
>
>
>
> \defineframedtext
>   [defbackground]
>   [width=10cm,
>    frame=on,
>    location=paragraph]
>
>
> \startdefbackground
> \placeformula
> \startformula[9pt]
> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
> \stopformula
> \stopdefbackground
>
>
>
>
>
> \definelayer[mylayer]
>
>
> \setlayerframed
>   [mylayer]
>   [x=25mm,
>    y=85mm,
>    height=43.5mm,
>    width=10cm,align=block]
>   {
>   \placeformula
> \startformula[9pt]
> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
> \stopformula
>   }
>
> \setupbackgrounds[page][background=mylayer]
>
>
>
>
>
>
> \stoptext
>
When I needed something like that, I used \allowbreak with inlinemath. 
In your case, you could do:
\bTABLE[frame=on,align=right,width=10cm]
\bTR
\bTD
$I=\big\{\lambda u(x_0-\pi^H K)\allowbreak+(1-\lambda)[\pi^L 
u(x_0-K+(1-\pi^L)Z_{L'})\allowbreak+(1-\pi^L)u(x_0-\pi^L 
Z_{L'})]\big\}\allowbreak -\big\{\pi^U 
u(x_0-K+(1-\pi^U)Z_{U'})\allowbreak+(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.$
\eTD
\eTR
\eTABLE

This will just flow it like regular text. I don't know if this is good 
enough for your needs. If not, you can add another way to your list of 
ways ;-).

-- Prash

[-- Attachment #1.2: Type: text/html, Size: 2406 bytes --]

[-- Attachment #2: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 19:41       ` Sietse Brouwer
@ 2012-08-09 20:31         ` Sietse Brouwer
  0 siblings, 0 replies; 9+ messages in thread
From: Sietse Brouwer @ 2012-08-09 20:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Addendum: I just bumped into Morten Høgholm's bachelor's thesis.
"Automatic line-breaking of displayed math expressions"
https://sites.google.com/site/mortenhoegholm/breqn-thesis.pdf

That thesis contains a conceptual explanation of the breqn algorithm
(or at least the algorithm he used when reimplementing breqn as
l3breqn). Might be useful if/when somebody decides to have a go at
improving ConTeXts math breaking. The thesis also contains the code of
l3breqn, but that is rather more sparsely commented than the code in
the breqn.pdf manual.

--Sietse
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 18:53     ` Aditya Mahajan
  2012-08-09 19:41       ` Sietse Brouwer
@ 2012-08-09 21:07       ` Hans Hagen
  1 sibling, 0 replies; 9+ messages in thread
From: Hans Hagen @ 2012-08-09 21:07 UTC (permalink / raw)
  To: mailing list for ConTeXt users

On 9-8-2012 20:53, Aditya Mahajan wrote:
> On Thu, 9 Aug 2012, Sietse Brouwer wrote:
>
>> Steffen Wolfrum wrote:
>>>> them to break automatically ... is there a handy solution?
>>
>> Aditya Mahajan wrote:
>>> Short answer: No easy solution exists.
>>
>> Is this because allowing automatic line breaks in math mode is itself
>> hard to implement, or is the basic mechanism possible but preventing
>> stupid/ugly breakpoints is hard? Because I can imagine a 70 percent
>> solution being a big help already.
>
> Partly both.
>
> The question is not so much the difficulty in choosing break-points
> (which is easy: before all \mathbin atoms, after \mathpunct if needed,
> etc). The hard part is how to align the split up portions, and choosing
> different alignments changes the line widths, and therefore affect
> future line-breaks.
>
> The old manual of breqn (the one by Michel Jones) had some discussion on
> the different alignment of display math. They are also explained nicely
> in the book on typesetting math by AMS (I forget the author's name).
>
> In principle, one can follow the same approach as Knuth did for
> line-breaking text (define penalties and then solve a dynamic program to
> find the layout that gives the lowest score). The breqn package does
> implement such an algorithm that works well in most cases. I wish that
> the breqn algorithm were described somethere; then one could play around
> implementing it in luatex. Trying to read breqn code to understand the
> algorithm is very difficult.

When I'm done ceaning up the pending tex and lua code, I'll look into 
these issues. It's probably not that hard to come up with a solution in 
lua (one of the pet projects on my list).

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
                                              | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: math formula linebreak
  2012-08-09 20:21 ` Prashanth
@ 2012-08-09 21:14   ` Steffen Wolfrum
  0 siblings, 0 replies; 9+ messages in thread
From: Steffen Wolfrum @ 2012-08-09 21:14 UTC (permalink / raw)
  To: mailing list for ConTeXt users


Am 09.08.2012 um 22:21 schrieb Prashanth:

> 
> On 09/08/12 09:37, Steffen Wolfrum wrote:
>> Hi,
>> 
>> for nice linebreaking we can adjust math formulas by the use of NC, NR alignment.
>> 
>> But if someone only wants long formulas to fit in a defined area, and want them to break automatically ... is there a handy solution?
>> 
>> (Below are examples that don't work)
>> 
>> Thanks,
>> Steffen
>> -------
>> 
>> 
>> \starttext
>> 
>> 
>> \placeformula
>> \startformula[9pt]
>> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
>> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\}-\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
>> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
>> \stopformula
>> 
>> 
>> 
>> \defineframedtext
>>  [defbackground]
>>  [width=10cm,
>>   frame=on,
>>   location=paragraph]
>> 
>> 
>> \startdefbackground
>> \placeformula
>> \startformula[9pt]
>> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
>> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
>> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
>> \stopformula
>> \stopdefbackground
>> 
>> 
>> 
>> 
>> 
>> \definelayer[mylayer]
>> 
>> 
>> \setlayerframed
>>  [mylayer]
>>  [x=25mm,
>>   y=85mm,
>>   height=43.5mm,
>>   width=10cm,align=block]
>>  {
>>  \placeformula
>> \startformula[9pt]
>> I=\big\{\lambda u(x_0-\pi^H K)+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})
>> +(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\} -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})
>> +(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.
>> \stopformula
>>  }
>> 
>> \setupbackgrounds[page][background=mylayer]
>> 
>> 
>> 
>> 
>> 
>> 
>> \stoptext
>> 
> When I needed something like that, I used \allowbreak with inlinemath. In your case, you could do:
> \bTABLE[frame=on,align=right,width=10cm]
> \bTR
> \bTD
> $I=\big\{\lambda u(x_0-\pi^H K)\allowbreak+(1-\lambda)[\pi^L u(x_0-K+(1-\pi^L)Z_{L'})\allowbreak+(1-\pi^L)u(x_0-\pi^L Z_{L'})]\big\}\allowbreak -\big\{\pi^U u(x_0-K+(1-\pi^U)Z_{U'})\allowbreak+(1-\pi^U)u(x_0-\pi^U Z_{U'})\big\}.$
> \eTD
> \eTR
> \eTABLE
> 
> This will just flow it like regular text. I don't know if this is good enough for your needs. If not, you can add another way to your list of ways ;-).



Hey, you skipped start/stopformula and used a $$ environment?! 
Why not, that's a quite clever approach (... actually, it's a quite efficient workaround for my needs).

Thank you Prash, thank you very much!
Steffen
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-08-09 21:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-09  7:37 math formula linebreak Steffen Wolfrum
2012-08-09 17:31 ` Aditya Mahajan
2012-08-09 18:19   ` Sietse Brouwer
2012-08-09 18:53     ` Aditya Mahajan
2012-08-09 19:41       ` Sietse Brouwer
2012-08-09 20:31         ` Sietse Brouwer
2012-08-09 21:07       ` Hans Hagen
2012-08-09 20:21 ` Prashanth
2012-08-09 21:14   ` Steffen Wolfrum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).