ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* math align
@ 2006-01-15 22:37 Hans Hagen
  2006-01-16  3:31 ` Aditya Mahajan
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Hans Hagen @ 2006-01-15 22:37 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Hi,

Here a first attempts for a flexible alignment mechanism (i depend on 
taco for the fine points of math typesetting since he's typeset \infty 
more complex formulas than i have)

(n=n_of_columns, m=n_of_pairs, so both requested multiple column 
features are supported)

Hans

[-- Attachment #2: math-ext.tex --]
[-- Type: text/x-tex, Size: 6363 bytes --]

%D \module
%D   [       file=math-ext,
%D        version=2006.01.14,
%D          title=\CONTEXT\ Math Macros,
%D       subtitle=Extra Macros,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright=\PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% some simple math constructs (based on user requests)
%
% preliminary

\unprotect

% adapted stuff

% we need to make this plain code a bit more 'readable'

\def\openup
  {\afterassignment\dopenup\scratchdimen=}

\def\dopenup
  {\advance\lineskip     \scratchdimen
   \advance\baselineskip \scratchdimen
   \advance\lineskiplimit\scratchdimen}

\def\jot{.25\bodyfontsize} % plain tex: 3 pt (todo: better name)

\newif\ifdt@p

\def\displ@y % \presetdisplayspacing or so
  {\global\dt@ptrue
   \openup\jot
   \mathsurround\zeropoint
   \everycr{\noalign{%
      \ifdt@p
        \global\dt@pfalse
        \ifdim\prevdepth>-\thousandpoint
          \vskip-\lineskiplimit
          \vskip\normallineskiplimit
        \fi
      \else
        \penalty\interdisplaylinepenalty
      \fi}}}

% context (hooks)

\let\normaldispl@y\displ@y

\def\displ@y{\resetdisplaymatheq\normaldispl@y}

\let\presetdisplaymath\displ@y

% plain tex value: \centering = 0pt plus 1000pt minus 1000pt
% plain tex valye: \jot = 3pt

% n>1 #### needed, strange # interaction (maybe we need a toks in recurse ane no macro)

\def\buildeqalign
  {\scratchtoks\emptytoks
   \dorecurse\@@eqm
     {\ifnum\recurselevel>\plusone\appendtoks\tabskip\@@eqdistance&\tabskip\zeropoint\to\scratchtoks\fi
      \expanded{\scratchtoks{\the\scratchtoks\the\!!toksa}}%
      \dorecurse{\numexpr\@@eqn-\plusone\relax}
        {\expanded{\scratchtoks{\the\scratchtoks\the\!!toksb}}}}%
   \expanded{\scratchtoks{\the\scratchtoks\the\!!toksc}}}

\def\forgetalign
  {\tabskip\zeropoint\everycr\emptytoks}

\def\eqalign#1% why no halign here, probably because of displaywidth
  {\!!toksa{\strut\hfil$\displaystyle{##}$}%
   \!!toksb{&$\displaystyle{{}##}$\hfil}%
   \!!toksc\emptytoks
   \buildeqalign
   \null\,\vcenter
     {\openup\jot
      \mathsurround\zeropoint
      \expandafter \ialign \expandafter {\the\scratchtoks\crcr#1\crcr}%
   }\,}

\def\eqalignno#1%
  {\!!toksa{\hfil$\forgetalign\displaystyle{##}$\tabskip\zeropoint}%
   \!!toksb{&$\forgetalign\displaystyle{{}##}$\tabskip\zeropoint}%
   \!!toksc{\hfil\tabskip\centering&\llap{$\forgetalign##$}\tabskip\zeropoint}%
   \buildeqalign
   \presetdisplaymath
   \tabskip\centering
   \halign to \displaywidth \expandafter {\the\scratchtoks\crcr#1\crcr}}

\def\leqalignno#1%
  {\!!toksa{\hfil$\forgetalign\displaystyle{##}$\tabskip\zeropoint}%
   \!!toksb{&$\forgetalign\displaystyle{{}##}$\tabskip\zeropoint}%
   \!!toksc{\hfil\tabskip\centering&\kern-\displaywidth\rlap{$\forgetalign##$}\tabskip\displaywidth}%
   \buildeqalign
   \presetdisplaymath
   \tabskip\centering
   \halign to \displaywidth \expandafter {\the\scratchtoks\crcr#1\crcr}}

\definesystemvariable{eq}

\def\setupmathalign
  {\dodoubleargument\getparameters[\??eq]}

\setupmathalign
  [\c!n=2,
   \c!m=1,
   \c!distance=1em]

\def\numberedeqalign
  {\doifelse\@@fmlocation\v!left\leqalignno\eqalignno}

\def\doalignNR[#1][#2]%
  {\doifsomething{#1}
     {\doifelse{#1}{+}
        {\doformulanumber[][#2][]{}}
        {\doformulanumber[#1][#2][]{}}}}

\def\startalign
  {\dosingleempty\dostartalign}

\long\def\dostartalign[#1]#2\stopalign
  {\doifassignmentelse{#1}{\setupmathalign[#1]}\donothing
   \def\NC{\crcr\def\NC####1{&####1}}%
   \def\EQ{&=}
   \def\NR{&\dodoubleempty\doalignNR}%
   % amstex compatibility mode: (ugly)
   \def\notag{\def\\{&\crcr}}%
   \doifelse{#1}{*}{\def\\{&\crcr}}{\def\\{&\doalignNR[+][]\crcr}}%
   % end of compatibility mode
   \numberedeqalign{#2}}

%D \startbuffer
%D \placeformula \startformula \eqalignno {
%D  a &= b & \formulanumber \cr
%D  c &= d \cr
%D    &= e \cr
%D    &= f & \formulanumber
%D } \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D \NC  a \EQ b \NR[+]
%D \NC  c \EQ d \NR
%D \NC    \EQ f \NR[for:hans]
%D \NC    \EQ g \NR[for:whoelse][a]
%D \NC    \EQ h \NR[for:whomore][b]
%D \NC    \EQ i \NR
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D \NC a \EQ b \NR[+]
%D \NC c \EQ d \NR
%D \NC   \EQ f \NR
%D \NC   \EQ g \NR
%D \NC   \EQ h \NR
%D \NC   \EQ i \NR[+]
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D a &= b \\
%D c &= d \notag \\
%D   &= e \notag \\
%D   &= f \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D a &= b \NR[+]
%D c &= d \NR
%D   &= e \NR
%D   &= f \NR[+]
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D \NC  a \NC \eq  b \NR[+]
%D \NC  c \NC \neq d \NR
%D \NC    \NC \neq f \NR[for:hans]
%D \NC    \NC \geq g \NR[for:whoelse][a]
%D \NC    \NC \leq h \NR[for:whomore][b]
%D \NC    \NC \neq i \NR
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign[*]
%D a &= b \\
%D c &= d \notag \\
%D   &= e \notag \\
%D   &= f \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign
%D     x &= y \\
%D     a &= b \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign[m=3]
%D     x &= y & x &= y & z &= t \\
%D     a &= b & p &= q & w &= s \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign[m=3,distance=0pt]
%D     x &= y &= x &= y &= z &= t \\
%D     a &= b &= p &= q &= w &= s \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer
%D
%D \startbuffer
%D \placeformula \startformula \startalign[n=5,distance=0pt]
%D     x &= yy &= xx &= yy &= zz \\
%D     a &= b  &= p  &= q  &= w  \\
%D \stopalign \stopformula
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\protect \endinput

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

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

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2006-01-17  3:02 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-15 22:37 math align Hans Hagen
2006-01-16  3:31 ` Aditya Mahajan
2006-01-16  6:17 ` David Arnold
2006-01-16  7:30 ` David Arnold
2006-01-16  9:02   ` Taco Hoekwater
2006-01-16 12:30     ` Hans Hagen
2006-01-16 15:40       ` Mojca Miklavec
2006-01-16 16:38         ` Hans Hagen
2006-01-16 19:47           ` Aditya Mahajan
2006-01-16 21:43             ` Hans Hagen
2006-01-16 23:03               ` Aditya Mahajan
2006-01-17  3:02       ` Aditya Mahajan
2006-01-16 18:01     ` David Arnold
2006-01-16 18:16       ` Hans Hagen
2006-01-16 18:22         ` David Arnold
2006-01-16 19:45           ` Hans Hagen
2006-01-16 18:42         ` David Arnold
2006-01-16 20:41           ` Hans Hagen
2006-01-16 23:19             ` David Arnold
2006-01-16 18:20       ` Taco Hoekwater
2006-01-16 19:09         ` David Arnold
2006-01-16 20:18           ` Hans Hagen

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).