Hi Hans and Taco,
I am back with some more math request---one alignment construct, one inner math alignment construct, and one formula tagging request. These are primarily to "complete" the context math environments. I am posting here rather than on the dev list, so that other math users can also contribute. This is a loong mail.
1. Multiline equations (they are called multline equations in amsmath)
This is used to write multiline formulas (where alignement does not make sense). The first line is left aligned, the last line is rightaligned and all the middle lines are middle aligned.
The entire formula gets only one number. If the formulas are numbered on the right, then the formula number is located on the last line; if the formulas are numbered on the left, then the formula number is located on the first line.
The alignment of a single line can be changed.
The first and the last line have a gap equal to \multlinegap from the text border. If the formula is numbered, the gap is used only for the line without the number.
I do not know what is a good syntax for this command. First of all, I think we should call it multiline (rather than multline as in ams). Then we can have
\placeformula \startmultilineformula[gap=5pt] \NC f(x) = ax \NR \NC + bx + c + \NR \NC e \NR \stopformula
This should come out as (assuming formulas are numbered on the right)
5pt gap |---f(x) = ax | <---- left aligned | + bx + c + | <---- middle aligned | + e (1) | <---- right aligned
If the formulas are numbered on the left |(1) f(x) = ax | | + bx + c + | | + e---| 5pt gap
If there is no placeformula in the front then
|---f(x) = ax |<-- left aligned (5pt gap) | + bx + c + |<-- middle aligned | + e---|<-- right aligned with 5pt gap
If should be possible to get the 2nd line right aligned by using
\NC f(x) = ax \NR \NC[align=right] + bx + c + \NR \NC +e \NR
I am not sure of the syntax and the above \NC...\NR is just to illustrate the point.
PS: I do not use multline of amsmath frequently. If someone does use it, please read this carefully to ensure that I did not misread the manual.
2. In amsmath, most of alignment constructs exist in two forms: outer and inner. The mathalignment implemented in core-mat.tex corresponds to outer alignment. The inner alignment is same as outer alignment, but is only as wide as necessay. The most common amsmath inner alignment constructs are aligned and gathered. It is easiest to explain by means of an example. Suppose I want to type
a x + b y = c `\ } (simultaneous equations) d x + e y = f / ,
I want to be able to do
\defineinnermathalignment[aligned][n=2,left={\left.},right={\right}}]
\startformula \startaligned \NC ax + by \EQ c \NR \NC dx + ey \EQ f \NR \stopaligned \quad \text{(simultaneous equations)} \stopformula
One crude way to implement this is as follows
\def\startaligned{ %Whatever corresponds to left= \left. \framed[align=normal,frame=off,location=lohi] % I do not know how to do this in terms of hboxes \bgroup \vskip-\baselineskip %There should be a better way \startformula \startalign[n=2]}
\def\stopaligned{ \stopalign \stopformula \egroup%end of framed % Whatever correspons to right= \right} }
\startformula \startaligned \NC ax + by \EQ c \NR \NC dx + ey \EQ f \NR \stopaligned \quad \text{(simultaneous equations)} \stopformula
I am sure that this definition can be improved. The innermath environments should take three types of options (n=...,m=....,distance=....,etc, that are passed to \startalign; left=...,right=..., that put the left and right delimiters; and location=high|low|lohi that align the innermath environment to the baseline. Notice that the crude definition that I have given does not handle location nicely.
I know Tex's limitation of scaling left and right delimiters on both sides of the math centerline, making it difficult to handle left|right and location correctly. It there is no easy fix, left|right can be left out.
Such a construct will take care of aligned, gathered and split environments of amsmath.
3. Formula tagging
amsmath allows formulas to be tagged. I will explain amsmath's behaviour and hope that Hans can come up with the context way of doing such things.
Occasionally, one wants to tag a formula, e.g.
\placefomrula[a] \startformula a x = b \stopformula
\placetaggedformula[b]{*} \startformula x = \frac {b}{a} \stopformula
should come out as
a x = b (1) x = b/a (*)
Notice that ( and ) correspond to left and right in setupformulas. It should also be possible to place a tag without these brackets, so
\placetaggedformulawithoutbrackets[c]{**} \startformula b = ax \stopformula
should come out as b = ax ** <--- no brackets here
Maybe, instead of placetaggedformulawithout brackets, one can simply have
\placetaggedformula[c][left=,right=]{**}
but in such cases it is easy to get confused with the reference and options. I am not sure what is a good way to do this.
It should also be possible to refer to these tagged formulas. So \in{formula}[b] should give * and \in{formula}[c] should give **.
The tag should be set in text mode, so that one can say \placetagformula {Answer} and the Answer will come out in text mode.
Thanks, Aditya
Aditya Mahajan wrote:
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
Hi Hans and Taco,
I am back with some more math request
Forgot a small request: Can this be added to core-mat.tex
\def\intertext#1{\startintertext#1\stopintertext}
sure, but as:
\def\intertext#1% {\noalign{\dointertext{#1}}}
(more efficient)
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Aditya Mahajan wrote:
- In amsmath, most of alignment constructs exist in two forms: outer
and inner. The mathalignment implemented in core-mat.tex corresponds to outer alignment. The inner alignment is same as outer alignment, but is only as wide as necessay. The most common amsmath inner alignment constructs are aligned and gathered. It is easiest to explain by means of an example. Suppose I want to type
a x + b y = c `\ } (simultaneous equations) d x + e y = f / ,
I want to be able to do
\defineinnermathalignment[aligned][n=2,left={\left.},right={\right}}]
This sounds very close to \definemathmatrix, yes?
Taco
On Tue, 8 Aug 2006, Taco Hoekwater wrote:
Aditya Mahajan wrote:
- In amsmath, most of alignment constructs exist in two forms: outer
and inner. The mathalignment implemented in core-mat.tex corresponds to outer alignment. The inner alignment is same as outer alignment, but is only as wide as necessay. The most common amsmath inner alignment constructs are aligned and gathered. It is easiest to explain by means of an example. Suppose I want to type
a x + b y = c `\ } (simultaneous equations) d x + e y = f / ,
I want to be able to do
\defineinnermathalignment[aligned][n=2,left={\left.},right={\right}}]
This sounds very close to \definemathmatrix, yes?
It is, and my first thought was that this can be achieved using \definematrix (that is why the previous requests for location= and style=). However, all my attempts to use a matrix failed because:
1. Matrix does not "see" beyond the \NCs as align.
Comapre the output of
\startformula \startalign[n=2] \NC a \NC = bx + c \NR \NC \NC + ey \NR \stopalign \stopformula
with
\startformula \startmatrix[n=2,distance=0pt, style=\displaystyle] \NC a \NC = bx + c \NR \NC \NC + ey \NR \stopmatrix \stopformula
The '+' in the second line comes out as a unary operator rather than a binary operator. This can be corrected by using \NC{}+ but should the user really know the ugly implementation details?
2. Matrix does not correct interline space. Compare
\startformula \startalign[n=2] \NC f(x) \NC = \int_{-\infty}^{\infty} \phi(y-x) dy \NR \NC \NC = \sum_{i=-\infty}^{\infty} \hat phi(i-x) \NR \stopalign \stopformula
with
\startformula \startmatrix[n=2,distance=0pt, style=\displaystyle] \NC f(x) \NC = \int_{-\infty}^{\infty} \phi(y-x) dy \NR \NC \NC = \sum_{i=-\infty}^{\infty} \hat phi(i-x) \NR \stopmatrix \stopformula
The two lines are too close.
I thought that it might be easier to simply wrap the whole align around a hbox as these inner alignments need not break across pages. If matrix can be enhanced to take care of the above two requirements then matrix is fine. However, if I just want a matrix, then both above behaviours of the matrix are correct. I am not sure what kind of interface matrix should have to behave in both ways (the current matrix behaviour and the requested aligned behaviour).
Aditya
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
- Formula tagging
amsmath allows formulas to be tagged. I will explain amsmath's behaviour and hope that Hans can come up with the context way of doing such things.
Occasionally, one wants to tag a formula, e.g.
\placefomrula[a] \startformula a x = b \stopformula
\placetaggedformula[b]{*} \startformula x = \frac {b}{a} \stopformula
should come out as
a x = b (1) x = b/a (*)
Notice that ( and ) correspond to left and right in setupformulas. It should also be possible to place a tag without these brackets, so
\placetaggedformulawithoutbrackets[c]{**} \startformula b = ax \stopformula
should come out as b = ax ** <--- no brackets here
Maybe, instead of placetaggedformulawithout brackets, one can simply have
\placetaggedformula[c][left=,right=]{**}
but in such cases it is easy to get confused with the reference and options. I am not sure what is a good way to do this.
It should also be possible to refer to these tagged formulas. So \in{formula}[b] should give * and \in{formula}[c] should give **.
The tag should be set in text mode, so that one can say \placetagformula {Answer} and the Answer will come out in text
mode.
I got an idea of using conversion for formula tagging. For single line formulas, the idea is pretty simple. I define a dummyconversion which always maps to the tag and set the formula conversion to dummyconversion. Then, I save the formula number, let startformula, work as normal and refine stopformula to restore formula number. The internal macros take care of referencing.
This is my first attempt
%------------------------8<-------------------------- \def\placeformulatag% {\dosingleempty\doplaceformulatag}
\def\doplaceformulatag[#1]#2% {\let\normalstopformula\stopformula \def\stopformula% {\normalstopformula \restorenumber[formula] \egroup \let\stopformula\normalstopformula} \bgroup \savenumber[formula] \def\dummyconversion##1{#2} \defineconversion[dummyconversion][\dummyconversion] \setupformulas[conversion=dummyconversion] \placeformula[#1]}
\starttext \placeformulatag[tag]{test} \startformula E = mc^2 \stopformula
See \in formula[tag] for a tagged formula \stoptext %----------------------------8<-------------------------
This one places (test) with the brackets in place of the formula number. It is easy to get rid of the brackets by using \setupformulas[left=,right=]. However, I do not know what will be a good interface for this.
In Latex, \tag{whatever} give (whatever) and \tag*{whatever} gives whatever without the brackets. But context does not use starred form of commands, and I do not want to introduce them here. One way is
\placeformulatag[ref][left=,right=] {my tag} ....
Is this fine? We can also have tagleft=... and tagright=... as part of setupformulas, or, if that is too confusion, have \setupformulatagging[left=...,right=...].
However, this idea does not work inside \startmathalignment as the conversion can not be changed inside a formula.
\placeformula \startformula \startalign \NC a \NC = b \NR[+] \setupformulas[conversion=set 1] \NC c \NC = d \NR[+] \stopalign \stopformula
Is there some better way to achieve the same effect inside a mathalignment?
Aditya
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
[ A long list of feature requests ]
Here is something that was not in my original list: subformula numbering.
Context allows one to number subformulas by specifying the subnumber. Thus, if I want (1a) (1b) and (1c), I need to do
\placesubformula[+]{a} ....
\placesubformula[+]{b} ....
\placesubformula[+]{c} ....
Basically, do the numbering by hand. This is fine if there are only a few formulas, but there are some drawbacks of this approach. Firstly, if at a later stage you decide to move the equations around, you need to retype the formula numbers. Also, you need to remember to increment the formula numbers at the right time.
I was thinking of a better (rather more familar) way of treating subformulas by imitating the \begin{subequations} .... \end{subeqations} environment of latex.
I propose a \startsubformula .... \stopsubformula environment, so that inside it, I will get subformula numbers rather than formula numbers. Having discovered conversions (see my previous mail on tagged formulas), I tried to implement it using conversions. The following straightforward approach works fine. This is just a stop gap code, I do not take care of inherting the right settings for formulas, but it conveys the idea.
%--------------------------8<------------------------------------ \definenumber[tempformula] \def\subformulaconversion#1{\getnumber[tempformula]\character{#1}} % character should be modifiable using \setupsubformulas
\defineconversion[subformulaconversion][\subformulaconversion]
\def\startsubformulas% {\incrementnumber[formula] \expanded{\setupnumber[tempformula][start={\rawnumber[formula]}]} \savenumber[formula] \setupformulas[conversion=subformulaconversion] % way should be set to bytext \resetnumber[formula] }
\def\stopsubformulas% {\setupformulas[conversion=numbers] % conversion should be inherited from setupformulas % way should be restored to whatever it was earlier \restorenumber[formula]}
\startbuffer \placeformula \startformula a^2 + b^2 = c^2 \stopformula \stopbuffer
\starttext
\dorecurse{3}{\getbuffer}
Lets start subformulas
\startsubformulas \dorecurse{3}{\getbuffer} \stopsubformulas
Also works inside alignments
\startsubformulas \placeformula \startformula \startalign \NC A \EQ B + C \NR[first] \NC D \EQ E + F \NR[+] \stopalign \stopformula \stopsubformulas
Notice that in \in formula[first] we get the correct reference.
\dorecurse{3}{\getbuffer}
\stoptext %----------------------------8<---------------------------------------
Hans and Taco, can something like this be added to the core? If so, I will try to make this macro more robust (correct inheritence, etc.)
Aditya
On Fri, 25 Aug 2006, Aditya Mahajan wrote:
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
[ A long list of feature requests ]
Here is something that was not in my original list: subformula numbering.
[...]
I was thinking of a better (rather more familar) way of treating subformulas by imitating the \begin{subequations} .... \end{subeqations} environment of latex.
I propose a \startsubformula .... \stopsubformula environment, so that inside it, I will get subformula numbers rather than formula numbers. Having discovered conversions (see my previous mail on tagged formulas), I tried to implement it using conversions. The following straightforward approach works fine. This is just a stop gap code, I do not take care of inherting the right settings for formulas, but it conveys the idea.
Hans and Taco, can something like this be added to the core? If so, I will try to make this macro more robust (correct inheritence, etc.)
Here is a more robust version. I use ??sf as a namespace for subformulas. I do not think that this is used anywhere else.
Aditya
On Sat, 26 Aug 2006 12:37:56 -0400 (EDT) Aditya Mahajan adityam@umich.edu wrote:
On Fri, 25 Aug 2006, Aditya Mahajan wrote:
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
[ A long list of feature requests ]
Here is something that was not in my original list: subformula numbering.
[...]
I was thinking of a better (rather more familar) way of treating subformulas by imitating the \begin{subequations} .... \end{subeqations} environment of latex.
I propose a \startsubformula .... \stopsubformula environment, so that inside it, I will get subformula numbers rather than formula numbers. Having discovered conversions (see my previous mail on tagged formulas), I tried to implement it using conversions. The following straightforward approach works fine. This is just a stop gap code, I do not take care of inherting the right settings for formulas, but it conveys the idea.
Hans and Taco, can something like this be added to the core? If so, I will try to make this macro more robust (correct inheritence, etc.)
Here is a more robust version. I use ??sf as a namespace for subformulas. I do not think that this is used anywhere else.
I found nothing where ??sf is used in the ConText core, but it is defined as systemvariable in mult-sys line 552.
--> \definesystemvariable {sf} % SpeciFics
You should ask Hans if he need it.
Wolfgang
Wolfgang Schuster wrote:
On Sat, 26 Aug 2006 12:37:56 -0400 (EDT) Aditya Mahajan adityam@umich.edu wrote:
On Fri, 25 Aug 2006, Aditya Mahajan wrote:
On Tue, 8 Aug 2006, Aditya Mahajan wrote:
[ A long list of feature requests ]
Here is something that was not in my original list: subformula numbering.
[...]
I was thinking of a better (rather more familar) way of treating subformulas by imitating the \begin{subequations} .... \end{subeqations} environment of latex.
I propose a \startsubformula .... \stopsubformula environment, so that inside it, I will get subformula numbers rather than formula numbers. Having discovered conversions (see my previous mail on tagged formulas), I tried to implement it using conversions. The following straightforward approach works fine. This is just a stop gap code, I do not take care of inherting the right settings for formulas, but it conveys the idea.
Hans and Taco, can something like this be added to the core? If so, I will try to make this macro more robust (correct inheritence, etc.)
Here is a more robust version. I use ??sf as a namespace for subformulas. I do not think that this is used anywhere else.
I found nothing where ??sf is used in the ConText core, but it is defined as systemvariable in mult-sys line 552.
--> \definesystemvariable {sf} % SpeciFics
You should ask Hans if he need it.
core-env.tex : 6 : {\long\setvalue{??sf#1}{#2}} core-env.tex : 12 : \getvalue{??sf#1}\relax core-env.tex : 15 : \getvalue{??sf#1}\relax
on my machine
Hans
On Mon, 28 Aug 2006, Hans Hagen wrote:
Wolfgang Schuster wrote:
On Sat, 26 Aug 2006 12:37:56 -0400 (EDT) Aditya Mahajan adityam@umich.edu wrote:
Here is a more robust version. I use ??sf as a namespace for subformulas. I do not think that this is used anywhere else.
I found nothing where ??sf is used in the ConText core, but it is defined as systemvariable in mult-sys line 552.
--> \definesystemvariable {sf} % SpeciFics
You should ask Hans if he need it.
core-env.tex : 6 : {\long\setvalue{??sf#1}{#2}} core-env.tex : 12 : \getvalue{??sf#1}\relax core-env.tex : 15 : \getvalue{??sf#1}\relax
on my machine
Alright, how about if I add a new variable
\definesystemvariable {subfm} % subForMulas
or do I need to stick to two letter acronyms?
Aditya
Aditya Mahajan wrote:
\definesystemvariable {subfm} % subForMulas
or do I need to stick to two letter acronyms?
in this case i'd go for a double one:
you can take \definesystemvariable {fn}
i didn't look into your code yet (but you're improving it anyway)
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------