Difference between revisions of "Math/Display"
Line 309: | Line 309: | ||
\stopplaceformula | \stopplaceformula | ||
− | % | + | % a reference ==> entry in the list of formulas |
\startplaceformula | \startplaceformula | ||
− | [reference=formula: | + | [reference=formula:mass1] % <====== here |
\startformula e=mc^2 \stopformula | \startformula e=mc^2 \stopformula | ||
\stopplaceformula | \stopplaceformula | ||
+ | |||
+ | % a reference + list ==> entry with number + additional text in the list | ||
+ | |||
+ | \startplaceformula | ||
+ | [reference=formula:mass2, | ||
+ | list={Mass-energy equivalence from list option}] | ||
+ | \startformula e=mc^2 \stopformula | ||
+ | \stopplaceformula | ||
+ | |||
+ | % a reference + title ==> entry with title text, no number | ||
\startplaceformula | \startplaceformula | ||
[title={Mass-energy equivalence}, % <====== here | [title={Mass-energy equivalence}, % <====== here | ||
− | reference=formula: | + | reference=formula:mass3] |
+ | \startformula e=mc^2 \stopformula | ||
+ | \stopplaceformula | ||
+ | |||
+ | % a reference + title + list ==> idem reference + title | ||
+ | |||
+ | \startplaceformula | ||
+ | [title={Mass-energy equivalence}, % <====== here | ||
+ | reference=formula:mass4, | ||
+ | list={Mass-energy equivalence from list option}] | ||
\startformula e=mc^2 \stopformula | \startformula e=mc^2 \stopformula | ||
\stopplaceformula | \stopplaceformula | ||
Line 330: | Line 349: | ||
To name a numbered formula in the list of formulas, one can use the list option: | To name a numbered formula in the list of formulas, one can use the list option: | ||
+ | |||
<context source=yes> | <context source=yes> | ||
% named formula | % named formula | ||
Line 335: | Line 355: | ||
\stopplaceformula | \stopplaceformula | ||
− | % numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas | + | % numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas |
\startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula | \startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula | ||
Revision as of 21:36, 11 May 2024
Contents
First \startformula
Display math is enclosed in a \startformula / \stopformula pair. Thus
The famous result (once more) is given by \startformula c^2 = a^2 + b^2 \stopformula
This, when typeset, produces the following:
Numbering Formulae \startformula
ConTeXt provides an easy way to number the display maths equations. Simply, insert the \startformula in the \startplaceformula environment, and you will get numbered equations.
The famous result (once more) is given by \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
This, when typeset, produces the following:
The \startplaceformula command is optional, and produces the equation number; leaving it off produces an unnumbered equation.
Referencing formulae \in and \at
Equations can be referred to by simply adding a label to \startplaceformula and using command for referencing :
- \ref (note that it expects two arguments, therefore you need the brackets twice),
- \in (a kind of \ref[number][TheRef],
- \at (a kind of \ref[page][TheRef].
\setupinteraction[state=start] The famous result (once more) is given by \startplaceformula[eq:myref] % <===== here \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula And now we can refer to its number by several ways, \startitemize \item with \tex{in} : formula \in[eq:myref] or \in{formula}{}[eq:myref] \item with \tex{at} : formula \in[eq:myref] \at{page}[eq:myref] \item with \tex{ref} : formula \ref[number] [eq:myref] page \ref[number] [eq:myref] \stopitemize
This, when typeset, produces the following:
By default, only the formula number appears as a reference. This can be changed by using \definereferenceformat. For example, to create a command \eqref
which shows the formula number in brackets, use
\setupinteraction[state=start] \definereferenceformat[eqref][left=(,right=)] The famous result (once more) is given by \startplaceformula[eq:myref] \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula And now we can refer to its number by several ways, \startitemize \item with \tex{in} : formula \in[eq:myref] or \in{formula}{}[eq:myref], \item with \tex{at} : formula \in[eq:myref] \at{page}[eq:myref], \item with \tex{ref} : formula \ref[number] [eq:myref] page \ref[number] [eq:myref], \item with \tex{eqref} : formula \eqref[eq:myref]. \stopitemize
This, when typeset, produces the following:
Sub-Formulae with \startsubformulas and \startalign
To use subformula numbering, you have to use \startsubformulas/\stopsubformulas and \startalign. For example
The famous result (once more) is given by Examples: \definereferenceformat[eqref][left=(,right=)] \startsubformulas[eq:total] \placeformula \startformula \startalign \NC a^2 + b^2 \NC = c^2 \NR[eq:first] \NC a^2 + b^2 \NC = c^2 \NR[eq:second] \stopalign \stopformula \stopsubformulas Formula \eqref[eq:total] states the Pythagora's Theorem twice, once in \eqref[eq:first] and again in \eqref[eq:second]. You can compare without \tex{startsubformulas}: \placeformula \startformula \startalign \NC a^2 + b^2 \NC = c^2 \NR[eq2:first] \NC a^2 + b^2 \NC = c^2 \NR[eq2:second] \stopalign \stopformula We now have references for \eqref[eq2:first] and \eqref[eq2:second].
This, when typeset, produces the following:
Formating with \setupformulas
Format of numbers
You can use \setupformulas to change the format of numbers. For example to get bold numbers inside square brackets use
The famous result (once more) is given by \setupformulas [left={[}, right={]}, numberstyle=bold] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
This, when typeset, produces the following:
To get equations also numbered by section,
use the command \setupnumbering \setupnumbering[way=bysection]
in the preamble of your document.
This means that the section number preceeds the formula number.
Add also \setupnumber \setupnumber[formula][way=bysection]
to reset with each new section.
The famous result (once more) is given by \setupformulas [left={[}, right={]}, numberstyle=bold] \setupnumbering [way=bysection] % to add the section number to the formula number \setupnumber [formula] [way=bysection] % to reset with each new section \startsection[title=First title] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \stopsection \startsection[title=Second title] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \stopsection
This, when typeset, produces the following:
To get alphabets instead of numbers, use again \setupformulas
The famous result (once more) is given by \setupformulas[numberconversion=Character] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[numberconversion=character] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
This, when typeset, produces the following:
Formula alignment
Normally a formula is centered, but in case you want to align it left or right, you can set up formulas to behave that way. Normally a formula will adapt its left indentation to the environment:
This is a bit of text for purpose of example. \startitemize \item This is some other example text. \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \item This is yet other example text. \stopitemize This is a bit more text for other purpose of example.
In the next examples we explicitly align formulas with \setupformulas, to the left (raggedleft
), center (middle
, and right (raggedright
):
\setuppapersize[A5] \setuplayout[textwidth=8cm] \setupformulas[align=left] \startformula c^2 = a^2 + b^2 \stopformula \setupformulas[align=middle] \startformula c^2 = a^2 + b^2 \stopformula \setupformulas[align=right] \startformula c^2 = a^2 + b^2 \stopformula
With formula numbers the code is:
\setuppapersize[A7,landscape] \setuplayout[textwidth=8cm] \starttext \setupformulas[align=flushleft] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[align=middle] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[align=flushright] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \stoptext
When tracing is turned on (\showboxes) you can visualize the bounding box of the formula,
The famous result (once more) is given by \showboxes \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
This, when typeset, produces the following:
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:
The famous result (once more) is given by \showboxes \setupformulas[align=middle,strut=yes] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]
You can influence the placement of the whole box with the parameters leftmargin and rightmargin.
The famous result (once more) is given by \showboxes \setupformulas[align=right,leftmargin=1em] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[align=right,leftmargin=3em] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[align=left,rightmargin=1em] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
You can also inherit the margin from the environment.
Some example text, again, to show where the right and left margins of the text block are. \showboxes \setupformulas[align=right] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula \setupformulas[align=right,margin=standard] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
The distance between the formula and the number is only applied when the formula is left or right aligned.
Some example text, again, to show where the right and left margins of the text block are. \showboxes \setupformulas[align=left,distance=2em] \startplaceformula \startformula c^2 = a^2 + b^2 \stopformula \stopplaceformula
List of Formulae with \placelist
Since MKIV there are two types of formulas: numbered and named. Numbered formulas have the number as a reference and caption next to the formula and are listed only with the number and pagenumber in the list of formulas. Named formulas use the name as the caption instead of a number and are referenced with the name and pagenumber in the list of formulas.
Three example: % no reference ==> no entry in the list of formulas \startplaceformula \startformula e=mc^2 \stopformula \stopplaceformula % a reference ==> entry in the list of formulas \startplaceformula [reference=formula:mass1] % <====== here \startformula e=mc^2 \stopformula \stopplaceformula % a reference + list ==> entry with number + additional text in the list \startplaceformula [reference=formula:mass2, list={Mass-energy equivalence from list option}] \startformula e=mc^2 \stopformula \stopplaceformula % a reference + title ==> entry with title text, no number \startplaceformula [title={Mass-energy equivalence}, % <====== here reference=formula:mass3] \startformula e=mc^2 \stopformula \stopplaceformula % a reference + title + list ==> idem reference + title \startplaceformula [title={Mass-energy equivalence}, % <====== here reference=formula:mass4, list={Mass-energy equivalence from list option}] \startformula e=mc^2 \stopformula \stopplaceformula This is the list: \placelist[formula][criterium=all,alternative=c]
\startplaceformula comes with the following key options: bookmark, list, reference, suffix, title.
To name a numbered formula in the list of formulas, one can use the list option:
% named formula \startplaceformula[reference=formula:mass,title={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula % numbered formula with list text, note without a reference option the formula is just a placeformula that is not listed in the list of formulas \startplaceformula[reference=formula:mass,list={Mass-energy equivalence}] \startformula e=mc^2 \stopformula \stopplaceformula \placelist[formula][criterium=text,alternative=c]
Note: The title option changes the formula to a named formula and will use that name in the list of formulas regardless of the list option.
Shaded background for part of a displayed equation
(see also Framed)
To highlight part of a formula, you can give it a gray background using \mframed: the following is the code you can use in mkii (see below what one has to do in mkiv):
\setuppapersize[A5] \setupcolors[state=start] \def\graymath{\mframed[frame=off, background=color, backgroundcolor=gray, backgroundoffset=3pt]} \startformula \ln (1+x) =\, \graymath{x - {x^2\over2}} \,+ {x^3\over3}-\cdots. \stopformula
In mkiv the code is slightly different: one may define \graymath directly using \definemathframed
\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
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…).