Difference between revisions of "Equation alignment"

From Wiki
Jump to navigation Jump to search
(Imported examples from core-mat.tex comments.)
 
({{Columns navbox}})
(13 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This set of math examples is taken from the comments in the <tt>core-mat.tex</tt> file, which contains most of the core ConTeXt math macros.
+
< [[Math]]
 +
 
 +
Be sure to also read the recent (2006-08-02) [http://dl.contextgarden.net/myway/mathalign.pdf Using \startalign and friends] written by Aditya Mahajan.
 +
 
 +
This set of math examples is taken from the comments in the [[source:core-mat.tex|core-mat.tex]] file, which contains most of the core ConTeXt math macros. The <tt>textwidth</tt> has been set to 8 cm in these examples so that the page isn't too wide (see [[Layout]] and <cmd>setuplayout</cmd> for further information specific to layout).
  
 
----
 
----
Line 7: Line 11:
  
 
<context>
 
<context>
 +
\setuplayout[textwidth=8cm]
 
This is a bit of text for purpose of example.\epar
 
This is a bit of text for purpose of example.\epar
 
\startitemize
 
\startitemize
Line 18: Line 23:
 
In the next examples we explicitly align formulas to the left (<cmd>raggedleft</cmd>), center and right (<cmd>raggedright</cmd>):
 
In the next examples we explicitly align formulas to the left (<cmd>raggedleft</cmd>), center and right (<cmd>raggedright</cmd>):
  
<texcode>
+
<context source="yes" text="Or in print:">
\setupformulas[align=left]
+
\setuplayout[textwidth=8cm]
\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
 
</texcode>
 
 
 
Or in print:
 
 
 
<context>
 
 
\setupformulas[align=left]
 
\setupformulas[align=left]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\startformula c^2 = a^2 + b^2 \stopformula
Line 38: Line 33:
 
</context>
 
</context>
  
With formula numbers these formulas look as follows:
+
With formula numbers the code is:
  
<context>
+
<context source="yes" text="And the formulas look like:">
 +
\setuplayout[textwidth=8cm]
 
\setupformulas[align=left]
 
\setupformulas[align=left]
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
Line 48: Line 44:
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</context>
 
</context>
 
This was keyed in as:
 
 
<texcode>
 
\setupformulas[align=left]
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\setupformulas[align=middle]
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\setupformulas[align=right]
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</texcode>
 
  
 
When tracing is turned on (<cmd>tracemathtrue</cmd>) you can visualize the bounding box of the formula,
 
When tracing is turned on (<cmd>tracemathtrue</cmd>) you can visualize the bounding box of the formula,
  
 
<context>
 
<context>
 +
\setuplayout[textwidth=8cm]
 
\tracemathtrue
 
\tracemathtrue
 
\setupformulas[align=left]
 
\setupformulas[align=left]
Line 74: Line 60:
 
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:
 
As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:
  
<texcode>
+
<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.]">
\setupformulas[strut=yes]
+
\setuplayout[textwidth=8cm]
\tracemathtrue
+
\setupformulas[align=middle,strut=yes]
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</texcode>
 
 
 
This time we get a more spacy result.
 
 
 
<context>
 
\setupformulas[strut=yes]
 
 
\tracemathtrue
 
\tracemathtrue
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
Line 90: Line 69:
 
We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space
 
We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space
  
<texcode>
+
<context source="yes">
\tracemathtrue
+
\setuplayout[textwidth=8cm]
\setupformulas[align=middle]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</texcode>
 
 
 
<context>
 
 
\tracemathtrue
 
\tracemathtrue
 
\setupformulas[align=middle]
 
\setupformulas[align=middle]
Line 106: Line 79:
 
You can influence the placement of the whole box with the parameters <tt>leftmargin</tt> and <tt>rightmargin</tt>.
 
You can influence the placement of the whole box with the parameters <tt>leftmargin</tt> and <tt>rightmargin</tt>.
  
<texcode>
+
<context source="yes">
Some example text, again, to show where the right and left margins of the text block are.
+
\setuplayout[textwidth=8cm]
\tracemathtrue
 
\setupformulas[align=right,leftmargin=3em]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
 
 
\setupformulas[align=left,rightmargin=1em]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</texcode>
 
 
 
<context>
 
 
Some example text, again, to show where the right and left margins of the text block are.
 
Some example text, again, to show where the right and left margins of the text block are.
 
\tracemathtrue
 
\tracemathtrue
Line 129: Line 91:
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</context>
 
</context>
 
  
 
You can also inherit the margin from the environment.
 
You can also inherit the margin from the environment.
  
<texcode>
+
<context source="yes">
Some example text, again, to show where the right and left margins of the text block are.
+
\setuplayout[textwidth=8cm]
\tracemathtrue
 
\setupformulas[align=right,margin=standard]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</texcode>
 
 
 
<context>
 
 
Some example text, again, to show where the right and left margins of the text block are.
 
Some example text, again, to show where the right and left margins of the text block are.
 
\tracemathtrue
 
\tracemathtrue
Line 151: Line 105:
 
The distance between the formula and the number is only applied when the formula is left or right aligned.
 
The distance between the formula and the number is only applied when the formula is left or right aligned.
  
<texcode>
+
<context source="yes">
 +
\setuplayout[textwidth=8cm]
 
\tracemathtrue
 
\tracemathtrue
 
\setupformulas[align=left,distance=2em]
 
\setupformulas[align=left,distance=2em]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
</texcode>
+
</context>
 +
 
 +
{{Columns navbox}}
  
<context>
+
[[Category:Math]]
\tracemathtrue
 
\setupformulas[align=left,distance=2em]
 
\startformula c^2 = a^2 + b^2 \stopformula
 
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
 
</context>
 

Revision as of 10:26, 1 October 2012

< Math

Be sure to also read the recent (2006-08-02) Using \startalign and friends written by Aditya Mahajan.

This set of math examples is taken from the comments in the core-mat.tex file, which contains most of the core ConTeXt math macros. The textwidth has been set to 8 cm in these examples so that the page isn't too wide (see Layout and \setuplayout for further information specific to layout).


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:

In the next examples we explicitly align formulas to the left (\raggedleft), center and right (\raggedright):

\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

Or in print:

With formula numbers the code is:

\setuplayout[textwidth=8cm]
\setupformulas[align=left]
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
\setupformulas[align=middle]
\placeformula \startformula c^2 = a^2 + b^2 \stopformula
\setupformulas[align=right]
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

And the formulas look like:

When tracing is turned on (\tracemathtrue) you can visualize the bounding box of the formula,

As you can see, the dimensions are the natural ones, but if needed you can force a normalized line:

\setuplayout[textwidth=8cm]
\setupformulas[align=middle,strut=yes]
\tracemathtrue
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

This time we get a more spacy result. [Ed. Note: For this example equation, there appears to be no visible change.]

We will now show a couple of more settings and combinations of settings. In centered formulas, the number takes no space

\setuplayout[textwidth=8cm]
\tracemathtrue
\setupformulas[align=middle]
\startformula c^2 = a^2 + b^2 \stopformula
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

You can influence the placement of the whole box with the parameters leftmargin and rightmargin.

\setuplayout[textwidth=8cm]
Some example text, again, to show where the right and left margins of the text block are.
\tracemathtrue
\setupformulas[align=right,leftmargin=3em]
\startformula c^2 = a^2 + b^2 \stopformula
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

\setupformulas[align=left,rightmargin=1em]
\startformula c^2 = a^2 + b^2 \stopformula
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

You can also inherit the margin from the environment.

\setuplayout[textwidth=8cm]
Some example text, again, to show where the right and left margins of the text block are.
\tracemathtrue
\setupformulas[align=right,margin=standard]
\startformula c^2 = a^2 + b^2 \stopformula
\placeformula \startformula c^2 = a^2 + b^2 \stopformula

The distance between the formula and the number is only applied when the formula is left or right aligned.

\setuplayout[textwidth=8cm]
\tracemathtrue
\setupformulas[align=left,distance=2em]
\startformula c^2 = a^2 + b^2 \stopformula
\placeformula \startformula c^2 = a^2 + b^2 \stopformula