Changes

Jump to navigation Jump to search
1,354 bytes added ,  16:29, 27 February 2017
no edit summary
< [[Math]]|>
= Display Math =
Display math is enclosed in a <{{cmd>|startformula<}} /{{cmd> / <cmd>|stopformula</cmd> }} pair. Thus
<table width="100%" cols="2"><tr valign="top"><td width="50%">
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
The famous result (once more) is given by
\startformula
= Numbering Formulae =
ConTeXt provides an easy way to number the display maths equations. Simply, put <{{cmd>|placeformula</cmd> }} before <{{cmd>|startformula</cmd> / <cmd>stopformula</cmd> pair }} and you will get numbered equations. Thus,
<table width="100%" cols="2"><tr valign="top"><td width="50%">
<texcode>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
The famous result (once more) is given by
\placeformula
</td></tr></table>
The <{{cmd>|placeformula</cmd> }} command is optional, and produces the equation number; leaving it off produces an unnumbered equation.
== Changing format of numbers ==
You can use <{{cmd>|setupformulas</cmd> }} to change the format of numbers. For example to get bold numbers inside square brackets use
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%">
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
\setupformulas[left={[},right={]},numberstyle=bold]
The famous result (once more) is given by
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%">
<texcode>
\setupformulas[conversionnumberconversion=Character]
</texcode>
</td>
<td>which gives
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]\setupformulas[conversionnumberconversion=Character]
\placeformula
\startformula
<context>
\setuppapersize[A5]
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
This is a bit of text for purpose of example.\epar
</context>
In the next examples we explicitly align formulas to the left (<{{cmd>|raggedleft</cmd>}}), center and right (<{{cmd>|raggedright</cmd>}}):
<context source="yes" text="Or in print:">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\setupformulas[align=left]
<context source="yes" text="And the formulas look like:">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\setupformulas[align=left]
</context>
When tracing is turned on (<{{cmd>|tracemathtrue</cmd>}}) you can visualize the bounding box of the formula,
<context>
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\tracemathtrue
<context source="yes" text="This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\setupformulas[align=middle,strut=yes]
<context source="yes">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\tracemathtrue
<context source="yes">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
Some example text, again, to show where the right and left margins of the text block are.
<context source="yes">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
Some example text, again, to show where the right and left margins of the text block are.
<context source="yes">
\setuppapersize[A5]
\setuplayout[textwidth=8cm]
\tracemathtrue
= Referencing formulae =
Equations can be referred to by simply adding a label to <{{cmd>|placeformula</cmd> }} and using <{{cmd>|ref</cmd> }} to create the reference:
<table width="100%" cols="2" cellpadding="5"><tr valign="top"><td width="50%">
c^2 = a^2 + b^2.
\stopformula
And now we can refer to formula \ref[][formulalabel].
</texcode>
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
The famous result (and again) is given by
\placeformula[formulalabel]
c^2 = a^2 + b^2.
\stopformula
% number is added manually because otherwise only '??' appears:And now we can refer to formula 1\ref[][formulalabel].
</context>
</td></tr></table>
Note, that {{cmd|ref}} expects two arguments, therefore you need the brackets twice. By default, only the formula number appears as a reference. This can be changed by using <{{cmd>|definereferenceformat</cmd>}}. For example, to create a command <code>\eqref</code> which shows the formula number in brackets, use
<texcode>
\definereferenceformat[eqref][left=(,right=)]
</texcode>
See [[References]] for more examples of <{{cmd>|definereferenceformat</cmd>}}.
=Sub-Formula Numbering=
== Automatic Sub-Formula Numbering ==
To use subformula numbering, you can use <{{cmd>|startsubformulas<}}/{{cmd>/<cmd>|stopsubformulas</cmd>}}. For example
<table width="100%" cols="2"><tr valign="top"><td width="50%">
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
Examples:
\startsubformulas[eq:1]
== The Manual Method ==
Sometimes, you need more fine grained control over numbering of subformulas. In that case one can make use of the optional agument of <{{cmd>|placeformula</cmd> }} command and the related <{{cmd>|placesubformula</cmd> }} commands which can be used to produce sub-formula numbering. For example:
<table width="100%" cols="2"><tr valign="top"><td width="50%">
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
Examples:
\placeformula{a}
</td></tr></table>
What's going on here is simpler than it might appear at first glance. Both <{{cmd>|placeformula</cmd> }} and <{{cmd>|placesubformula</cmd> }} produce equation numbers with the optional tag added at the end; the sole difference is that the former increments the equation number first, while the latter does not (and thus can be used for the second and subsequent formulas that use the same formula number but presumably have different tags).
This is sufficient for cases where the standard ConTeXt equation numbers suffice, and where only one equation number is needed per formula. However, there are many cases where this is insufficient, and <{{cmd>|placeformula</cmd> }} defines <{{cmd>|formulanumber</cmd> }} and <{{cmd>|subformulanumber</cmd> }} commands, which provide hooks to allow the use of ConTeXt-managed formula numbers with plain TeX equation numbering. These, when used within a formula, simply return the formula number in properly formatted form, as can be seen in this simple example with plain TeX's <{{cmd>|eqno</cmd>}}. Note that the optional tag is inherited from <{{cmd>|placeformula</cmd>}}.
<table width="100%" cols="2"><tr valign="top"><td width="50%">
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
More examples:
\placeformula{c}
</td></tr></table>
In order for this to work properly, we need to turn off ConTeXt's automatic formula number placement; thus the <{{cmd>|let</cmd> }} command to empty <{{cmd>|doplaceformulanumber</cmd>}}, which must be placed <em>after</em> the start of the formula. In many practical examples, however, this is not necessary; ConTeXt redefines <{{cmd>|displaylines</cmd> }} and <{{cmd>|eqalignno</cmd> }} to do this automatically.
For more control over sub-formula numbering, <{{cmd>|formulanumber</cmd> }} and <{{cmd>|subformulanumber</cmd> }} have an optional argument parallel to that of <{{cmd>|placeformula</cmd>}}, as demonstrated in this use of plain TeX's <{{cmd>|eqalignno</cmd>}}, which places multiple equation numbers within one formula.
<table width="100%" cols="2"><tr valign="top"><td width="50%">
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
\placeformula
\startformula
</td></tr></table>
Note that both <{{cmd>|formulanumber</cmd> }} and <{{cmd>|subformulanumber</cmd> }} can be used within the same formula, and the formula number is incremented as expected. Also, if an optional argument is specified in both <{{cmd>|placefigure</cmd> }} and <{{cmd>|formulanumber</cmd>}}, the latter takes precedence.
<table width="100%" cols="2"><tr valign="top"><td width="50%">
</td><td>
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=8cm]
More examples for left-located equation no.:
\setupformulas[location=left]
=List of Formulas=
You can have a list of the formulas contained in a document by using <{{cmd>|placenamedformula</cmd> }} instead of <{{cmd>|placeformula</cmd>}}. Only the formulas written with <{{cmd>|placenamedformula</cmd> }} are not put in the list, so that you can control precisely the content of the list.
<{{cmd>|placenamedformula</cmd> }} takes as first parameter the name of the formula put in the list. The other <{{cmd>|placeformula</cmd> }} features are still available. The list can be formatted like any other list.
Example:
<context>
\setuppapersize[A5]\setuplayout[scale=0.8,width=13cm]
\subsubject{List of Formulas}
\placelist[formula][criterium=text,alternative=c]
(see also [[Framed]])
To highlight part of a formula, you can give it a gray background using <{{cmd>|mframed</cmd>}}: the following is the code you can use in mkii (see below what one has to do in mkiv):
<context source="yes">
\setuppapersize[A5]
\setupcolors[state=start]
\def\graymath{\mframed[frame=off,
\ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots.
\stopformula
</context>
 
In mkiv the code is slightly different: one may define {{cmd|graymath}} directly using {{cmd|definemathframed}}
 
<texcode>
\setuppapersize[A5]
\definemathframed[graymath]
[
frame=off,
location=mathematics,
background=color,
backgroundcolor=lightgray,
backgroundoffset=2pt
]
\starttext
Since for $|x| < 1$ we have
\startformula
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots
\stopformula
we may write $\log(1+x) = x + O(x^2)$.
\stoptext
</texcode>
 
The result is shown below (possibly the framed part of the formula is not aligned correctly with the remainder of the formula because the mkiv engine on Context Garden is not up to date…).
 
<context mode=mkiv>
\setuppapersize[A5]
\definemathframed[graymath]
[
frame=off,
location=mathematics,
background=color,
backgroundcolor=lightgray,
backgroundoffset=2pt
]
 
Since for $|x| < 1$ we have
\startformula
\log(1+x) = \graymath{x- \displaystyle{x^2\over2}} + {x^3 \over 3} + \cdots
\stopformula
we may write $\log(1+x) = x + O(x^2)$.
</context>

Navigation menu