Changes

Jump to navigation Jump to search
907 bytes added ,  09:29, 2 March 2022
< [[Main Page]] | [[Math]] | [[Math with newmat]] | [[MathML]] >
 
Be sure to also read [http://dl.contextgarden.net/myway/mathalign.pdf Using \startalign and friends] written by Aditya Mahajan.
 
== Basic Alignment ==
* Latex style
<texcode>
\startformula \startalign
v &= u + at \\
h &= ut + \frac12 gt^2 \\
\stopalign \stopformula
</texcode>
 
Note the \\ in the last line, above.
 
This appears as follows:
<contextsource=yes text="Note the \\ in the last line, above. This appears as follows:">
\startformula \startalign
v &= u + at \\
* Context Style
<texcode>\startformula \startalign \NC v \NC context source= u + at \NR \NC h \NC= ut + \frac12 gt^2 \NR\stopalign \stopformula</texcode> <contextyes>
\startformula \startalign
\NC v \NC = u + at \NR
The above equations were aligned at <code>=</code>. Suppose you also want the <code>+</code> to align. Well, this is simple in context, simply specify the number of columns with <code>\startalign</code>
 <texcode>\startformula \startalign[n=3] \NC v \NC = u \NC+ at \NR \NC h \NCcontext source= ut \NC+ \frac12 gt^2 \NR\stopalign \stopformula</texcode> <contextyes>
\startformula \startalign[n=3]
\NC v \NC = u \NC+ at \NR
== Alignment of each column ==
If you want more control over the formatting, and want the middle column to be center aligned, you can do that by
<texcode>
\startformula \startalign[n=3,align={right,middle,left}]
\NC v \NC = u \NC+ at \NR
\NC h \NC= ut \NC+ \frac12 gt^2 \NR
\stopalign \stopformula
</texcode>
<contextsource=yes>\startformula \startalign[n=3,align={1:right,2:middle,3:left}]
\NC v \NC = u \NC+ at \NR
\NC h \NC= ut \NC+ \frac12 gt^2 \NR
This mechanism allows fancier alignments like
<texcodecontext source=yes>\startformula \startalign[n=4,align={1:left,2:right,3:middle,4:left}]
\NC \text{We have} \quad \NC v \NC = u \NC+ at \NR
\NC \text{and} \NC h \NC= ut \NC+ \frac12 gt^2 \NR
\stopalign \stopformula
</texcodecontext== Working with equation numbering ==
aligned equations can be numbered by placing a tag after {{cmd|NR}}
<contextsource=yes>\startformula \startalignsetuplayout[nscale=40.8,alignwidth={left,right,middle,left}13cm] \NC placeformula \text{We have} startformula \quad startalign \NC v \NC = u \NC+ at \NR[eq:v] \NC \text{and} \NC h \NC= ut \NC+ \frac12 gt^2 \NR[eq:h]\stopalign \stopformulaEquation~(\in[eq:v]) tells the final velocity after time~$t$ and equation~(\in[eq:h]) tells the distance travelled in time~$t$.
</context>
The numbering can be changed to a subformula style using {{cmd|placesubformula}} instead of {{cmd|placeformula}} and numbering the subformulas using {{cmd|NR|2=[+][a]}}, {{cmd|NR|2=[+][b]}}, … instead: <context source=yes>\setuplayout[scale=0.8,width= Working with equation numbering 13cm]\placesubformula \startformula \startalign \NC v \NC =u + at \NR[+][eq:v] \NC h \NC =ut + \frac12 gt^2 \NR[+][eq:h]\stopalign \stopformula Equation~(\in[eq:v]) tells the final velocity after time~$t$ and equation (\in[eq:h]) tells the distance travelled in time~$t$.</context>
== Changing the number of columns ==
 
== Defining new alignment structures ==
 
New alignment can be defined using {{cmd|definemathalignment}}. For example, to emulate <code>gather</code> environment of amsmath, we can use
 
<context source=yes>
\definemathalignment
[gather]
[n=1,align={1:middle}]
 
\startformula \startgather
\NC ax^2 + bx + c = 0 \NR
\NC \text{roots} = \frac{ -b \pm \sqrt{b^2 - 4ac}}{2a} \NR
\stopgather \stopformula
 
</context>
== Cases ==
Context provides a <{{cmd>|startmathcases</cmd> <}} {{cmd>|stopmathcases</cmd> }} pair to make it easy to get cases.  <texcodecontext source=yes text="gives">
\startformula
\delta_{ij} = f(x) = \startmathcases \NC x, 1 \NC \text{if $0 \le x \le \frac12$ } i = j \NR \NC 1-x ,0 \NC if $\frac12 \le x \le 1$ text{otherwise} \NR \stopmathcases
\stopformula
</texcodecontext>
givesThe cases environment consists of two columns, separated by {{cmd|NC}}. The second column is by default in math mode. To typeset the second column in text mode, use {{cmd|TC}}
<contexttexcode>
\startformula
\delta_{ij} = f(x) = \startmathcases \NC x, 1 \NC TC if $0 \le x \le \frac12$ m{i = j} \NR \NC 1-x ,\NC if $0 \frac12 \le x \le 1$ TC otherwise \NR \stopmathcases
\stopformula
</contexttexcode>
The cases environment consists of two columns, separated by <cmd>NC</cmd>. The second column is by default in text mode. Each line must end with a <{{cmd>|NR</cmd>}}.
== Numbered Cases ==
 
[[Category:Math]]
107

edits

Navigation menu