ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Aditya Mahajan <adityam@umich.edu>
Subject: Guide on align (was Help : Unknown references)
Date: Thu, 23 Mar 2006 00:43:43 -0500 (EST)	[thread overview]
Message-ID: <Pine.WNT.4.63.0603230034200.2900@nqvgln> (raw)
In-Reply-To: <Pine.GSO.4.63.0603221628320.4164@rrpf4327h07.ratva.hzvpu.rqh>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 170 bytes --]

Here are a few details of _how I understand_ the align mechanism of 
context. Hope that others will find it useful. Any suggestions for 
improvement are welcome.

Aditya

[-- Attachment #2: Type: APPLICATION/octet-stream, Size: 6595 bytes --]

\setupcolors[state=start]
\definecolor [BufferColor] [r=1,g=1,b=0.5]

\setuptyping[option=color]
\gdef\ShowExample{
  \blank
  \framed[align=normal,width=broad,frame=off,background=screen]
  {\tfx \typebuffer}
  \framed[align=normal,width=broad,frame=off,
  background=color,backgroundcolor=BufferColor] {\getbuffer}}

\starttext
\section{Basic Alignment}
The purpose of this document is to show how to do multi-line display equations 
in \CONTEXT. Hans has provided a configurable align environment that can be 
used for general purpose multiline display equations. Lets look at few 
examples to understand how it works. In many cases, we need to align a 
sequence of equations at the $=$ sign. This is how it can be done
\startbuffer
\startformula \startalign
  \NC a_1 x + b_1 y \NC = c_1 \NR
  \NC a_2 x + b_2 y \NC = c_2 \NR
\stopalign \stopformula
\stopbuffer
\ShowExample

Lets look at how this is working. The \tex{startformula} starts the \CONTEXT 
display mode, \tex{startalign} moves to the multiline display mode. \tex{NC} 
specifies to start a {\em New Column} is starting and \tex{NR} specifies to 
start a {\em New Row}. By default, the first column is right aligned and the 
second is left aligned. You can increase the number of alignments by 
specifying \type{n=?} as options to \tex{startalign}. By default all the new 
columns are left aligned.
\startbuffer
\startformula \startalign[n=3]
  \NC a_1 x + b_1 y \NC = c_1 \NC =  d_1 u + e_1 v \NR
  \NC a_2 x + b_2 y \NC = c_2 + c_3 \NC =  d_2 u + e_2 v + f_1 w\NR
\stopalign \stopformula
\stopbuffer
\ShowExample

The default column alignment can be changed by using 
\type<<align={...,...,...}>> construct. This is a comma separated list, each 
value is either \type{right}, \type{left} or \type{middle}.  For example, to 
get the second column to be middle aligned, we can specify \type<<[n=3, 
align={right,middle,left}]>>
\startbuffer
\startformula \startalign[n=3, align={right,middle,left}]
  \NC a_1 x + b_1 y \NC = c_1 \NC =  d_1 u + e_1 v \NR
  \NC a_2 x + b_2 y \NC = c_2 + c_3 \NC =  d_2 u + e_2 v + f_1 w\NR
\stopalign \stopformula
\stopbuffer
\ShowExample

Oops, this doesn't look too good. We need to specify each \type{=} sign as a 
separate column.
\startbuffer
\startformula \startalign[n=4, align={right,middle,middle,left}]
  \NC a_1 x + b_1 y \NC = \NC c_1 \NC =  d_1 u + e_1 v \NR
  \NC a_2 x + b_2 y \NC = \NC c_2 + c_3 \NC =  d_2 u + e_2 v + f_1 w\NR
\stopalign \stopformula
\stopbuffer
\ShowExample

Sometimes one wants to have two columns of equations, next to one another.  
This can be done by specifying the number of blocks in \type<<m=?>>.
\startbuffer
\startformula \startalign[m=2]
  \NC a_1 x + b_1 y \NC = c_1 \NC d_1 u + e_1 v \NC = f_1 \NR
  \NC a_2 x + b_2 y \NC = c_2 \NC d_2 u + e_2 v \NC = f_2 \NR
\stopalign \stopformula
\stopbuffer
\ShowExample

The distance between the blocks can be increased by specifying (well you 
guessed it) \type<<distance>> in the parameters of align.
\startbuffer
\startformula \startalign[m=2,distance=5em]
  \NC a_1 x + b_1 y \NC = c_1 \NC d_1 u + e_1 v \NC = f_1 \NR
  \NC a_2 x + b_2 y \NC = c_2 \NC d_2 u + e_2 v \NC = f_2 \NR
\stopalign \stopformula
\stopbuffer
\ShowExample

However, this block mode can be cumbersome to work with. You need to work with 
two formulas at the same time and this can be confusing. There is another 
alternative in \tex{startformulas}
\startbuffer
\startformulas
  \startformula \startalign
    \NC a_1 x + b_1 y \NC = c_1 \NR
    \NC a_2 x + b_2 y \NC = c_2 \NR
  \stopalign \stopformula
  \startformula \startalign
    \NC d_1 u + e_1 v \NC = f_1 \NR
    \NC d_2 u + e_2 v \NC = f_2 \NR
  \stopalign \stopformula
\stopformulas
\stopbuffer
\ShowExample

More than two groups can also be placed.
\startbuffer
\startformulas
    \dorecurse{5}{\startformula
        \startalign[n=3,align={middle,middle,middle}]
            \NC a  \NC = \NC b  \NR
            \NC 2a \NC = \NC 2b \NR
        \stopalign
    \stopformula}
\stopformulas
\stopbuffer
\ShowExample

\section{Equation Numbering and referring}
To number multiline displays, two things need to be done. Write 
\tex{placeformula} before \tex{startformula} to {\em start up} equation 
numbering. To actually number the equations, you need to type \type{[+]} with 
each \tex{NR}. Going back to our basic example

\startbuffer
\placeformula
\startformula \startalign
  \NC a_1 x + b_1 y \NC = c_1 \NR[+]
  \NC a_2 x + b_2 y \NC = c_2 \NR[+]
\stopalign \stopformula
\stopbuffer
\ShowExample

If you only want to number a some specific equations, just add \type<<[+]>> to 
that equation only. Suppose in the above example, we want to only number the 
second equation.
\startbuffer
\placeformula
\startformula \startalign
  \NC a_1 x + b_1 y \NC = c_1 \NR
  \NC a_2 x + b_2 y \NC = c_2 \NR[+]
\stopalign \stopformula
\stopbuffer
\ShowExample

Some more examples \unknown
\startbuffer
\placeformula
\startformula \startalign[n=3, align={right,middle,left}]
  \NC a_1 x + b_1 y \NC = c_1 \NC =  d_1 u + e_1 v \NR[+]
  \NC a_2 x + b_2 y \NC = c_2 + c_3 \NC =  d_2 u + e_2 v + f_1 w\NR
\stopalign \stopformula
\stopbuffer
\ShowExample


\startbuffer
\placeformula
\startformula \startalign[m=2]
  \NC a_1 x + b_1 y \NC = c_1 \NC d_1 u + e_1 v \NC = f_1 \NR
  \NC a_2 x + b_2 y \NC = c_2 \NC d_2 u + e_2 v \NC = f_2 \NR[+]
\stopalign \stopformula
\stopbuffer
\ShowExample
\startbuffer
\placeformula
\startformulas
  \startformula \startalign
    \NC a_1 x + b_1 y \NC = c_1 \NR[+]
    \NC a_2 x + b_2 y \NC = c_2 \NR
  \stopalign \stopformula
  \startformula \startalign
    \NC d_1 u + e_1 v \NC = f_1 \NR
    \NC d_2 u + e_2 v \NC = f_2 \NR[+]
  \stopalign \stopformula
\stopformulas
\stopbuffer
\ShowExample

There is no fun numbering equations if can not refer to it. Well, referencing 
an equation is easy. Instead of the \type<<[+]>>, you can specify 
\type<<[eq:tag]>> and then refer to the equation using \type{\in[eq:tag]}. For 
example,

\startbuffer
\placeformula
\startformula \startalign
  \NC a_1 x + b_1 y \NC = c_1 \NR[eq:1]
  \NC a_2 x + b_2 y \NC = c_2 \NR[eq:2]
\stopalign \stopformula
As seen from (\in[eq:1]) and (\in[eq:2]), referring equations is straight 
forward.
\stopbuffer
\ShowExample

{\bf Note that you need to put the tag with the \tex{NR} and not with 
\tex{placeformula} (as is done with single line equations).}


\section{Some Advanced Tips}
Well, need to understand more myself before writing this. Write about 
\tex{setupalign}, \tex{definealign}. Give examples of defining \type<<gather>> 
and \type<<split>> environments.




\stoptext

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
ntg-context mailing list
ntg-context@ntg.nl
http://www.ntg.nl/mailman/listinfo/ntg-context

  reply	other threads:[~2006-03-23  5:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-21 19:42 Help : Unknown references WN
2006-03-21 23:43 ` Aditya Mahajan
2006-03-22 16:33   ` WN
2006-03-22 16:55     ` Taco Hoekwater
2006-03-22 21:57       ` Aditya Mahajan
2006-03-23  5:43         ` Aditya Mahajan [this message]
2006-03-24 16:54           ` Guide on align (was Help : Unknown references) WN
2006-03-24 18:06             ` Aditya Mahajan
2006-03-24 20:45               ` Taco Hoekwater
2006-03-24 21:40                 ` Aditya Mahajan
2006-03-27  8:37                   ` Taco Hoekwater
2006-03-24 21:41               ` Hans Hagen
2006-03-27 14:24           ` Hans Hagen
2006-03-27 14:40             ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.WNT.4.63.0603230034200.2900@nqvgln \
    --to=adityam@umich.edu \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).