mdwtab.dtx 170 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444
  1. % \begin{meta-comment}
  2. %
  3. % $Id$
  4. %
  5. % Another rewrite of the tabular environment, and maths alignments
  6. %
  7. % (c) 1996 Mark Wooding
  8. %
  9. %----- Revision history -----------------------------------------------------
  10. %
  11. % $Log$
  12. % Revision 1.1 1998-09-21 10:19:01 michael
  13. % Initial implementation
  14. %
  15. % Revision 1.8 1996/12/09 23:20:42 mdw
  16. % (\tab@setstrut): Fixed so that it uses \dimen\tw@ for the strut depth,
  17. % as advertised.
  18. %
  19. % Revision 1.7 1996/11/29 21:59:16 mdw
  20. % Fixed a little formatting mistake in a syntax diagram, and switched over
  21. % to the new syntax diagram commands on the grounds that they're slightly
  22. % less messy. Maybe.
  23. %
  24. % Revision 1.6 1996/11/19 20:54:33 mdw
  25. % Entered into RCS
  26. %
  27. %
  28. % \end{meta-comment}
  29. %
  30. % \begin{meta-comment} <general public licence>
  31. %%
  32. %% mdwtab package -- another rewrite of the tabular environment, etc.
  33. %% Copyright (c) 1996 Mark Wooding
  34. %%
  35. %% This program is free software; you can redistribute it and/or modify
  36. %% it under the terms of the GNU General Public License as published by
  37. %% the Free Software Foundation; either version 2 of the License, or
  38. %% (at your option) any later version.
  39. %%
  40. %% This program is distributed in the hope that it will be useful,
  41. %% but WITHOUT ANY WARRANTY; without even the implied warranty of
  42. %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  43. %% GNU General Public License for more details.
  44. %%
  45. %% You should have received a copy of the GNU General Public License
  46. %% along with this program; if not, write to the Free Software
  47. %% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  48. %%
  49. % \end{meta-comment}
  50. %
  51. % \begin{meta-comment} <Package preambles>
  52. %<+mdwtab>\NeedsTeXFormat{LaTeX2e}
  53. %<+mdwtab>\ProvidesPackage{mdwtab}
  54. %<+mdwtab> [1998/04/28 1.9 Table typesetting with style]
  55. %<+mathenv>\NeedsTeXFormat{LaTeX2e}
  56. %<+mathenv>\ProvidesPackage{mathenv}
  57. %<+mathenv> [1998/04/28 1.9 Various maths environments]
  58. % \end{meta-comment}
  59. %
  60. % \CheckSum{2758}
  61. %% \CharacterTable
  62. %% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
  63. %% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
  64. %% Digits \0\1\2\3\4\5\6\7\8\9
  65. %% Exclamation \! Double quote \" Hash (number) \#
  66. %% Dollar \$ Percent \% Ampersand \&
  67. %% Acute accent \' Left paren \( Right paren \)
  68. %% Asterisk \* Plus \+ Comma \,
  69. %% Minus \- Point \. Solidus \/
  70. %% Colon \: Semicolon \; Less than \<
  71. %% Equals \= Greater than \> Question mark \?
  72. %% Commercial at \@ Left bracket \[ Backslash \\
  73. %% Right bracket \] Circumflex \^ Underscore \_
  74. %% Grave accent \` Left brace \{ Vertical bar \|
  75. %% Right brace \} Tilde \~}
  76. %%
  77. %
  78. % \begin{meta-comment}
  79. %
  80. %<*driver>
  81. \input{mdwtools}
  82. \describespackage{mdwtab}
  83. \describespackage{mathenv}
  84. \addcontents{lot}{\listoftables}
  85. \mdwdoc
  86. %</driver>
  87. %
  88. % \end{meta-comment}
  89. %
  90. %^^A-------------------------------------------------------------------------
  91. % \renewcommand{\tabstyle}{\small}
  92. %
  93. % \section{User guide}
  94. %
  95. %
  96. % The \package{mdwtab} package contains a reimplementation of the standard
  97. % \LaTeX\ \env{tabular} and \env{array} environments. This is not just an
  98. % upgraded version: it's a complete rewrite. It has several advantages over
  99. % the official \package{array} package (not raw \LaTeX's, which is even less
  100. % nice), and it's more-or-less compatible. Most of these are rather
  101. % technical, I'll admit.
  102. %
  103. % \begin{itemize}
  104. %
  105. % \item The newcolumn system is properly and perfectly integrated into the
  106. % system. There are now \emph{no} `primitive' column types -- all the
  107. % standard types are created as user-defined columns.
  108. %
  109. % \item You can define entirely different table-like environments using the
  110. % equipment here. It's still hard work, although less so than before.
  111. % I'll do an example of this some time.
  112. %
  113. % \item Construction of the preamble is generally much tidier. I've used
  114. % token registers rather than |\edef|, and it's all done very nicely.
  115. %
  116. % \item Fine spacing before and after rules (described by DEK as `a mark of
  117. % quality') is now utterly trivial, since the preamble-generator will
  118. % store the appropriate information.
  119. %
  120. % \item You can use \env{array} in LR and paragraph modes without having
  121. % to surround it with `|$|' signs.
  122. %
  123. % \item Usually you don't want tables in the middle of paragraphs. For these
  124. % cases, I've provided a simpler way to position the table
  125. % horizontally.
  126. %
  127. % \item Footnotes work properly inside \env{tabular} environments (hoorah!).
  128. % You can `catch' footnotes using the \env{minipage} environment if
  129. % you like. (It uses an internal version of the \package{footnote}
  130. % package to handle footnotes, which doesn't provide extra goodies like
  131. % the \env{footnote} environment; you'll need to load the full package
  132. % explicitly to get them.)
  133. %
  134. % \item Standard \LaTeX\ tabular environments have a problem with lining up
  135. % ruled tables. The |\firsthline| command given in the \textit{\LaTeX\
  136. % Companion} helps a bit, but it's not really good enough, and besides,
  137. % it doesn't \emph{actually} line the text up right after all. The
  138. % \package{mdwtab} package does the job properly to begin with, so you
  139. % don't need to worry.
  140. %
  141. % \end{itemize}
  142. %
  143. % I've tested the following packages with \package{mdwtab}, and they all
  144. % work. Some of the contortions required to make them work weren't pleasant,
  145. % but you don't need to know about them. By a strange coincidence, all the
  146. % packages were written by David Carlisle. Anyway, here's the list:
  147. % \begin{itemize}
  148. % \item The quite nice \package{dcolumn} package.
  149. % \item The more useful \package{delarray} package.
  150. % \item The rather spiffy \package{hhline} package.
  151. % \item The truly wonderful \package{tabularx} package.
  152. % \item The utterly magnificent \package{longtable} package.
  153. % \end{itemize}
  154. %
  155. % Note that I've looked at \package{supertabular} as well: it won't work, so
  156. % use \package{longtable} instead, 'cos it's much better.
  157. %
  158. %
  159. % \subsection{The downside}
  160. %
  161. % There's no such thing as a free lunch. The \package{mdwtab} environment
  162. % is not 100\% compatible with the \env{tabular} environment found in
  163. % \LaTeXe\ or the \package{array} package.
  164. %
  165. % The differences between \package{mdwtab} and \LaTeXe's \env{tabular}
  166. % environment are as follows:
  167. %
  168. % \begin{itemize} \synshorts \let\`=\lq
  169. %
  170. % \item The vertical spacing in \env{array} environments is different to
  171. % that in \env{tabular} environments. This produces more attractive
  172. % results in most mathematical uses of \env{array}s, in the author's
  173. % opinion. The spacing can be modified by playing with length
  174. % parameters.
  175. %
  176. % \item The presence of horizontal and vertical rules will alter the spacing
  177. % of the table (so a pair of columns separated by a `|' is wider than
  178. % a pair with no separation by "\\arrayrulewidth". This does mean that
  179. % horizontal and vertical rules match up properly -- the usual \LaTeX\
  180. % environment makes the horizontal rules stop just short of the edge
  181. % of the table, making an ugly mess (check out the \textit{\LaTeX\
  182. % book} if you don't believe me -- page~62 provides a good example).
  183. % The \package{array} package handles rules in the same way as
  184. % \package{mdwtab}.
  185. %
  186. % \setbox0=\hbox{\footnotesize`\\def\\xcs{\\tabskip=\\fill}'}
  187. % \setbox2=\hbox{\footnotesize`...@{\\span\\xcs}...'}
  188. % \item In common with the \package{array} package, there are some
  189. % restrictions on the use of the "\\extracolsep" command in preambles:
  190. % you may use at most one "\\extracolsep" command in each `@' or `!'
  191. % expression. Also, you can't say
  192. % \begin{listing}
  193. %\newcommand{\xcs}{\extracolsep{\fill}}
  194. % \end{listing}
  195. % and then expect something like `...@{\\xcs}...' to actually work --
  196. % the "\\extracolsep" mustn't be hidden inside any other
  197. % commands. Because things like `@' expressions aren't expanded at
  198. % the time, "\\extracolsep" has to be searched and processed
  199. % \`by hand'.\footnote{^^A
  200. % All \cs{extracolsep} does is modify the \cs{tabskip} glue, so
  201. % if you were an evil \TeX\ hacker like me, you could just say
  202. % \unhbox0\ and put \unhbox2\ in your preamble. That'd work nicely.
  203. % It also works with the \package{array} package.}
  204. %
  205. % \item Control sequences (commands) in a table's preamble aren't expanded
  206. % before the preamble is read. In fact, commands in the preamble are
  207. % considered to be column types, and their names are entirely
  208. % independent of normal \LaTeX\ commands. No column types of this
  209. % nature have yet been defined\footnote{^^A
  210. % There used to be an internal \cs{@magic} type used by
  211. % \env{eqnarray}, but you're not supposed to know about that.
  212. % Besides, it's not there any more.}
  213. % but the possibility's always there. Use the "\\newcolumntype" or
  214. % "\\coldef" commands to define new column types.
  215. %
  216. % \item The preamble parsing works in a completely different way. There is
  217. % a certain amount of compatibility provided, although it's heavily
  218. % geared towards keeping \package{longtable} happy and probably won't
  219. % work with other packages.
  220. %
  221. % \item Obscure constructs which were allowed by the old preamble parser but
  222. % violate the syntax shown in the next section (e.g., `|@{}|' to
  223. % suppress the "\\doublerulesep" space between two vertical rules,
  224. % described in \textit{The \LaTeX\ Companion} as \`a misuse of the
  225. % `@{...}' qualifier') are now properly outlawed. You will be given
  226. % an error message if you attempt to use such a construction.
  227. %
  228. % \item The `*' forms (which repeat column types) are now expanded at a
  229. % different time. Previously, preambles like `c@*{4}{{:}@}{--}c'
  230. % were considered valid (the example would expand to
  231. % `c@{:}@{:}@{:}@{:}@{--}c'), because `*'s were expanded before the
  232. % preamble was actually parsed. In the new system, `*' is treated
  233. % just like any other preamble character (it just has a rather odd
  234. % action), and preambles like this will result in an error (and
  235. % probably a rather confusing one).
  236. %
  237. % \end{itemize}
  238. %
  239. % There are also several incompatibilities between \package{mdwtab} and
  240. % \package{array}:
  241. %
  242. % \begin{itemize} \synshorts \let\`=\lq
  243. %
  244. % \item Because of the way "\\newcolumntype" works in the \package{array}
  245. % package, a horrid construction like
  246. % \begin{listing}
  247. %\newcolumntype{x}{{:}}
  248. %\begin{tabular}{|c!xc|}
  249. % \end{listing}
  250. % is considered to be valid, and is interpreted as `|c!{:}c|'. My
  251. % reading of pages~54 and~55 of the \textit{\LaTeX\ book} tells me
  252. % that this sort of thing is forbidden in normal \LaTeX\ commands.
  253. % The \package{mdwtab} preamble parser now treats column type letters
  254. % much more like commands with the result that the hacking above won't
  255. % work any more. The construction above would actually be interpreted
  256. % as `|c!{x}c|' (i.e., the `x' column type wouldn't be expanded to
  257. % `{:}' because the parser noticed that it was the argument to the
  258. % `!' modifier\footnote{^^A
  259. % This is a direct result of the way \TeX\ treats undelimited
  260. % arguments. See chapters~5 and~20 of \textit{The \TeX book} for
  261. % more information about how grouping affects argument reading.}).
  262. %
  263. % \item Most of the points above, particularly those relating to the
  264. % handling of the preamble, also apply to the \package{array} package.
  265. % it's not such an advance over the \LaTeXe\ version as everyone said
  266. % it was.
  267. %
  268. % \end{itemize}
  269. %
  270. %
  271. % \subsection{Syntax}
  272. %
  273. % \DescribeEnv{tabular}
  274. % \DescribeEnv{tabular*}
  275. % \DescribeEnv{array}
  276. % So that everyone knows where I stand, here's a complete syntax for my
  277. % version of the \env{tabular} environment, and friends
  278. %
  279. % \begin{grammar}
  280. %
  281. % <tabular-env> ::= \[[
  282. % "\\begin"
  283. % \begin{stack}
  284. % "{tabular}" \\ "{tabular*}" "{" <length> "}" \\
  285. % "{array}" \\ "{smarray}"
  286. % \end{stack}
  287. % \[ "[" <position-arg> "]" \]
  288. % "{" <preamble> "}" <text>
  289. % "\\end"
  290. % \( "{tabular}" \\ "{tabular*}" \\ "{array}" \\ "{smarray}" \)
  291. % \]]
  292. %
  293. % <position-arg> ::= (see below)
  294. %
  295. % <preamble> ::= \[[
  296. % <first-column>
  297. % \[ \< <column> \> \]
  298. % \]]
  299. %
  300. % <first-column> ::= \[[ \[ <rule> \] <column> \]]
  301. %
  302. % <column> ::= \[[
  303. % \[ <spacing> \] \[ \< <user-pre-text> \> \] <column-type>
  304. % \[ \< <user-post-text> \> \] \[ <spacing> \] \[ <rule> \]
  305. % \]]
  306. %
  307. % <spacing> ::= \[[ "@" "{" <text> "}" \]]
  308. %
  309. % <user-pre-text> ::= \[[ ">" "{" <text> "}" \]]
  310. %
  311. % <column-type> ::= \[[
  312. % \begin{stack}
  313. % \[ "T" \\ "M" \] \( "l" \\ "c" \\ "r" \) \\
  314. % \( "p" \\ "m" \\ "b" \) "{" <length> "}" \\
  315. % "#" "{" <raw-pre-text> "}" "{" <raw-post-text> "}"
  316. % \end{stack}
  317. % \]]
  318. %
  319. % <user-post-text> ::= \[[ "<" "{" <text> "}" \]]
  320. %
  321. % <rule> ::= \[[ \( "|" \\ "!" "{" <text> "}" \) \]]
  322. %
  323. % \end{grammar}
  324. %
  325. % If you examine the above very carefully, you'll notice a slight deviation
  326. % from the original -- an |@|-expression \emph{following} a rule is
  327. % considered to be part of the \emph{next} column, not the current one. This
  328. % is, I think, an almost insignificant change, and essential for some of the
  329. % new features. You'll also notice the new |#| column type form, which
  330. % allows you to define new real column types instead of just modifying
  331. % existing ones. It's not intended for direct use in preambles -- it's
  332. % there mainly for the benefit of people who know what they're doing and
  333. % insist on using |\newcolumntype| anyway.
  334. %%
  335. % The actual column types are shown in table~\ref{tbl:columns}.
  336. %
  337. % \begin{table}
  338. % \begin{tabular}[C]{| >{\synshorts} c | m{3in} |} \hlx{hv[1]}
  339. %
  340. % \multicolumn{2}{|c|}{\bf Column types} \\ \hlx{v[1]hv}
  341. % \bf Name & \bf Meaning \\ \hlx{vhv.}
  342. % "l" & Left aligned text (\env{tabular}) or
  343. % equation (\env{array}). \\ \hlx{.}
  344. % "c" & Centred text (\env{tabular}) or
  345. % equation (\env{array}). \\ \hlx{.}
  346. % "r" & Right aligned text (\env{tabular}) or
  347. % equation (\env{array}). \\ \hlx{vhv.}
  348. % "Ml", "Mc" and "Mr" & Left, centre and right aligned
  349. % equations.* \\ \hlx{.}
  350. % "Tl", "Tc" and "Tr" & Left, centre and right aligned
  351. % text.* \\ \hlx{vhv.}
  352. % "p{"<width>"}" & Top aligned paragraph with the given
  353. % width. \\ \hlx{.}
  354. % "m{"<width>"}" & Vertically centred paragraph with
  355. % the given width. \\ \hlx{.}
  356. % "b{"<width>"}" & Bottom aligned paragraph with the
  357. % given width. \\ \hlx{vhv.}
  358. % "#{"<pre>"}{"<post>"}" & User defined column type:
  359. % \<pre> is inserted before the
  360. % cell entry, \<post> is inserted
  361. % afterwards.* \\ \hlx{vhhv[1]}
  362. %
  363. % \multicolumn{2}{|c|}{\bf Other modifier characters} \\ \hlx{v[1]hv}
  364. % \bf Name & \bf Meaning \\ \hlx{vhv.}
  365. % "|" & Inserts a vertical rule between
  366. % columns. \\ \hlx{.}
  367. % "!{"<text>"}" & Inserts \<text> between columns,
  368. % treating it as a vertical rule. \\ \hlx{vhv.}
  369. % "@{"<text>"}" & Inserts \<text> instead of the
  370. % usual intercolumn space. \\ \hlx{vhv.}
  371. % ">{"<text>"}" & Inserts \<text> just before the
  372. % actual column entry. \\ \hlx{.}
  373. % "<{"<text>"}" & Inserts \<text> just after the
  374. % actual column entry. \\ \hlx{vhv.}
  375. % "*{"<count>"}{"<chars>"}" & Inserts \<count>
  376. % copies of the \<chars> into the
  377. % preamble. \\ \hlx{vhs}
  378. %
  379. % \multicolumn{2}{@{}l}{* This column type is a new feature}
  380. % \end{tabular}
  381. %
  382. % \caption{\package{array} and \package{tabular} column types and modifiers}
  383. % \label{tbl:columns}
  384. % \end{table}
  385. %
  386. % Now that's sorted everything out, there shouldn't be any arguments at all
  387. % about what a column means.
  388. %
  389. % The lowercase \<position-arg>s \lit{t}, \lit{c} and \lit{b} do exactly
  390. % what they did before: control the vertical positioning of the table. The
  391. % uppercase ones control the \emph{horizontal} positioning -- this is how you
  392. % create \emph{unboxed} tables. You can only create unboxed tables in
  393. % paragraph mode.
  394. %
  395. % Note that unboxed tables still can't be broken across pages. Use
  396. % the \package{longtable} package for this, because it already does an
  397. % excellent job.
  398. %
  399. % \DescribeMacro{\tabpause}
  400. % One thing you can to with unboxed tables, however, is to `interrupt' them,
  401. % do some normal typesetting, and then continue. This is achieved by the
  402. % |\tabpause| command: its argument is written out in paragraph mode, and
  403. % the table is continued after the argument finishes.
  404. % Note that it isn't a real argument as far as commands like |\verb| are
  405. % concerned -- they'll work inside |\tabpause| without any problems.
  406. %
  407. % \DescribeMacro{\vline}
  408. % The |\vline| command draws a vertical rule the height of the current table
  409. % cell (unless the current cell is being typeset in paragraph mode -- it
  410. % only works in the simple LR-mode table cells, or in \lit{@} or \lit{!}
  411. % modifiers). It's now been given an optional argument which gives the
  412. % width of the rule to draw:
  413. %
  414. % { \let\tabstyle=\relax
  415. % \begin{demo}{An example of \cmd\vline}
  416. %\large
  417. %\begin{tabular}
  418. % {| c !{\vline[2pt]} c | c |}
  419. % \hlx{hv}
  420. % \bf A & \it B & \sf C \\
  421. % \hlx{vhv}
  422. % \bf D & \it E & \sf F \\
  423. % \hlx{vh}
  424. %\end{tabular}
  425. % \end{demo}
  426. % }
  427. %
  428. % \DescribeMacro{smarray}
  429. % You've probably noticed that there's an unfamiliar environment mentioned
  430. % in the syntax shown above. The \env{smarray} environment produces a
  431. % `small' array, with script size cells rather than the normal full text
  432. % size cells. I've seen examples of this sort of construction\footnote{^^A
  433. % There's a nasty use of \env{smallmatrix} in the |testmath.tex| file which
  434. % comes with the \package{amslatex} distribution. It's actually there to
  435. % simulate a `smallcases' environment, which the \package{mathenv} package
  436. % includes, based around \env{smarray}.}
  437. % being implemented by totally unsuitable commands. Someone may find it
  438. % handy.
  439. %
  440. %
  441. % \subsection{An updated \cs{cline} command}
  442. %
  443. % \DescribeMacro{\cline}
  444. % The standard \LaTeX\ |\cline| command has been updated. As well as just
  445. % passing a range of columns to draw lines through, you can now pass a comma
  446. % separated list of column numbers and ranges:
  447. %
  448. % \begin{grammar}
  449. % <cline-cmd> ::= \[[
  450. % "\\cline" "{" \< <number> \[ "-" <number> \] \\ "," \> "}"
  451. % \]]
  452. % \end{grammar}
  453. %
  454. % The positioning of the horizontal lines has also been improved a bit, so
  455. % that they meet up with the vertical lines properly. Displays like the one
  456. % in the example below don't look good unless this has been done properly.
  457. %
  458. % {\let\tabstyle\relax
  459. % \begin{demo}[w]{A \cs{cline} example}
  460. %\newcommand{\mc}{\multicolumn{1}}
  461. %\begin{tabular}[C]{|c|c|c|c|} \cline{2,4}
  462. % \mc{c|}{one} & two & three & four \\ \hline
  463. % five & six & seven & \mc{c}{eight} \\ \cline{1,3}
  464. %\end{tabular}
  465. % \end{demo}
  466. % }
  467. %
  468. % \subsection{Spacing control}
  469. %
  470. % One of the most irritating things about \LaTeX's tables is that there isn't
  471. % enough space around horizontal rules. Donald Knuth, in \textit{The
  472. % \TeX book}, describes addition of some extra vertical space here as `a mark
  473. % of quality', and since \TeX\ was designed to produce `beautiful documents'
  474. % it seems a shame that \LaTeX\ doesn't allow this to be done nicely. Well,
  475. % it does now.
  476. %
  477. % \DescribeMacro{\vgap}
  478. % The extra vertical space is added using a command |\vgap|, with the
  479. % following syntax:
  480. %
  481. % \begin{grammar}
  482. %
  483. % <vgap-cmd> ::= \[[
  484. % "\\vgap" \[ "[" <which-cols> "]" \] "{" <length> "}"
  485. % \]]
  486. %
  487. % <which-cols> ::= \[[ \< <number> \[ "-" <number> \] \\ "," \> \]]
  488. %
  489. % \end{grammar}
  490. %
  491. % This command must appear either immediately after the beginning of the
  492. % table or immediately after the |\\| which ends a row. (Actually, there are
  493. % other commands which also have this requirement -- you can specify a
  494. % collection of them wherever you're allowed to give any one.) It adds some
  495. % vertical space (the amount is given by the \<length>) to the table,
  496. % making sure that the vertical rules of the table are extended correctly.
  497. %
  498. % The |\vgap| command relies on information stored while your table preamble
  499. % is being examined. However, it's possible that you might not want some
  500. % of the rules drawn (e.g., if you've used |\multicolumn|). The optional
  501. % \<which-cols> argument allows you to specify which rules are \emph{not}
  502. % to be drawn. You can specify either single column numbers or ranges. The
  503. % rule at the very left hand side is given the number~0; the rules at the
  504. % end of column~$n$ are numbered~$n$. It's easy really.
  505. %
  506. % \DescribeMacro{\hlx}
  507. % Using |\vgap| is all very well, but it's a bit cumbersome, and takes up a
  508. % lot of typing, especially when combined with |\hline| commands. The |\hlx|
  509. % command tries to tidy things.
  510. %
  511. % The syntax is simple:
  512. % \begin{grammar}
  513. %
  514. % <hlx-cmd> ::= \[[
  515. % "\\hlx" "{"
  516. % \begin{rep}
  517. % \begin{stack}
  518. % "h" \\
  519. % \tok{"v["<which-cols>"]["<length>"]"} \\
  520. % \tok{"s["<length>"]"} \\
  521. % \tok{"c{"<which-cols>"}"} \\
  522. % "b" \\
  523. % \tok{"/["<number>"]"} \\
  524. % "."
  525. % \end{stack}
  526. % \end{rep}
  527. % "}"
  528. % \]]
  529. %
  530. % \end{grammar}
  531. % The argument works a bit like a table preamble, really. Each letter is a
  532. % command. The following are supported:
  533. %
  534. % \begin{description}
  535. %
  536. % \item [\lit*{h}] Works just like |\hline|. If you put two adjacent to each
  537. % other, a gap will be put between them.
  538. %
  539. % \item [\lit*{v[}\<which-cols>\lit*{][}\<length>\lit*{]}] Works
  540. % like \syntax{"\\vgap["<which-cols>"]{"<length>"}"}. If the
  541. % \<length> is omitted, the value of |\doublerulesep| is used.
  542. % This usually looks right.
  543. %
  544. % \item [\lit*{s[}\<length>\lit*{]}] Leaves a vertical gap with the
  545. % given size. If you omit the \<length> then |\doublerulesep| is
  546. % used. This is usually right.
  547. %
  548. % \item [\lit*{c\char`\{}\<which-cols>\lit*{\char`\}}] Works just like
  549. % |\cline|.
  550. %
  551. % \item [\lit*{b}] Inserts a backspace the width of a rule. This is useful
  552. % when doing \package{longtable}s.
  553. %
  554. % \item [\lit*{/[}\<number>\lit*{]}] Allows a page break in a table. Don't
  555. % use this except in a \env{longtable} environment. The \<number>
  556. % works exactly the same as it does in the |\pagebreak| command,
  557. % except that the default is 0, which just permits a break without
  558. % forcing it.
  559. %
  560. % \item [\lit*{.}] (That's a dot) Starts the next row of the table. No
  561. % more characters may follow the dot, and no |\hline|, |\hlx|, |\vgap|
  562. % or |\multicolumn| commands may be used after it. You don't have to
  563. % include it, and most of the time it's totally useless. It can be
  564. % handy for some macros, though. I used it in (and in fact added it
  565. % especially for) the table of column types.
  566. %
  567. % \end{description}
  568. %
  569. % An example of the use of |\hlx| is given, so you can see what's going on.
  570. %
  571. % \begin{figure}
  572. % \let\tabstyle\relax
  573. % \begin{demo}[w]{Beautiful table example}
  574. %\newcommand{\zerowidth}[1]{\hbox to 0pt{\hss#1\hss}}
  575. %\setlength{\tabcolsep}{1.5em}
  576. %\begin{tabular}[C]{| r | c | r |} \hlx{hv[1,2]}
  577. % \multicolumn{3}{|c|}{\bf AT\&T Common Stock} \\ \hlx{v[1,2]hv}
  578. % \multicolumn{1}{|c|}{\zerowidth{\bf Year}} &
  579. % \multicolumn{1}{c|}{\zerowidth{\bf Price}} &
  580. % \multicolumn{1}{c|}{\zerowidth{\bf Dividend}} \\ \hlx{vhv}
  581. % 1971 & 41--54 & \$2.60 \\
  582. % 2 & 41--54 & 2.70 \\
  583. % 3 & 46--55 & 2.87 \\
  584. % 4 & 40--53 & 3.24 \\
  585. % 5 & 45--52 & 3.40 \\
  586. % 6 & 51--59 & .95\rlap{*} \\ \hlx{vhs}
  587. % \multicolumn{3}{@{}l}{* (first quarter only)}
  588. %\end{tabular}
  589. % \end{demo}
  590. % \end{figure}
  591. %
  592. %
  593. % \subsection{Creating beautiful long tables}
  594. %
  595. % You can use the |\vgap| and |\hlx| commands with David Carlisle's
  596. % stunning \package{longtable} package. However, there are some things you
  597. % should be away of to ensure that your tables always come out looking
  598. % lovely.
  599. %
  600. % The \package{longtable} package will break a table at an |\hline| command,
  601. % leaving a rule at the bottom of the page and another at the top of the
  602. % next page. This means that a constructions like |\hlx{vhv}| will be
  603. % broken into something like |\hlx{vh}| at the bottom of the page and
  604. % |\hlx{hv}| at the top of the next. You need to design the table headers
  605. % and footers with this in mind.
  606. %
  607. % However, there appears to be a slight problem:\footnote
  608. % {You might very well call it a bug. I couldn't possibly comment.}
  609. % if the footer starts with an |\hline|, and a page is broken at an |\hline|,
  610. % then you get an extra thick rule at the bottom of the page. This is a bit
  611. % of a problem, because if the rule isn't there in the footer and you get
  612. % a break between two rows \emph{without} a rule between them, then the page
  613. % looks very odd.
  614. %
  615. % If you want to do ruled longtables, I'd recommend that you proceed as
  616. % follows:
  617. % \begin{itemize}
  618. % \item End header sections with an |\hlx{vh}|.
  619. % \item Begin footer sections with an |\hlx{bh}|.
  620. % \item Begin the main table with |\hlx{v}|.
  621. % \item Insert |\hlx{vhv}| commands in the main table body as usual.
  622. % \end{itemize}
  623. % If \package{longtable} gets modified appropriately, the use of the \lit{b}
  624. % command won't be necessary.
  625. %
  626. % Here's an example of the sort of thing you'd type.
  627. %
  628. % \begin{listinglist} \listingsize
  629. % \verb"\begin{longtable}[c]{|c|l|} \hlx{hv}" \\
  630. % \verb"\bf Heading & \bf Also heading \\ \hlx{vh}" \\
  631. % \verb"\endhead" \\
  632. % \verb"\hlx{bh}" \\
  633. % \verb"\endfoot" \\
  634. % \verb"\hlx{v}" \\
  635. % \verb"First main & table line \\ \hlx{vhv}" \\
  636. % \verb"Lots of text & like this \\ \hlx{vhv}" \\
  637. % \null\quad\vdots \\
  638. % \verb"Lots of text & like this \\ \hlx{vhv}" \\
  639. % \verb"Last main & table line \\ \hlx{vh}" \\
  640. % \verb"\end{longtable}"
  641. % \end{listinglist}
  642. %
  643. %
  644. % \subsection{Rules and vertical positioning}
  645. %
  646. % In the \LaTeXe\ and \package{array.sty} versions of \env{tabular}, you run
  647. % into problems if you try to use ruled tables together with the \lit{[t]} or
  648. % \lit{[b]} position specifiers -- the top or bottom rule ends up being
  649. % nicely lined up with the text baseline, giving you an effect which is
  650. % nothing like the one you expected. The \textit{\LaTeX\ Companion} gives
  651. % two commands |\firsthline| and |\lasthline| which are supposed to help with
  652. % this problem. (These commands have since migrated into the \package{array}
  653. % package.) Unfortunately, |\firsthline| doesn't do its job properly --
  654. % it gets the text position wrong by exactly the width of the table rules.
  655. %
  656. % The \package{mdwtab} package makes all of this automatic. It gets the
  657. % baseline positions exactly right, whether or not you use rules. Earlier
  658. % versions of this package required that you play with a length parameter
  659. % called |\rulefudge|; this is no longer necessary (or even possible -- the
  660. % length parameter no longer exists). The package now correctly compensates
  661. % for all sorts of rules and |\vgap|s at the top and bottom of a table and
  662. % it gets the positioning right all by itself. You've never had it so good.
  663. %
  664. %
  665. % \subsection{User serviceable parts}
  666. %
  667. % There are a lot of parameters which you can modify in order to make arrays
  668. % and tables look nicer. They are all listed in table~\ref{tbl:config}.
  669. %
  670. % \begin{table}
  671. % \begin{tabular}[C]{| l | m{3in} |} \hlx{hv}
  672. % \bf Parameter & \bf Meaning \\ \hlx{vhv}
  673. % |\tabstyle| & A command executed at the beginning of
  674. % a \env{tabular} or \env{tabular$*$}
  675. % environment. By default does nothing.
  676. % Change using |\renewcommand|. \\ \hlx{vhv}
  677. % |\extrarowheight| & A length added to the height of every
  678. % row, used to stop table rules
  679. % overprinting ascenders. Default 0\,pt.
  680. % Usage is deprecated now: use |\hlx|
  681. % instead. \\ \hlx{vhv}
  682. % |\tabextrasep| & Extra space added between rows in a
  683. % \env{tabular} or \env{tabular$*$}
  684. % environment (added \emph{before} any
  685. % following |\hline|). Default 0\,pt. \\
  686. % |\arrayextrasep| & Analogous to |\tabextrasep|, but for
  687. % \env{array} environments. Default
  688. % 1\,jot (3\,pt). \\
  689. % |\smarrayextrasep| & Analogous to |\tabextrasep|, but for
  690. % \env{smarray} environments. Default
  691. % 1\,pt. \\ \hlx{vhv}
  692. % |\tabcolsep| & Space added by default on each side of
  693. % a table cell (unless suppressed by an
  694. % \lit{@}-expression) in \env{tabular}
  695. % environments. Default is defined by
  696. % your document class. \\
  697. % |\arraycolsep| & Analogous to |\tabcolsep|, but for
  698. % \env{array} environments. Default is
  699. % defined by your document class. \\
  700. % |\smarraycolsep| & Analogous to |\tabcolsep|, but for
  701. % \env{smarray} environments. Default
  702. % is 3\,pt. \\ \hlx{vhv}
  703. % |\arrayrulewidth| & The width of horizontal and vertical
  704. % rules in tables. \\
  705. % |\doublerulesep| & Space added between two adjacent
  706. % vertical or horizontal rules. Also
  707. % used by |\hlx{v}|. \\ \hlx{vhv}
  708. % |\arraystretch| & Command containing a factor to
  709. % multiply the default row height.
  710. % Default is defined by your document
  711. % class (usually 1). \\ \hlx{vh}
  712. % \end{tabular}
  713. %
  714. % \caption{Parameters for configuring table environments}
  715. % \label{tbl:config}
  716. %
  717. % \end{table}
  718. %
  719. %
  720. % \subsection{Defining column types}
  721. %
  722. % \DescribeMacro{\newcolumntype}
  723. % The easy way to define new column types is using |\newcolumntype|. It
  724. % works in more or less the same way as |\newcommand|:
  725. %
  726. % \begin{grammar}
  727. %
  728. % <new-col-type-cmd> ::= \[[
  729. % "\\newcolumntype"
  730. % "{" <column-name> "}"
  731. % \[ "[" <num-args> "]" \]
  732. % \[ "[" <default-arg> "]" \]
  733. % "{" <first-column> \[ \< <column> \> \] "}"
  734. % \]]
  735. %
  736. % \end{grammar}
  737. %
  738. % (The \env{array.sty} implementation doesn't accept the \<default-arg>
  739. % argument. I've no idea why not, 'cos it was very easy to implement.)
  740. %
  741. % \DescribeMacro{\colset}
  742. % This implementation allows you to define lots of different sets of columns.
  743. % You can change the current set using the |\colset| declaration:
  744. % \begin{grammar}
  745. % <colset-cmd> ::= \[[ "\\colset" "{" <set-name> "}" \]]
  746. % \end{grammar}
  747. % This leaves a problem, though: at any particular moment, the current
  748. % column set could be anything, since other macros and packages can change
  749. % it.
  750. %
  751. % \DescribeMacro{\colpush}
  752. % \DescribeMacro{\colpop}
  753. % What actually happens is that a stack of column sets is maintained. The
  754. % |\colset| command just replaces the item at the top of the stack. The
  755. % command |\colpush| pushes its argument onto the top of the stack, making
  756. % it the new current set. The corresponding |\colpop| macro (which doesn't
  757. % take any arguments) removes the top item from the stack, reinstating the
  758. % previous current column set.
  759. %
  760. % \begin{grammar}
  761. % <colpush-cmd> ::= \[[ "\\colpush" "{" <set-name> "}" \]]
  762. % <colpop-cmd> ::= \[[ "\\colpop" \]]
  763. % \end{grammar}
  764. %
  765. % The macros which manipulate the column set stack work \emph{locally}.
  766. % The contents of the stack are saved when you open a new group.
  767. %
  768. % To make sure everyone behaves themselves properly, these are the rules for
  769. % using the column set stack:
  770. %
  771. % \begin{itemize}
  772. %
  773. % \item Packages defining column types must ensure that they preserve the
  774. % current column set. Either they must push their own column type
  775. % and pop it off when they're finished defining columns, or they must
  776. % avoid changing the stack at all, and use the optional arguments to
  777. % |\coldef| and |\collet|.
  778. %
  779. % \item Packages must not assume that any particular column set is current
  780. % unless they have made sure of it themselves.
  781. %
  782. % \item Packages must ensure that they pop exactly as much as they push.
  783. % There isn't much policing of this (perhaps there should be more),
  784. % so authors are encouraged to behave responsibly.
  785. %
  786. % \item Packages must change the current column set (using |\colset|) when
  787. % they start up their table environment. This will be restored when
  788. % the environment closes.
  789. %
  790. % \end{itemize}
  791. %
  792. % \DescribeMacro{\coldef}
  793. % |\newcolumntype| is probably enough for most purposes. However, Real
  794. % \TeX nicians, and people writing new table-generating environments, require
  795. % something lower-level.
  796. %
  797. % \begin{grammar}
  798. % <coldef-cmd> ::= \[[
  799. % "\\coldef"
  800. % \[ "[" <set-name> "]" \]
  801. % <col-name> <arg-template> "{" <replacement-text> "}"
  802. % \]]
  803. % \end{grammar}
  804. %
  805. % Note that this defines a column type in the current colset. It works
  806. % almost exactly the same way as \TeX's primitive |\def|. There is a
  807. % potential gotcha here: a |\tab@mkpream| token is inserted at the end of
  808. % your replacement text. If you need to read an optional argument or
  809. % something, you'll need to gobble this token before you carry on. The
  810. % |\@firstoftwo| macro could be handy here:
  811. % \begin{listing}
  812. %\coldef x{\@firstoftwo{\@ifnextchar[\@xcolumn@i\@xcolumn@ii}}}
  813. % \end{listing}
  814. % This isn't a terribly pretty state of affairs, and I ought to do something
  815. % about it. I've not seen any use for an optional argument yet, though.
  816. % Note that if you do gobble the |\tab@mkpream|, it's your responsibility to
  817. % insert another one at the very end of your macro's expansion (so that
  818. % further preamble characters can be read).
  819. %
  820. % The replacement text is inserted directly. It's normal to insert preamble
  821. % elements here. There are several to choose from:
  822. %
  823. % \begin{description}
  824. %
  825. % \item [Column items] provide the main `meat' of a column. You insert a
  826. % column element by saying
  827. % \syntax{"\\tabcoltype{"<pre-text>"}{"<post-text>"}"}.
  828. % The user's text gets inserted between these two. (So do user pre-
  829. % and post-texts. Bear this in mind.)
  830. %
  831. % \item [User pre-text items] work like the \lit{>} preamble command. You
  832. % use the \syntax{"\\tabuserpretype{"<text>"}"} command to insert it.
  833. % User pre-texts are written in \emph{reverse} order between the
  834. % pre-text of the column item and the text from the table cell.
  835. %
  836. % \item [User post-text items] work like the \lit{<} preamble command. You
  837. % use the \syntax{"\\tabuserposttype{"<text>"}"} command to insert it.
  838. % Like user pre-texts, user post-texts are written in reverse order,
  839. % between the table cell text and the column item post-text.
  840. %
  841. % \item [Space items] work like the \lit{@} preamble command. They're
  842. % inserted with the \syntax{"\\tabspctype{"<text>"}"} command.
  843. %
  844. % \item [Rule items] work like the `\verb"|"' and \lit{!} commands. You
  845. % insert them with the \syntax{"\\tabruletype{"<text>"}"} command.
  846. % Note that the text is inserted by |\vgap| too, so it should contain
  847. % things which adjust their vertical size nicely. If you really need
  848. % to, you can test |\iftab@vgap| to see if you're in a |\vgap|.
  849. %
  850. % \end{description}
  851. %
  852. % \DescribeMacro{\collet}
  853. % As well as defining columns, you can copy definitions (rather like |\let|
  854. % allows you to copy macros). The syntax is like this:
  855. %
  856. % \begin{grammar}
  857. %
  858. % <collet-cmd> ::= \[[
  859. % \[ "[" <set-name> "]" \] <col-name> \[ "=" \] \[ "[" <set-name> "]" \]
  860. % <col-name>
  861. % \]]
  862. %
  863. % \end{grammar}
  864. %
  865. % (In other words, you can copy defintions from other column sets.)
  866. %
  867. %
  868. % \subsection{Defining new table-generating environments}
  869. %
  870. % Quite a few routines are provided specifically to help you to define new
  871. % environments which do alignment in a nice way.
  872. %
  873. % \subsubsection{Reading preambles}
  874. %
  875. % The main tricky bit in doing table-like environments is parsing preambles.
  876. % No longer.
  877. %
  878. % \DescribeMacro{\tab@readpreamble}
  879. % \DescribeMacro{\tab@doreadpream}
  880. % The main parser routine is called |\tab@doreadpream|. Given a user
  881. % preamble string as an argument, it will build an |\halign| preamble to
  882. % return to you. However, the preamble produced won't be complete. This is
  883. % because you can actually make multiple calls to |\tab@doreadpream| with
  884. % bits of user preambles. The |\newcolumntype| system uses this mechanism,
  885. % as does the \lit{*} (repeating) modifier. When there really is no more
  886. % preamble to read, you need to \emph{commit} the heldover tokens to the
  887. % output. The |\tab@readpreamble| routine will do this for you -- given a
  888. % user preamble, it builds a complete output from it.
  889. %
  890. % A token register |\tab@preamble| is used to store the generated preamble.
  891. % Before starting, you must iniitialise this token list to whatever you want.
  892. % There's another token register, |\tab@shortline|, which is used to store
  893. % tokens used by |\vgap|. For each column in the table, the list contains
  894. % an |\omit| (to override the standard preamble) and an |\hfil| space taking
  895. % up most of the column. Finally, for each rule item in the user preamble,
  896. % the shortline list contains an entry of the form:
  897. % \begin{quote} \synshorts
  898. % "\\tab@ckr{"<column-number>"}{"<rule-text>"}"
  899. % \end{quote}
  900. % This is used to decide whether to print the rule or an empty thing of the
  901. % same width. You probably ought to know that the very first column does
  902. % \emph{not} have a leading |\omit| -- this is supplied by |\vgap| so that
  903. % it can then look for optional arguments.
  904. %
  905. % \DescribeMacro{\tab@initread}
  906. % As well as initialising |\tab@preamble| and emptying |\tab@shortline|,
  907. % there are several other operations required to initialise a preamble read.
  908. % These are all performed by the |\tab@initread| macro, although you may want
  909. % to change some of the values for your specific application. For reference,
  910. % the actions performed are:
  911. % \begin{itemize}
  912. % \item initialising the parser state by setting $|\tab@state| =
  913. % |\tab@startstate|$;
  914. % \item clearing the token lists |\tab@preamble| and |\tab@shortlist|;
  915. % \item initialising the macros |\tab@tabtext|, |\tab@midtext|, and
  916. % |\tab@multicol| to their default values of `|&|',
  917. % `|\ignorespaces#\unskip|' and the empty token list respectively.^^A
  918. % \footnote{^^A
  919. % These are macros rather than token lists to avoid hogging all
  920. % the token list registers. Actually, the package only allocates
  921. % two, although it does use almost all of the temporary registers as
  922. % well. Also, there's a lie: \cs{unskip} is too hamfisted to remove
  923. % trailing spaces properly; I really use a macro called
  924. % \cs{@maybe@unskip}}
  925. % \item clearing the internal token list registers |\tab@pretext|,
  926. % |tab@userpretext| and |\tab@posttext|;
  927. % \item clearing the column counter |\tab@columns| to zero;
  928. % \item clearing the action performed when a new column is started (by making
  929. % the |\tab@looped| macro equal to |\relax|; this is used to make
  930. % |\multicolumn| macro raise an error if you try to do more than one
  931. % column); and
  932. % \item setting up some other switches used by the parser (|\iftab@rule|,
  933. % |\iftab@initrule| and |\iftab@firstcol|, all of which are set to be
  934. % |true|).
  935. % \end{itemize}
  936. %
  937. % The macro |\tab@multicol| is used by the |\multicolumn| command to insert
  938. % any necessary items (e.g., struts) before the actual column text. If you
  939. % set this to something non-empty, you should probably consider adding a
  940. % call to the macro to the beginning of |\tab@preamble|.
  941. %
  942. % When parsing is finally done, the count register |\tab@columns| contains
  943. % the number of columns in the alignment. Don't corrupt this value, because
  944. % it's used for handling |\hline| commands.
  945. %
  946. % \subsubsection{Starting new lines}
  947. %
  948. % The other messy bit required by table environments is the newline command
  949. % |\\|. There are nasty complications involved with starting new lines, some
  950. % of which can be handled by this package, and some on which I can only give
  951. % advice.
  952. %
  953. % \DescribeMacro{\tab@cr}
  954. % The optional arguments and star-forms etc. can be read fairly painlessly
  955. % using the |\tab@cr| command:
  956. %
  957. % \begin{grammar}
  958. % <tabcr-cmd> ::= \[[
  959. % "\\tab@cr" <command> "{" <non-star-text> "}" "{" <star-text> "}"
  960. % \]]
  961. % \end{grammar}
  962. %
  963. % This will call your \<command> with two arguments. The first is the
  964. % contents of the optional argument, or `|\z@|' if there wasn't one. The
  965. % second is either \<star-text> or \<non-star-text> depending on
  966. % whether the user wrote the $*$-form or not.
  967. %
  968. % Somewhere in your \<command>, you'll have to use the |\cr| primitive to
  969. % end the table row. After you've done this, you \emph{must} ensure that you
  970. % don't do anything that gets past \TeX's mouth without protecting it --
  971. % otherwise |\hline| and co.\ won't work. I usually wrap things up in a
  972. % |\noalign| to protect them, although there are other methods. Maybe.
  973. %
  974. % You might like to have a look at the \env{eqnarray} implementation provided
  975. % to see how all this gets put into practice.
  976. %
  977. %
  978. % \subsection{The \env{mathenv} package alignment environments}
  979. %
  980. % The \env{mathenv} package provides several environments for aligning
  981. % equations in various ways. They're mainly provided as a demonstration of
  982. % the table handling macros in \package{mdwtab}, so don't expect great
  983. % things. If you want truly beautiful mathematics, use
  984. % \package{amsmath}.\footnote{^^A
  985. % Particularly since nice commands like \cmd\over\ are being reactivated
  986. % in a later release of \package{amsmath}.}
  987. % However, the various environments do nest in an approximately useful way.
  988. % I also think that the \env{matrix} and \env{script} environments provided
  989. % here give better results than their \package{amsmath} equivalents, and
  990. % they are certainly more versatile.
  991. %
  992. % \subsubsection{The new \env{eqnarray} environment}
  993. %
  994. % \DescribeEnv{eqnarray}
  995. % \DescribeEnv{eqnarray*}
  996. % As an example of the new column defining features, and because the original
  997. % isn't terribly good, I've included a rewritten version of the
  998. % \env{eqnarray} environment. The new implementation closes the gap between
  999. % \env{eqnarray} and \AmSTeX\ alignment features. It's in a separate,
  1000. % package called \package{mathenv}, to avoid wasting your memory.
  1001. %
  1002. % \begin{grammar}
  1003. %
  1004. % <eqnarray-env> ::= \[[
  1005. % <begin-eqnarray> \< <row> \\ "\\\\" \> <end-eqnarray>
  1006. % \]]
  1007. %
  1008. % <begin-eqnarray> ::= \[[
  1009. % "\\begin" \( "{eqnarray}" \\ "{eqnarray*}" \)
  1010. % \[ "[" \< <eqa-column> \> "]" \]
  1011. % \]]
  1012. %
  1013. % <eqa-column> ::= \[[
  1014. % \[ "q" \\ ":" \]
  1015. % \[ \< ">" "{" <pre-text> "}" \> \]
  1016. % \begin{stack}
  1017. % \[ "T" \] \( "r" \\ "c" \\ "l" \) \\
  1018. % "L" \\
  1019. % "x"
  1020. % \end{stack}
  1021. % \[ \< "<" "{" <post-text> "}" \> \]
  1022. % \]]
  1023. %
  1024. % <end-eqnarray> ::= \[[
  1025. % "\\end" \begin{stack} "{eqnarray}" \\ "{eqnarray*}" \end{stack}
  1026. % \]]
  1027. %
  1028. % \end{grammar}
  1029. %
  1030. % Descriptions of the various column types are given in
  1031. % table~\ref{tbl:eqnarray}.
  1032. %
  1033. % \begin{table}
  1034. % \begin{tabular}[C]{| >{\synshorts} c | m{3in} |} \hlx{hv[1]}
  1035. %
  1036. % \multicolumn{2}{|c|}{\bf Column types} \\ \hlx{v[1]hv}
  1037. % \bf Name & \bf Meaning \\ \hlx{vhv.}
  1038. % "l" & Left aligned piece of equation. \\ \hlx{.}
  1039. % "c" & Centred piece of equation. \\ \hlx{.}
  1040. % "x" & Centred or flush-left whole equation
  1041. % (depending on \textsf{fleqn} option). \\ \hlx{.}
  1042. % "r" & Right aligned piece of equation. \\ \hlx{vhv.}
  1043. % "L" & Left aligned piece of equation whose
  1044. % width is considered to be 2\,em. \\ \hlx{vhv.}
  1045. % "Tl", "Tc" and "Tr" & Left, centre and right aligned
  1046. % text. \\ \hlx{vhhv[1]}
  1047. %
  1048. % \multicolumn{2}{|c|}{\bf Other modifier characters} \\ \hlx{v[1]hv}
  1049. % \bf Name & \bf Meaning \\ \hlx{vhv.}
  1050. % ":" & Leaves a big gap between equations.
  1051. % By default, the `chunks' separated by
  1052. % \lit{:}s are equally spaced on the
  1053. % line. \\ \hlx{.}
  1054. % "q" & Inserts 1\,em of space \\ \hlx{vhv.}
  1055. % ">{"<text>"}" & Inserts \<text> just before the
  1056. % actual column entry. \\ \hlx{.}
  1057. % "<{"<text>"}" & Inserts \<text> just after the
  1058. % actual column entry. \\ \hlx{vhv.}
  1059. % "*{"<count>"}{"<chars>"}" & Inserts \<count>
  1060. % copies of the \<chars> into the
  1061. % preamble. \\ \hlx{vh}
  1062. % \end{tabular}
  1063. %
  1064. % \caption{\package{eqnarray} column types and modifiers}
  1065. % \label{tbl:eqnarray}
  1066. % \end{table}
  1067. %
  1068. % The default preamble, if you don't supply one of your own, is \lit{rcl}.
  1069. % Most of the time, \lit{rl} is sufficient, although compatibility is more
  1070. % important to me.
  1071. %
  1072. % By default, there is no space between columns, which makes formul\ae\ in an
  1073. % \env{eqnarray} environment look just like formul\ae\ typeset on their own,
  1074. % except that things get aligned in columns. This is where the default
  1075. % \env{eqnarray} falls down: it leaves |\arraycolsep| space between each
  1076. % column making the thing look horrible.
  1077. %
  1078. % An example would be good here, I think. This one's from exercise 22.9 of
  1079. % the \textit{\TeX book}.
  1080. %
  1081. % \begin{demo}[w]{Simultaneous equations}
  1082. %\begin{eqnarray}[*3{rc}rl]
  1083. % 10w & + & 3x & + & 3y & + & 18z & = 1 \\
  1084. % 6w & - & 17x & & & - & 5z & = 2
  1085. %\end{eqnarray}
  1086. % \end{demo}
  1087. %
  1088. % Choosing a more up-to-date example, here's some examples from the
  1089. % \textit{\LaTeX\ Companion}.
  1090. %
  1091. % \begin{demo}[w]{Lots of equations}
  1092. %\begin{eqnarray}[rl:rl:lq]
  1093. % V_i &= v_i - q_i v_j, & X_i &= x_i - q_i x_j, &
  1094. % U_i = u_i, \qquad \mbox{for $i \ne j$} \\
  1095. % V_j &= v_j, & X_j &= x_j &
  1096. % U_j u_j + \sum_{i \ne j} q_i u_i. \label{eq:A}
  1097. %\end{eqnarray}
  1098. % \end{demo}
  1099. %
  1100. % \begin{figure}
  1101. % \begin{demo}[w]{Plain text column and \cs{tabpause}}
  1102. %\begin{eqnarray}[rlqqTl]
  1103. % x &= y & by (\ref{eq:A}) \\
  1104. % x' &= y' & by definition \\
  1105. %\tabpause{and}
  1106. % x + x' &= y + y' & by Axiom~1
  1107. %\end{eqnarray}
  1108. % \end{demo}
  1109. % \end{figure}
  1110. %
  1111. % The new features also mean that you don't need to mess about with
  1112. % |\lefteqn| any more. This is handled by the \lit{L} column type:
  1113. %
  1114. % \begin{demo}{Splitting example}
  1115. %\begin{eqnarray*}[Ll]
  1116. % w+x+y+z = \\
  1117. % & a+b+c+d+e+ \\
  1118. % & f+g+h+i+j
  1119. %\end{eqnarray*}
  1120. % \end{demo}
  1121. %
  1122. % Finally, just to prove that the spacing's right at last, here's another one
  1123. % from the \textit{Companion}.
  1124. %
  1125. % \begin{demo}{Spacing demonstration}
  1126. %\begin{equation}
  1127. % x^2 + y^2 = z^2
  1128. %\end{equation}
  1129. %\begin{eqnarray}[rl]
  1130. % x^2 + y^2 &= z^2 \\
  1131. % y^2 &< z^2
  1132. %\end{eqnarray}
  1133. % \end{demo}
  1134. %
  1135. % Well, that was easy enough. Now on to numbering. As you've noticed, the
  1136. % equations above are numbered. You can use the \env{eqnarray$*$}
  1137. % environment to turn off the numbering in the whole environment, or say
  1138. % |\nonumber| on a line to suppress numbering of that one in particular.
  1139. %
  1140. % \DescribeMacro{\eqnumber}
  1141. % More excitingly, you can say |\eqnumber| to enable numbering for a
  1142. % particular equation, or \syntax{"\\eqnumber["<text>"]"} to choose what to
  1143. % show instead of the line number. This works for both starred and unstarred
  1144. % versions of the environment. Now |\nonumber| becomes merely a synonym for
  1145. % `|\eqnumber[]|'.
  1146. %
  1147. % A note for cheats: you can use the sparkly new \env{eqnarray} for simple
  1148. % equations by specifying \lit{x} as the column description. Who needs
  1149. % \AmSTeX?\ |;-)|
  1150. %
  1151. % \DescribeEnv{eqlines}
  1152. % \DescribeEnv{eqlines*}
  1153. % In fact, there's a separate environment \env{eqlines}, which is equivalent
  1154. % to \env{eqnarray} with a single \lit{x} column; the result is that you can
  1155. % insert a collection of displayed equations separated by |\\| commands. If
  1156. % you don't like numbering, use \env{eqlines$*$} insead.
  1157. %
  1158. % \subsubsection{The \env{eqnalign} environment}
  1159. %
  1160. % \DescribeEnv{eqnalign}
  1161. % There's a new environment, \env{eqnalign}, which does almost the same
  1162. % thing as \env{eqnarray} but not quite. It doesn't do equation numbers,
  1163. % and it wraps its contents up in a box. The result of this is that:
  1164. %
  1165. % \begin{itemize}
  1166. %
  1167. % \item You can use \env{eqnalign} for just a part of a formula.
  1168. % The \env{eqnarray} environment must take up the whole display.
  1169. %
  1170. % \item You can use \env{eqnalign} within \env{eqnarray} for extra fine
  1171. % alignment of subsidiary bits.
  1172. %
  1173. % \item You can break off from doing an \env{eqnarray} using the |\tabpause|
  1174. % command. You can't use |\tabpause| inside
  1175. % \env{eqnalign}.\footnote{^^A
  1176. % Well, technically speaking there's nothing to stop you. However,
  1177. % the results won't be pretty.}
  1178. %
  1179. % \end{itemize}
  1180. %
  1181. % The \env{eqnalign} environment works like this:
  1182. %
  1183. % \begin{grammar}
  1184. %
  1185. % <eqnalign-env> ::= \[[
  1186. % <begin-eqnalign> <contents> <end-eqnalign>
  1187. % \]]
  1188. %
  1189. % <begin-eqnalign> ::= \[[
  1190. % "\\begin" "{eqnalign}"
  1191. % \[ "[" \< <eqa-column> \> "]" \]
  1192. % \[ "[" \( "t" \\ "c" \\ "b" \) "]" \]
  1193. % \]]
  1194. %
  1195. % <end-eqnalign> ::= \[[ "\\end" "{eqnalign}" \]]
  1196. %
  1197. % \end{grammar}
  1198. %
  1199. % As the syntax suggests, the preamble for the \env{eqnalign} environment
  1200. % works exactly the same way as for \env{eqnarray}. Example time: another
  1201. % one from the \textit{\TeX book}.
  1202. %
  1203. % \begin{figure}
  1204. % \begin{demo}[w]{Example of \env{eqnalign}}
  1205. %\[
  1206. % \left\{ \begin{eqnalign}[rl]
  1207. % \alpha &= f(z) \\ \beta &= f(z^2) \\
  1208. % \gamma &= f(z^3)
  1209. % \end{eqnalign} \right\}
  1210. % \qquad
  1211. % \left\{ \begin{eqnalign}[rl]
  1212. % x &= \alpha^2 - \beta \\ y &= 2\gamma
  1213. % \end{eqnalign} \right\}.
  1214. %\]
  1215. % \end{demo}
  1216. % \end{figure}
  1217. %
  1218. % \DescribeMacro{\multicolumn}
  1219. % The |\multicolumn| command works correctly in both the \env{eqnarray} and
  1220. % \env{eqnalign} environments, although you should bear in mind that you
  1221. % should give \env{eqnarray} column types, not \env{array} ones.
  1222. %
  1223. % \subsubsection{A note on spacing in alignment environments}
  1224. %
  1225. % Most of the time, equations in \env{eqnarray} and \env{eqnalign}
  1226. % environments will be beautiful. However, there are some things you should
  1227. % bear in mind when you produce beautiful equations.
  1228. %
  1229. % The main problem with spacing is making sure that binary relations and
  1230. % binary operators have the correct amount of space on each side of them.
  1231. % The alignment environments insert `hidden' objects at the ends of table
  1232. % cells to assist with the spacing: \lit{l} column types have a hidden object
  1233. % on the left, \lit{r} types have a hidden object on the right, and \lit{c}
  1234. % types have a hidden object on \emph{both} ends. These hidden objects add
  1235. % the correct space when there's a binary operator or relation next to them.
  1236. % If some other sort of object is lurking there, no space is added. So far,
  1237. % so good.
  1238. %
  1239. % The only problem comes when you have something like this:
  1240. %
  1241. % \begin{demo}{How not to do an \env{eqnarray}}
  1242. %\begin{eqnarray*}[rcl]
  1243. % x + y & = & 12 \\
  1244. % 2x - 5y & = & -6
  1245. %\end{eqnarray*}
  1246. % \end{demo}
  1247. %
  1248. % The `$-$' sign in the second equation has been treated as a binary operator
  1249. % when really it should be a unary prefix operator, but \TeX\ isn't clever
  1250. % enough to know the difference. (Can you see the difference in the spacing
  1251. % between $-6$~and~${}-6$?) There are two possible solutions to the
  1252. % problem. You could wrap the `|-6|' up in a group (`|{-6}|'), or just the
  1253. % $-$ sign (`|{-}6|'). A better plan, though, is to get rid of the middle
  1254. % column altogether:
  1255. %
  1256. % \begin{demo}{How to do an \env{eqnarray}}
  1257. %\begin{eqnarray*}[rl]
  1258. % x + y & = 12 \\
  1259. % 2x - 5y & = -6
  1260. %\end{eqnarray*}
  1261. % \end{demo}
  1262. %
  1263. % Since the things in the middle column were the same width, it's not
  1264. % actually doing any good. Also, now that \TeX\ can see that the thing on
  1265. % the left of the `$-$' sign is a relation (the `$=$' sign), it will space
  1266. % the formula correctly.
  1267. %
  1268. % In this case, it might be even better to add some extra columns, and line
  1269. % up the $x$ and $y$ terms in the left hand side:
  1270. %
  1271. % \begin{demo}{Extra beautiful \env{eqnarray}}
  1272. %\begin{eqnarray*}[rrl]
  1273. % x + & y & = 12 \\
  1274. % 2x - & 5y & = -6
  1275. %\end{eqnarray*}
  1276. % \end{demo}
  1277. %
  1278. % ^^A Some hacking now to display box sizes.
  1279. %
  1280. % {
  1281. % \catcode`p=12 \catcode`t=12
  1282. % \gdef\magni#1pt{#1}
  1283. % }
  1284. %
  1285. % \newcommand{\widthof}[1]{^^A
  1286. % \settowidth{\dimen0 }{#1}^^A
  1287. % \expandafter\magni\the\dimen0\,pt^^A
  1288. % }
  1289. %
  1290. % ^^A The text below makes an assumption which looks correct to me (I asked
  1291. % ^^A TeX, and it agreed with me), although in case anything changes, I want
  1292. % ^^A to be informed.
  1293. %
  1294. % \sbox0{$+$} \sbox2{$-$} \ifdim\wd0=\wd2\else%
  1295. % \errmessage{Assertion failed: `+' and `-' are different widths!}
  1296. % \fi
  1297. %
  1298. % There's no need to put the `$+$' and `$-$' operators in their own column
  1299. % here, because they're both \widthof{$+$} wide, even though they don't
  1300. % look it.
  1301. %
  1302. % \subsubsection{Configuring the alignment environments}
  1303. %
  1304. % There are a collection of parameters you can use to make the equation
  1305. % alignment environments (\env{eqnarray} and \env{eqnalign}) look the way
  1306. % you like them. These are all shown in table~\ref{tbl:eqnparms}.
  1307. %
  1308. % \begin{table}
  1309. % \begin{tabular}[C]{| l | p{3in} |} \hlx{hv}
  1310. % \bf Parameter & \bf Use \\ \hlx{vhv}
  1311. % |\eqaopenskip| & Length put on the left of an
  1312. % \env{eqnarray} environment. By
  1313. % default, this is |\@centering| (to
  1314. % centre the alignment) or |\mathindent|
  1315. % (to left align) depending on whether
  1316. % you're using the \textsf{fleqn}
  1317. % document class option. \\
  1318. % |\eqacloseskip| & Length put on the right of an
  1319. % \env{eqnarray} environment. By
  1320. % default, this is |\@centering|, to
  1321. % align the environment correctly. \\ \hlx{vhv}
  1322. % |\eqacolskip| & Space added by the \lit{:} column
  1323. % modifier. This should be a rubber
  1324. % length, although it only stretches in
  1325. % \env{eqnarray}, not in \env{eqnalign}.
  1326. % The default value is 1\smallf1/2\,em
  1327. % with 1000\,pt of stretch. \\
  1328. % |\eqainskip| & Space added at each side of a normal
  1329. % column. By default this is 0\,pt. \\ \hlx{vhv}
  1330. % |\eqastyle| & The maths style used in the alignment.
  1331. % By default, this is |\textstyle|,
  1332. % and you probably won't want to change
  1333. % it. \\ \hlx{vh}
  1334. % \end{tabular}
  1335. %
  1336. % \caption{Parameters for the \env{eqnarray} and \env{eqnalign} environments}
  1337. % \label{tbl:eqnparms}
  1338. % \end{table}
  1339. %
  1340. %
  1341. % \subsection{Other multiline equations}
  1342. %
  1343. % Sometimes there's no sensible alignment point for splitting equations. The
  1344. % normal thing to do under these circumstances is to put the first line way
  1345. % over to the left of the page, and the last line over to the right. (If
  1346. % there are more lines, I imagine we put them in the middle.)
  1347. %
  1348. % \DescribeEnv{spliteqn}
  1349. % \DescribeEnv{spliteqn*}
  1350. % The \env{spliteqn} environment allows you to do such splitting of
  1351. % equations. Rather than tediously describe it, I'll just give an example,
  1352. % because it's really easy. The $*$-version works the same, except it
  1353. % doesn't put an equation number in.
  1354. %
  1355. % \begin{figure}
  1356. % \begin{demo}[w]{A split equation}
  1357. %\begin{spliteqn}
  1358. % \sum_{1\le j\le n}
  1359. % \frac {1} { (x_j - x_1) \ldots (x_j - x_{j-1})
  1360. % (x - x_j) (x_j - x_{j+1}) \ldots (x_j - x_n) }
  1361. % \\
  1362. % = \frac {1} { (x - x_1) \ldots (x - x_n) }.
  1363. %\end{spliteqn}
  1364. % \end{demo}
  1365. % \end{figure}
  1366. %
  1367. % \DescribeEnv{subsplit}
  1368. % If you have a very badly behaved equation, you might want to split a part
  1369. % of it (say, a bit of a fraction), particularly if you're doing things in
  1370. % narrow columns.
  1371. %
  1372. % \begin{figure}
  1373. % \begin{demo}[w]{A \env{subsplit} environment}
  1374. %\begin{equation}
  1375. % \frac{
  1376. % \begin{subsplit}
  1377. % q^{\frac{1}{2} n(n+1)}(ea; q^2)_\infty (eq/a; q^2)_\infty \\
  1378. % (caq/e; q^2)_\infty (cq^2/ae; q^2)_\infty
  1379. % \end{subsplit}
  1380. % }{
  1381. % (e; q)_\infty (cq/e; q)_\infty
  1382. % }
  1383. %\end{equation}
  1384. % \end{demo}
  1385. % \end{figure}
  1386. %
  1387. % \subsection{Matrices}
  1388. %
  1389. % Also included in the \package{mathenv} package is a collection of things
  1390. % for typesetting matrices. The standard \env{array} doesn't (in my opinion)
  1391. % provide the right sort of spacing for matrices. \PlainTeX\ provides some
  1392. % quite nice matrix handling macros, but they don't work in the appropriate
  1393. % \LaTeX\ way.
  1394. %
  1395. % \textbf{Warning:} These definitions will make old versions of
  1396. % \package{plain.sty} unhappy; newer versions correctly restore the
  1397. % Plain~\TeX\ macros |\matrix| and |\pmatrix|.
  1398. %
  1399. % \DescribeEnv{matrix}
  1400. % The simple way to do matrices is with the \env{matrix} environment.
  1401. %
  1402. % \begin{grammar}
  1403. %
  1404. % <matrix-env> ::= \[[ <begin-matrix> <contents> <end-matrix> \]]
  1405. %
  1406. % <begin-matrix> ::= \[[ "\\begin{matrix}" \[ "[" <matrix-cols> "]" \] \]]
  1407. %
  1408. % <matrix-cols> ::= \[[
  1409. % \< \[ "[" \] \[ "T" \] \( "l" \\ "c" \\ "r" \) \>
  1410. % \]]
  1411. %
  1412. % <end-matrix> ::= \[[ "\\end{stack}" \]]
  1413. %
  1414. % \end{grammar}
  1415. %
  1416. % The \lit{l}, \lit{c} and \lit{r} columns are fairly obvious -- they align
  1417. % their contents in the appropriate way. The \lit{[} character is more
  1418. % complicated. It means `repeat the remaining column types forever', so a
  1419. % preamble of \lit{cc[lr} means `two centred columns, then alternating left-
  1420. % and right-aligned columns for as often as needed'. The default preamble,
  1421. % if you don't specify one, is \lit{[c} -- `any number of centred columns'.
  1422. %
  1423. % \DescribeMacro{\multicolumn}
  1424. % The |\multicolumn| command works correctly in matrices, although you should
  1425. % bear in mind that you should give \env{matrix} column types, not
  1426. % \env{array} ones.
  1427. %
  1428. % \DescribeEnv{pmatrix}
  1429. % The standard \env{matrix} environment doesn't put any delimiters around the
  1430. % matrix. You can use the standard |\left| and |\right| commands, although
  1431. % this is a bit nasty. The \env{pmatrix} environment will put parentheses
  1432. % around the matrix it creates; it's otherwise exactly the same as
  1433. % \env{matrix}.
  1434. %
  1435. % \DescribeEnv{dmatrix}
  1436. % A \env{dmatrix} environment is also provided. It takes two extra
  1437. % arguments: the left and right delimiter characters (without |\left| or
  1438. % |\right|).
  1439. %
  1440. % \begin{figure}
  1441. % \begin{demo}[w]{Various \env{matrix} environments}
  1442. %\[ \begin{matrix} 1 & 0 \\ 0 & -1 \end{matrix} \quad
  1443. % \begin{pmatrix}
  1444. % \cos\theta & \sin\theta \\
  1445. % -\sin\theta & \cos\theta
  1446. % \end{pmatrix} \quad
  1447. % \begin{dmatrix}[] 0 & -i \\ i & 0 \end{dmatrix}
  1448. %\]
  1449. % \end{demo}
  1450. % \end{figure}
  1451. %
  1452. % \DescribeEnv{smatrix}
  1453. % Normal matrices always come out the same size; they don't change size
  1454. % according to the surrounding context (unfortunately). However, it can be
  1455. % occasionally useful to put matrices in running text, so you can talk about
  1456. % $A$ being $\bigl( \begin{smatrix} a & b \\ b & c \end{smatrix} \bigr)$
  1457. % being its own transpose (i.e., $A = A^T$). This is accomplished using the
  1458. % \env{smatrix} (the `s' stands for `small' -- I thought that `smallmatrix'
  1459. % was too big to type inline). As well as inline text, the \env{smatrix}
  1460. % can be useful in displays, if the matrix is deep in a subformula. I can't
  1461. % think of any examples offhand, though.
  1462. %
  1463. % \DescribeEnv{spmatrix}
  1464. % \DescribeEnv{sdmatrix}
  1465. % The \env{smatrix} environment doesn't supply any delimiters, like
  1466. % \env{matrix}. There are \env{spmatrix} and \env{sdmatrix} environments
  1467. % which do, though. Note that delimiters have a tendency to get too big and
  1468. % mess up the line spacing -- I had to use explicitly |\big| delimiters
  1469. % in the above example.
  1470. %
  1471. % \DescribeEnv{pmatrix*}
  1472. % \DescribeEnv{spmatrix*}
  1473. % \DescribeEnv{sdmatrix*}
  1474. % All the small matrix environments have starred versions, which are more
  1475. % suitable for use in displays, since they have more space between the rows.
  1476. % They're intended for typesetting really big matrices in displays.
  1477. %
  1478. % \DescribeMacro{\ddots}
  1479. % \DescribeMacro{\vdots}
  1480. % The standard |\vdots| and |\ddots| commands don't produce anything at all
  1481. % nice in small matrices, so this package redefines them so that they scale
  1482. % properly to smaller sizes.
  1483. %
  1484. % \DescribeEnv{genmatrix}
  1485. % Actually, all these environments are special cases of one: \env{genmatrix}.
  1486. % This takes oodles of arguments:
  1487. % \begin{quote} \synshorts
  1488. % "\\begin{genmatrix}{"<matrix-style>"}{"<outer-style>"}" \\
  1489. % \null \qquad "{"<spacing>"}{"<left-delim>"}{"<right-delim>"}" \\
  1490. % \null \quad\vdots \\
  1491. % "\\end{genmatrix}"
  1492. % \end{quote}
  1493. % The two `style' arguments should be things like |\textstyle| or
  1494. % |\scriptstyle|; the first, \<matrix-style>, is the style to use for the
  1495. % matrix elements, and the second, \<outer-style>, is the style to assume
  1496. % for the surrounding text (this affects the spacing within the matrix; it
  1497. % should usually be the same as \<matrix-style>). The \<spacing> is inserted
  1498. % between the matrix and the delimiters, on each side of the matrix. It's
  1499. % usually `|\,|' in full-size matrices, and blank for small ones. The
  1500. % delimiters are inserted around the matrices, and sized appropriately.
  1501. %
  1502. % \DescribeEnv{newmatrix}
  1503. % You can create your own matrix environments if you like, using the
  1504. % |\newmatrix| command. It takes two arguments, although they're a bit
  1505. % odd. The first is the name of the environment, and the second contains
  1506. % the arguments to pass to \env{genmatrix}. For example, the \env{pmatrix}
  1507. % environment was defined by saying
  1508. %
  1509. % \begin{listing}
  1510. %\newmatrix{pmatrix}{{\textstyle}{\textstyle}{\,}{(}{)}}
  1511. % \end{listing}
  1512. %
  1513. % If you don't pass all three arguments, then you end up requiring the
  1514. % user to specify the remaining ones. This is how \env{dmatrix} works.
  1515. %
  1516. % \DescribeEnv{script}
  1517. % Finally, although it's not really a matrix, stacked super- and subscripts
  1518. % follow much the same sorts of spacing rules. The \env{script} environment
  1519. % allows you to do this sort of thing very easily. It essentially provides
  1520. % a `matrix' with the right sort of spacing. The default preamble string is
  1521. % \lit{c}, giving you centred scripts, although you can say
  1522. % |\begin{script}[l]| for left-aligned scripts, which is better if the
  1523. % script is being placed to the right of its operator. If you're really
  1524. % odd, you can have more than one column.
  1525. %
  1526. % \begin{demo}{Example of \env{script}}
  1527. %\[ \mathop{{\sum}'}_{x \in A}
  1528. % f(x)
  1529. % \stackrel{\mathrm{def}}{=}
  1530. % \sum_{\begin{script}
  1531. % x \in A \\ x \ne 0
  1532. % \end{script}} f(x)
  1533. %\]
  1534. % \end{demo}
  1535. %
  1536. %
  1537. % \subsection{Other \package{mathenv} environments}
  1538. %
  1539. % The \package{mathenv} package contains some other environments which may
  1540. % be useful, based on the enhanced \env{tabular} and \env{array}
  1541. % environments.
  1542. %
  1543. % \DescribeEnv{cases}
  1544. % The \env{cases} environment lets you say things like the following:
  1545. %
  1546. % \begin{demo}[w]{Example of \env{cases}}
  1547. %\[ P_{r-j} = \begin{cases}
  1548. % 0 & if $r-j$ is odd \\
  1549. % r!\,(-1)^{(r-j)/2} & if $r-j$ is even
  1550. % \end{cases}
  1551. %\]
  1552. % \end{demo}
  1553. %
  1554. % The spacing required for this is a bit messy, so providing an environment
  1555. % for it is quite handy.
  1556. %
  1557. % \DescribeEnv{smcases}
  1558. % The \env{smcases} environment works the same way as \env{cases}, but with
  1559. % scriptsize lettering.
  1560. %
  1561. % \implementation
  1562. %
  1563. %
  1564. %^^A-------------------------------------------------------------------------
  1565. % \section{Implementation of table handling}
  1566. %
  1567. %
  1568. % Here we go. It starts horrid and gets worse. However, it does stay nicer
  1569. % than the original, IMHO.
  1570. %
  1571. % \begin{macrocode}
  1572. %<*mdwtab>
  1573. % \end{macrocode}
  1574. %
  1575. %
  1576. % \subsection{Registers, switches and things}
  1577. %
  1578. % We need lots of these. It's great fun.
  1579. %
  1580. % The two count registers are simple enough:
  1581. %
  1582. % \begin{description}
  1583. % \item [\cs{tab@state}] contains the current parser state. Since we
  1584. % probably won't be parsing preambles recursively, this is a global
  1585. % variable.
  1586. % \item [\cs{tab@columns}] contains the number of the current column.
  1587. % \item [\cs{tab@hlstate}] contains the state required for hline management.
  1588. % \end{description}
  1589. %
  1590. % \begin{macrocode}
  1591. \newcount\tab@state
  1592. \newcount\tab@columns
  1593. % \end{macrocode}
  1594. %
  1595. % We need \emph{lots} of token registers. Fortunately, most of them are only
  1596. % used during parsing. We'll use \PlainTeX's scratch tokens for this. Note
  1597. % that |\toks\tw@| isn't used here. It, and |\toks@|, are free for use by
  1598. % column commands.
  1599. %
  1600. % \begin{macrocode}
  1601. \newtoks\tab@preamble
  1602. \newtoks\tab@shortline
  1603. \toksdef\tab@pretext 4
  1604. \toksdef\tab@posttext 6
  1605. \toksdef\tab@userpretext 8
  1606. % \end{macrocode}
  1607. %
  1608. % The dimens are fairly straightforward. The inclusion of |\col@sep| is a
  1609. % sacrifice to compatibility -- judicious use of |\let| in \package{array}
  1610. % would have saved a register.
  1611. %
  1612. % \begin{macrocode}
  1613. \newdimen\extrarowheight
  1614. \newdimen\tabextrasep
  1615. \newdimen\arrayextrasep
  1616. \newdimen\smarraycolsep
  1617. \newdimen\smarrayextrasep
  1618. \newdimen\tab@width
  1619. \newdimen\col@sep
  1620. \newdimen\tab@endheight
  1621. % \end{macrocode}
  1622. %
  1623. % Some skip registers too. Phew.
  1624. %
  1625. % \begin{macrocode}
  1626. \newskip\tab@leftskip
  1627. \newskip\tab@rightskip
  1628. % \end{macrocode}
  1629. %
  1630. % And some switches. The first three are for the parser.
  1631. %
  1632. % \begin{macrocode}
  1633. \newif\iftab@firstcol
  1634. \newif\iftab@initrule
  1635. \newif\iftab@rule
  1636. \newif\iftab@vgap
  1637. % \end{macrocode}
  1638. %
  1639. % Now assign some default values to new dimen parameters. These definitions
  1640. % are essentially the equivalent of an |\openup 1\jot| in \env{array}, but
  1641. % not in \env{tabular}. This looks nice, I think.
  1642. %
  1643. % \begin{macrocode}
  1644. \tabextrasep\z@
  1645. \arrayextrasep\jot
  1646. \smarraycolsep\thr@@\p@
  1647. \smarrayextrasep\z@
  1648. % \end{macrocode}
  1649. %
  1650. % Set some things up for alien table environments.
  1651. %
  1652. % \begin{macrocode}
  1653. \let\tab@extrasep\tabextrasep
  1654. \let\tab@penalty\relax
  1655. % \end{macrocode}
  1656. %
  1657. %
  1658. % \subsection{Some little details}
  1659. %
  1660. % \begin{macro}{\@maybe@unskip}
  1661. %
  1662. % This macro solves a little problem. In an alignment (and in other places)
  1663. % it's desirable to suppress trailing space. The usual method, to say
  1664. % |\unskip|, is a little hamfisted, because it removes perfectly reasonable
  1665. % aligning spaces like |\hfil|s. While as a package writer I can deal with
  1666. % this sort of thing by saying |\kern\z@| in appropriate places, it can
  1667. % annoy users who are trying to use |\hfill| to override alignment in funny
  1668. % places.
  1669. %
  1670. % My current solution seems to be acceptable. I'll remove the natural width
  1671. % of the last glue item, so that it can still stretch and shrink if
  1672. % necessary. The implementation makes use of the fact that multiplying
  1673. % a \<skip> by a \<number> kills off the stretch. (Bug fix: don't do this
  1674. % when we're in vertical mode.)
  1675. %
  1676. % \begin{macrocode}
  1677. \def\@maybe@unskip{\ifhmode\hskip\m@ne\lastskip\relax\fi}
  1678. % \end{macrocode}
  1679. %
  1680. % \end{macro}
  1681. %
  1682. % \begin{macro}{\q@delim}
  1683. %
  1684. % Finally, for the sake of niceness, here's a delimiter token I can use
  1685. % for various things. It's a `quark', for what it's worth (i.e., it expands
  1686. % to itself) although I'm not really sure why this is a good thing. As far
  1687. % as I'm concerned, it's important that it has a unique meaning (i.e., that
  1688. % it won't be |\ifx|-equal to other things, or something undefined) and that
  1689. % it won't be used where I don't expect it to be used. \TeX\ will loop
  1690. % horridly if it tries to expand this, so I don't think that quarks are
  1691. % wonderfully clever thing to use. (Maybe it should really expand to
  1692. % something like `\syntax{<quark>"."}', which will rapdly fill \TeX's memory
  1693. % if it gets accidentally expanded. Still, I'll leave it as it is until
  1694. % such time as I understand the idea more.)
  1695. %
  1696. % \begin{macrocode}
  1697. \def\q@delim{\q@delim}
  1698. % \end{macrocode}
  1699. %
  1700. % \end{macro}
  1701. %
  1702. %
  1703. % \subsection{Parser states}
  1704. %
  1705. % Now we start on the parser. It's really simple, deep down. We progress
  1706. % from state to state, extracing tokens from the preamble and building
  1707. % command names from them. Each command calls one of the element-building
  1708. % routines, which works out which state it should be in. We go through each
  1709. % of the states in between (see later) doing default things for the ones we
  1710. % missed out.
  1711. %
  1712. % Anyway, here's some symbolic names for the states. It makes my life
  1713. % easier.
  1714. %
  1715. % \begin{macrocode}
  1716. \chardef\tab@startstate 0
  1717. \chardef\tab@loopstate 1
  1718. \chardef\tab@rulestate 1
  1719. \chardef\tab@prespcstate 2
  1720. \chardef\tab@prestate 3
  1721. \chardef\tab@colstate 4
  1722. \chardef\tab@poststate 5
  1723. \chardef\tab@postspcstate 6
  1724. \chardef\tab@limitstate 7
  1725. % \end{macrocode}
  1726. %
  1727. %
  1728. % \subsection{Adding things to token lists}
  1729. %
  1730. % Define some macros for adding stuff to the beginning and end of token
  1731. % lists. This is really easy, actually. Here we go.
  1732. %
  1733. % \begin{macrocode}
  1734. \def\tab@append#1#2{#1\expandafter{\the#1#2}}
  1735. \def\tab@prepend#1#2{%
  1736. \toks@{#2}#1\expandafter{\the\expandafter\toks@\the#1}%
  1737. }
  1738. % \end{macrocode}%
  1739. %
  1740. %
  1741. % \subsection{Committing a column to the preamble}
  1742. %
  1743. % Each time we pass the `rule' state, we `commit' the tokens we've gathered
  1744. % so far to the main preamble token list. This is how we do it. Note the
  1745. % icky use of |\expandafter|.
  1746. %
  1747. % \begin{macrocode}
  1748. \def\tab@commit{%
  1749. % \end{macrocode}
  1750. %
  1751. % If this isn't the first column, then we need to put in a column separator.
  1752. %
  1753. % \begin{macrocode}
  1754. \iftab@firstcol\else%
  1755. \expandafter\tab@append\expandafter\tab@preamble%
  1756. \expandafter{\tab@tabtext}%
  1757. \fi%
  1758. % \end{macrocode}
  1759. %
  1760. % Now we spill the token registers into the main list in a funny order (which
  1761. % is why we're doing it in this strange way in the first place.
  1762. %
  1763. % \begin{macrocode}
  1764. \toks@\expandafter{\tab@midtext}%
  1765. \tab@preamble\expandafter{%
  1766. \the\expandafter\tab@preamble%
  1767. \the\expandafter\tab@pretext%
  1768. \the\expandafter\tab@userpretext%
  1769. \the\expandafter\toks@%
  1770. \the\tab@posttext%
  1771. }%
  1772. % \end{macrocode}
  1773. %
  1774. % Now reset token lists and things for the next go round.
  1775. %
  1776. % \begin{macrocode}
  1777. \tab@firstcolfalse%
  1778. \tab@pretext{}%
  1779. \tab@userpretext{}%
  1780. \tab@posttext{}%
  1781. }
  1782. % \end{macrocode}
  1783. %
  1784. %
  1785. % \subsection{Playing with parser states}
  1786. %
  1787. % \begin{macro}{\tab@setstate}
  1788. %
  1789. % This is how we set new states. The algorithm is fairly simple, really.
  1790. %
  1791. % ^^A Let's see how good my TeX really is... ;-)
  1792. % ^^A Actually, it doesn't seem to have worked out too badly. Maybe I should
  1793. % ^^A write a package to do this automatically. It's rather tricky, though.
  1794. %
  1795. % \def\qq{\mbox{\quad}}
  1796. % \sbox{0}{\itshape\textunderscore}\def\_{\usebox{0}}
  1797. %
  1798. % \begin{quote}
  1799. % {\bf while} $\it tab\_state \ne s$ {\bf do} \\
  1800. % \qq $\mathit{tab\_state = tab\_state}+1$; \\
  1801. % \qq {\bf if} $\it tab\_state = tab\_limitState$ {\bf then}
  1802. % $\it tab\_state=tab\_loopState$; \\
  1803. % \qq {\bf if} $\it tab\_state = tab\_preSpcState$ {\bf then} \\
  1804. % \qq \qq {\bf if} $\it tab\_initRule$ {\bf then} \\
  1805. % \qq \qq \qq $\it tab\_initRule = {\bf false}$; \\
  1806. % \qq \qq {\bf else} \\
  1807. % \qq \qq \qq {\bf if} $\it tab\_inMultiCol$ {\bf then moan}; \\
  1808. % \qq \qq \qq $\it commit$; \\
  1809. % \qq \qq \qq $\it append(tab\_shortLine,\hbox{`|&\omit|')}$; \\
  1810. % \qq \qq {\bf end\,if}; \\
  1811. % \qq {\bf end\,if}; \\
  1812. % \qq {\bf if} $\it tab\_state \ne s$ {\bf then}
  1813. % $\it do\_default(tab\_state)$; \\
  1814. % {\bf end\,while};
  1815. % \end{quote}
  1816. %
  1817. % First we decide if there's anything to do. If so, we call another macro to
  1818. % do it for us.
  1819. %
  1820. % \begin{macrocode}
  1821. \def\tab@setstate#1{%
  1822. \ifnum#1=\tab@state\else%
  1823. \def\@tempa{\tab@setstate@i{#1}}%
  1824. \@tempa%
  1825. \fi%
  1826. }
  1827. % \end{macrocode}
  1828. %
  1829. % This is where the fun is. First we bump the state by one, and loop back
  1830. % if we fall off the end.
  1831. %
  1832. % \begin{macrocode}
  1833. \def\tab@setstate@i#1{%
  1834. \global\advance\tab@state\@ne%
  1835. \ifnum\tab@state>\tab@limitstate%
  1836. \global\tab@state\tab@loopstate%
  1837. \fi%
  1838. % \end{macrocode}
  1839. %
  1840. % Now, if we've just passed the ruleoff state, we commit the current text
  1841. % \emph{unless} this was the strange initial rule at the very beginning. We
  1842. % provide a little hook here so that |\multicolumn| can moan if you try and
  1843. % give more than one column there. We also add another tab/omit pair to the
  1844. % list we use for |\vgap|.
  1845. %
  1846. % \begin{macrocode}
  1847. \ifnum\tab@state=\tab@prespcstate%
  1848. \iftab@initrule%
  1849. \tab@initrulefalse%
  1850. \else%
  1851. \tab@looped%
  1852. \tab@commit%
  1853. \tab@append\tab@shortline{&\omit}%
  1854. \fi%
  1855. \fi%
  1856. % \end{macrocode}
  1857. %
  1858. % Now we decide whether to go round again. If not, we do the default thing
  1859. % for this state. This is mainly here so that we can put the |\tabcolsep| or
  1860. % whatever in if the user didn't give an \lit{@} expression.
  1861. %
  1862. % \begin{macrocode}
  1863. \ifnum#1=\tab@state%
  1864. \let\@tempa\relax%
  1865. \else%
  1866. \csname tab@default@\number\tab@state\endcsname%
  1867. \fi%
  1868. \@tempa%
  1869. }
  1870. % \end{macrocode}
  1871. %
  1872. % \end{macro}
  1873. %
  1874. % Now we set up the default actions for the various states.
  1875. %
  1876. % In state~2 (pre-space) we add in the default gap if either we didn't have
  1877. % an \lit{@} expression in the post-space state or there was an explicit
  1878. % intervening rule.
  1879. %
  1880. % \begin{macrocode}
  1881. \@namedef{tab@default@2}{%
  1882. \iftab@rule%
  1883. \tab@append\tab@pretext{\hskip\col@sep}%
  1884. \fi%
  1885. }
  1886. % \end{macrocode}
  1887. %
  1888. % If the user omits the column type, we insert an `l'-type column and moan
  1889. % a lot.
  1890. %
  1891. % \begin{macrocode}
  1892. \@namedef{tab@default@4}{%
  1893. \tab@err@misscol%
  1894. \tab@append\tab@pretext{\tab@bgroup\relax}%
  1895. \tab@append\tab@posttext{\relax\tab@egroup\hfil}%
  1896. \tab@append\tab@shortline{\hfil}%
  1897. \advance\tab@columns\@ne%
  1898. }
  1899. % \end{macrocode}
  1900. %
  1901. % Finally we deal with the post-space state. We set a marker so that we
  1902. % put in the default space in the pre-space state later too.
  1903. %
  1904. % \begin{macrocode}
  1905. \@namedef{tab@default@6}{%
  1906. \tab@append\tab@posttext{\hskip\col@sep}%
  1907. \tab@ruletrue%
  1908. }
  1909. % \end{macrocode}
  1910. %
  1911. %
  1912. % \subsection{Declaring token types}
  1913. %
  1914. % \begin{macro}{\tab@extracol}
  1915. %
  1916. % Before we start, we need to handle |\extracolsep|. This is a right pain,
  1917. % because the original version of \env{tabular} worked on total expansion,
  1918. % which is a Bad Thing. On the other hand, turning |\extracolsep| into a
  1919. % |\tabskip| is also a major pain.
  1920. %
  1921. % \begin{macrocode}
  1922. \def\tab@extracol#1#2{\tab@extracol@i#1#2\extracolsep{}\extracolsep\end}
  1923. \def\tab@extracol@i#1#2\extracolsep#3#4\extracolsep#5\end{%
  1924. \ifx @#3@%
  1925. \def\@tempa{#1{#2}}%
  1926. \else%
  1927. \def\@tempa{#1{#2\tabskip#3\relax#4}}%
  1928. \fi%
  1929. \@tempa%
  1930. }
  1931. % \end{macrocode}
  1932. %
  1933. % \end{macro}
  1934. %
  1935. % This is where we do the work for inserting preamble elements.
  1936. %
  1937. % \begin{macro}{\tabruletype}
  1938. %
  1939. % Inserting rules is interesting, because we have to decide where to put
  1940. % them. If this is the funny initial rule, it goes in the pre-text list,
  1941. % otherwise it goes in the post-text list. We work out what to do first
  1942. % thing:
  1943. %
  1944. % \begin{macrocode}
  1945. \def\tabruletype#1{\tab@extracol\tabruletype@i{#1}}%
  1946. \def\tabruletype@i#1{%
  1947. \iftab@initrule%
  1948. \let\tab@tok\tab@pretext%
  1949. \else%
  1950. \let\tab@tok\tab@posttext%
  1951. \fi%
  1952. % \end{macrocode}
  1953. %
  1954. % Now if we're already in the rule state, we must have just done a rule.
  1955. % This means we must put in the |\doublerulesep| space, both here and in the
  1956. % shortline list. Otherwise we just stick the rule in.
  1957. %
  1958. % This is complicated, because |\vgap| needs to be able to remove some bits
  1959. % of rule. We pass each one to a macro |\tab@ckr|, together with the column
  1960. % number, which is carefully bumped at the right times, and this macro will
  1961. % vet the rules and output the appropriate ones. There's lots of extreme
  1962. % |\expandafter| nastiness as a result. Amazingly, this actually works.
  1963. %
  1964. % \begin{macrocode}
  1965. \ifnum\tab@state=\tab@rulestate%
  1966. \tab@append\tab@tok{\hskip\doublerulesep\begingroup#1\endgroup}%
  1967. \expandafter\tab@append\expandafter\tab@shortline\expandafter{%
  1968. \expandafter\hskip\expandafter\doublerulesep%
  1969. \expandafter\tab@ckr\expandafter{\the\tab@columns}%
  1970. {\begingroup#1\endgroup}%
  1971. }%
  1972. \else%
  1973. \tab@setstate\tab@rulestate%
  1974. \tab@append\tab@tok{\begingroup#1\endgroup}%
  1975. \expandafter\tab@append\expandafter\tab@shortline\expandafter{%
  1976. \expandafter\tab@ckr\expandafter{\the\tab@columns}%
  1977. {\begingroup#1\endgroup}%
  1978. }%
  1979. \fi%
  1980. % \end{macrocode}
  1981. %
  1982. % Finally, we say there was a rule here, so that default space gets put in
  1983. % after this. Otherwise we lose lots of generality.
  1984. %
  1985. % \begin{macrocode}
  1986. \tab@ruletrue%
  1987. }
  1988. % \end{macrocode}
  1989. %
  1990. % \end{macro}
  1991. %
  1992. % \begin{macro}{\tabspctype}
  1993. %
  1994. % We need to work out which space-state we should be in. Then we just put
  1995. % the text in. Easy, really.
  1996. %
  1997. % \begin{macrocode}
  1998. \def\tabspctype#1{\tab@extracol\tabspctype@i{#1}}%
  1999. \def\tabspctype@i#1{%
  2000. \tab@rulefalse%
  2001. \ifnum\tab@state>\tab@prespcstate%
  2002. \tab@setstate\tab@postspcstate%
  2003. \let\tab@tok\tab@posttext%
  2004. \else%
  2005. \tab@setstate\tab@prespcstate%
  2006. \let\tab@tok\tab@pretext%
  2007. \fi%
  2008. \tab@append\tab@tok{\begingroup#1\endgroup}%
  2009. }
  2010. % \end{macrocode}
  2011. %
  2012. % \end{macro}
  2013. %
  2014. % \begin{macro}{\tabcoltype}
  2015. %
  2016. % If we're already in the column state, we bump the state and loop round
  2017. % again, to get all the appropriate default behaviour. We bump the column
  2018. % counter, and add the bits of text we were given to appropriate token lists.
  2019. % We also add the |\hfil| glue to the shortline list, to space out the rules
  2020. % properly.
  2021. %
  2022. % \begin{macrocode}
  2023. \def\tabcoltype#1#2{%
  2024. \ifnum\tab@state=\tab@colstate%
  2025. \global\advance\tab@state\@ne%
  2026. \fi%
  2027. \advance\tab@columns\@ne%
  2028. \tab@setstate\tab@colstate%
  2029. \tab@append\tab@pretext{#1}%
  2030. \tab@append\tab@posttext{#2}%
  2031. \tab@append\tab@shortline{\hfil}%
  2032. }
  2033. % \end{macrocode}
  2034. %
  2035. % \end{macro}
  2036. %
  2037. % \begin{macro}{\tabuserpretype}
  2038. % \begin{macro}{\tabuserposttype}
  2039. %
  2040. % These are both utterly trivial.
  2041. %
  2042. % \begin{macrocode}
  2043. \def\tabuserpretype#1{%
  2044. \tab@setstate\tab@prestate%
  2045. \tab@prepend\tab@userpretext{#1}%
  2046. }
  2047. % \end{macrocode}
  2048. %
  2049. % \begin{macrocode}
  2050. \def\tabuserposttype#1{%
  2051. \tab@setstate\tab@poststate%
  2052. \tab@prepend\tab@posttext{#1}%
  2053. }
  2054. % \end{macrocode}
  2055. %
  2056. % \end{macro}
  2057. % \end{macro}
  2058. %
  2059. %
  2060. % \subsection{The colset stack}
  2061. %
  2062. % Let's start with something fairly easy. We'll keep a stack of column sets
  2063. % so that users don't get confused by package authors changing the current
  2064. % column set. This is fairly easy, really.
  2065. %
  2066. % \begin{macro}{\tab@push}
  2067. % \begin{macro}{\tab@pop}
  2068. % \begin{macro}{\tab@head}
  2069. %
  2070. % These are the stack management routines. The only important thing to note
  2071. % is that |\tab@head| must take place \emph{only} in \TeX's mouth, so we can
  2072. % use it in |\csname|\dots|\endcsname| constructions.
  2073. %
  2074. % \begin{macrocode}
  2075. \def\tab@push#1#2{%
  2076. \toks@{{#2}}%
  2077. \expandafter\def\expandafter#1\expandafter{\the\expandafter\toks@#1}%
  2078. }
  2079. \def\tab@pop#1{\expandafter\def\expandafter#1\expandafter{\@gobble#1}}
  2080. \def\tab@head#1{\expandafter\tab@head@i#1\relax}
  2081. \def\tab@head@i#1#2\relax{#1}
  2082. % \end{macrocode}
  2083. %
  2084. % \end{macro}
  2085. % \end{macro}
  2086. % \end{macro}
  2087. %
  2088. % \begin{macro}{\colset}
  2089. % \begin{macro}{\colpush}
  2090. % \begin{macro}{\colpop}
  2091. %
  2092. % Now we can define the user macros.
  2093. %
  2094. % \begin{macrocode}
  2095. \def\tab@colstack{{tabular}}
  2096. \def\colset{\colpop\colpush}
  2097. \def\colpush{\tab@push\tab@colstack}
  2098. \def\colpop{\tab@pop\tab@colstack}
  2099. % \end{macrocode}
  2100. %
  2101. % \end{macro}
  2102. % \end{macro}
  2103. % \end{macro}
  2104. %
  2105. % \begin{macro}{\tab@colset}
  2106. %
  2107. % Now we define a shortcut for reading the top item off the stack.
  2108. %
  2109. % \begin{macrocode}
  2110. \def\tab@colset{\tab@head\tab@colstack}
  2111. % \end{macrocode}
  2112. %
  2113. % \end{macro}
  2114. %
  2115. %
  2116. % \subsection{The main parser routine}
  2117. %
  2118. % \begin{macro}{\tab@initread}
  2119. %
  2120. % This macro sets up lots of variables to their normal states prior to
  2121. % parsing a preamble. Some things may need changing, but not many.
  2122. %
  2123. % \begin{macrocode}
  2124. \def\tab@initread{%
  2125. % \end{macrocode}
  2126. %
  2127. % First, reset the parser state to the start state.
  2128. %
  2129. % \begin{macrocode}
  2130. \global\tab@state\tab@startstate%
  2131. % \end{macrocode}
  2132. %
  2133. % We clear the token lists to sensible values, mostly. The midtext macro
  2134. % contains what to put in the very middle of each template -- |\multicolumn|
  2135. % will insert its argument here.
  2136. %
  2137. % \begin{macrocode}
  2138. \tab@preamble{}%
  2139. \tab@shortline{}%
  2140. \def\tab@tabtext{&}%
  2141. \def\tab@midtext{\ignorespaces####\@maybe@unskip}%
  2142. \tab@pretext{}%
  2143. \tab@userpretext{}%
  2144. \tab@posttext{}%
  2145. \let\tab@multicol\@empty%
  2146. \def\tab@startpause{\penalty\postdisplaypenalty\medskip}%
  2147. \def\tab@endpause{\penalty\predisplaypenalty\medskip}%
  2148. % \end{macrocode}
  2149. %
  2150. % Finally, reset the column counter, don't raise errors when we loop, and set
  2151. % some parser flags to their appropriate values.
  2152. %
  2153. % \begin{macrocode}
  2154. \tab@columns\z@%
  2155. \let\tab@looped\relax%
  2156. \tab@ruletrue%
  2157. \tab@initruletrue%
  2158. \tab@firstcoltrue%
  2159. }
  2160. % \end{macrocode}
  2161. %
  2162. % \end{macro}
  2163. %
  2164. % \begin{macro}{\tab@readpreamble}
  2165. %
  2166. % This is the main macro for preamble handling. Actually, all it does is
  2167. % gobble its argument's leading brace and call another macro, but it does it
  2168. % with style.
  2169. %
  2170. % \begin{macrocode}
  2171. \def\tab@readpreamble#1{%
  2172. \tab@doreadpream{#1}%
  2173. \iftab@initrule\global\tab@state\tab@prespcstate\fi%
  2174. \tab@setstate\tab@rulestate%
  2175. \tab@commit%
  2176. }
  2177. % \end{macrocode}
  2178. %
  2179. % \end{macro}
  2180. %
  2181. % \begin{macro}{\tab@doreadpream}
  2182. %
  2183. % The preamble is in an argument. Previous versions used a nasty trick using
  2184. % |\let| and |\afterassignment|. Now we use an explicit end token, to allow
  2185. % dodgy column type handlers to scoop up the remaining preamble tokens
  2186. % and process them. Not that anyone would want to do that, oh no (see
  2187. % the \lit{[} type in the \env{eqnarray} environment |;-)|).
  2188. %
  2189. % \begin{macrocode}
  2190. \def\tab@doreadpream#1{\tab@mkpreamble#1\q@delim}
  2191. % \end{macrocode}
  2192. %
  2193. % \end{macro}
  2194. %
  2195. % \begin{macro}{\tab@mkpreamble}
  2196. %
  2197. % This is the main parser routine. It takes each token in turn, scrutinises
  2198. % it carefully, and does the appropriate thing with it.
  2199. %
  2200. % The preamble was given as an argument to |\tab@doreadpream|, and that has
  2201. % helpfully stripped off the initial |{| character. We need to pick off the
  2202. % next token (whatever it is) so we can examine it. We'll use |\futurelet|
  2203. % so we can detect groups and things in funny places.
  2204. %
  2205. % \begin{macrocode}
  2206. \def\tab@mkpreamble{\futurelet\@let@token\tab@mkpreamble@i}
  2207. % \end{macrocode}
  2208. %
  2209. % If we find a space token, we'll go off and do something a bit special,
  2210. % since spaces are sort of hard to handle. Otherwise we'll do it in the old
  2211. % fashioned way.
  2212. %
  2213. % \begin{macrocode}
  2214. \def\tab@mkpreamble@i{%
  2215. \ifx\@let@token\@sptoken%
  2216. \expandafter\tab@mkpreamble@spc%
  2217. \else%
  2218. \expandafter\tab@mkpreamble@ii%
  2219. \fi%
  2220. }
  2221. % \end{macrocode}
  2222. %
  2223. % If we find a |\@@endpreamble| token, that's it and we're finished. We just
  2224. % gobble it and return. Otherwise, if it's an open group character, we'll
  2225. % complain because someone's probably tried to put an argument in the wrong
  2226. % place. Finally, if none of the other things apply, we'll deal with the
  2227. % character below.
  2228. %
  2229. % \begin{macrocode}
  2230. \def\tab@mkpreamble@ii{%
  2231. \ifx\@let@token\q@delim%
  2232. \def\@tempa{\let\@let@token}%
  2233. \else%
  2234. \ifcat\bgroup\noexpand\@let@token%
  2235. \tab@err@oddgroup%
  2236. \def\@tempa##1{\tab@mkpreamble}%
  2237. \else%
  2238. \let\@tempa\tab@mkpreamble@iii%
  2239. \fi%
  2240. \fi%
  2241. \@tempa%
  2242. }
  2243. % \end{macrocode}
  2244. %
  2245. % Handle a character. This involves checking to see if it's actually
  2246. % defined, and then doing it. Doing things this way means we won't get
  2247. % stranded in mid-preamble unless a package author has blown it.
  2248. %
  2249. % \begin{macrocode}
  2250. \def\tab@mkpreamble@iii#1{%
  2251. \@ifundefined{\tab@colset!col.\string#1}{%
  2252. \tab@err@undef{#1}\tab@mkpreamble%
  2253. }{%
  2254. \@nameuse{\tab@colset!col.\string#1}%
  2255. }%
  2256. }
  2257. % \end{macrocode}
  2258. %
  2259. % If we get given a space character, we'll look up the command name as
  2260. % before. If no-one's defined the column type we'll just skip it silently,
  2261. % which lets users do pretty formatting if they like.
  2262. %
  2263. % \begin{macrocode}
  2264. \@namedef{tab@mkpreamble@spc} {%
  2265. \@ifundefined{\tab@colset!col. }{%
  2266. \tab@mkpreamble%
  2267. }{%
  2268. \@nameuse{\tab@colset!col. }%
  2269. }%
  2270. }
  2271. % \end{macrocode}
  2272. %
  2273. % \end{macro}
  2274. %
  2275. % \begin{macro}{\coldef}
  2276. %
  2277. % Here's how to define column types the nice way. Some dexterity is required
  2278. % to make everything work right, but it's simple really.
  2279. %
  2280. % \begin{macrocode}
  2281. \def\coldef{\@ifnextchar[\coldef@i{\coldef@i[\tab@colset]}}
  2282. \def\coldef@i[#1]#2#3#{\coldef@ii[#1]{#2}{#3}}
  2283. \def\coldef@ii[#1]#2#3#4{%
  2284. \expandafter\def\csname#1!col.\string#2\endcsname#3{%
  2285. #4\tab@mkpreamble%
  2286. }%
  2287. }
  2288. % \end{macrocode}
  2289. %
  2290. % \end{macro}
  2291. %
  2292. % \begin{macro}{\collet}
  2293. %
  2294. % We'd like to let people copy column types from other places. This is how
  2295. % to do it.
  2296. %
  2297. % \begin{macrocode}
  2298. \def\collet{\@ifnextchar[\collet@i{\collet@i[\tab@colset]}}
  2299. \def\collet@i[#1]#2{%
  2300. \@ifnextchar=%
  2301. {\collet@ii[#1]{#2}}%
  2302. {\collet@ii[#1]{#2}=}%
  2303. }
  2304. \def\collet@ii[#1]#2={%
  2305. \@ifnextchar[%
  2306. {\collet@iii[#1]{#2}}%
  2307. {\collet@iii[#1]{#2}[\tab@colset]}%
  2308. }
  2309. \def\collet@iii[#1]#2[#3]#4{%
  2310. \expandafter\let\csname#1!col.\string#2\expandafter\endcsname%
  2311. \csname#3!col.\string#4\endcsname%
  2312. }
  2313. % \end{macrocode}
  2314. %
  2315. % \end{macro}
  2316. %
  2317. % \begin{macro}{\newcolumntype}
  2318. %
  2319. % We just bundle the text off to |\newcommand| and expect it to cope. It
  2320. % ought to. The column type code inserts the user's tokens directly, rather
  2321. % than calling |\tab@doreadpream| recursively. The magic control sequence
  2322. % is the one looked up by the parser.
  2323. %
  2324. % There's some additional magic here for compatiblity with the obscure way
  2325. % that \package{array} works.
  2326. %
  2327. % \begin{macrocode}
  2328. \def\newcolumntype#1{\@ifnextchar[{\nct@i{#1}}{\nct@i#1[0]}}
  2329. \def\nct@i#1[#2]{\@ifnextchar[{\nct@ii{#1}[#2]}{\nct@iii{#1}{[#2]}}}
  2330. \def\nct@ii#1[#2][#3]{\nct@iii{#1}{[#2][#3]}}
  2331. \def\nct@iii#1#2#3{%
  2332. \expandafter\let\csname\tab@colset!col.\string#1\endcsname\relax%
  2333. \expandafter\newcommand\csname\tab@colset!col.\string#1\endcsname#2{%
  2334. \tab@deepmagic{#1}%
  2335. \tab@mkpreamble%
  2336. #3%
  2337. }%
  2338. }
  2339. % \end{macrocode}
  2340. %
  2341. % Now for some hacking for compatibility with \package{tabularx}.
  2342. %
  2343. % \begin{macrocode}
  2344. \def\newcol@#1[#2]{\nct@iii{#1}{[#2]}}
  2345. % \end{macrocode}
  2346. %
  2347. % And now some more. This is seriously deep magic. Hence the name.
  2348. %
  2349. % \begin{macrocode}
  2350. \def\tab@deepmagic#1{%
  2351. \csname NC@rewrite@\string#1\endcsname\NC@find\tab@@magic@@%
  2352. }
  2353. \def\NC@find#1\tab@@magic@@{}
  2354. % \end{macrocode}
  2355. %
  2356. % \end{macro}
  2357. %
  2358. %
  2359. % \subsection{Standard column types}
  2360. %
  2361. % First, make sure we're setting up the right columns. This also sets the
  2362. % default for the user. Other packages must not use the |\colset| command
  2363. % for defining columns -- they should use the stack operations defined above.
  2364. %
  2365. % \begin{macrocode}
  2366. \colset{tabular}
  2367. % \end{macrocode}
  2368. %
  2369. % Now do the simple alignment types. These are fairly simple. The
  2370. % mysterious kern in the \lit{l} type is to stop the |\col@sep| glue from
  2371. % vanishing due to the |\unskip| inserted by the standard |\tab@midtext| if
  2372. % the column contains no text. (Thanks for spotting this bug go to that
  2373. % nice Mr~Carlisle.)
  2374. %
  2375. % \begin{macrocode}
  2376. \coldef l{\tabcoltype{\kern\z@\tab@bgroup}{\tab@egroup\hfil}}
  2377. \coldef c{\tabcoltype{\hfil\tab@bgroup}{\tab@egroup\hfil}}
  2378. \coldef r{\tabcoltype{\hfil\tab@bgroup}{\tab@egroup}}
  2379. % \end{macrocode}
  2380. %
  2381. % Some extensions now. These are explicitly teextual or mathematical
  2382. % columns. Can be useful if you're providing column types for other people.
  2383. % I've inserted a kern here for exactly the same reason as for the \lit{l}
  2384. % column type above.
  2385. %
  2386. % \begin{macrocode}
  2387. \coldef T#1{\tab@aligncol{#1}{\tab@btext}{\tab@etext}}
  2388. \coldef M#1{\tab@aligncol{#1}{\tab@bmaths}{\tab@emaths}}
  2389. \def\tab@aligncol#1#2#3{%
  2390. \if#1l\tabcoltype{\kern\z@#2}{#3\hfil}\fi%
  2391. \if#1c\tabcoltype{\hfil#2}{#3\hfil}\fi%
  2392. \if#1r\tabcoltype{\hfil#2}{#3}\fi%
  2393. }
  2394. % \end{macrocode}
  2395. %
  2396. % Now for the default rules.
  2397. %
  2398. % \begin{macrocode}
  2399. \coldef |{\tabruletype{\vrule\@width\arrayrulewidth}}
  2400. \coldef !#1{\tabruletype{#1}}
  2401. % \end{macrocode}
  2402. %
  2403. % Deal with \lit{@} expressions.
  2404. %
  2405. % \begin{macrocode}
  2406. \coldef @#1{\tabspctype{#1}}
  2407. % \end{macrocode}
  2408. %
  2409. % And the paragraph types. I've added things to handle footnotes here.
  2410. %
  2411. % \begin{macrocode}
  2412. \coldef p#1{\tabcoltype%
  2413. {\savenotes\vtop\tab@bpar{#1}}%
  2414. {\tab@epar\spewnotes\hfil}}
  2415. \coldef m#1{\tabcoltype%
  2416. {\savenotes$\vcenter\tab@bpar{#1}}%
  2417. {\tab@epar$\spewnotes\hfil}}
  2418. \coldef b#1{\tabcoltype%
  2419. {\savenotes\vbox\tab@bpar{#1}}%
  2420. {\tab@epar\spewnotes\hfil}}
  2421. % \end{macrocode}
  2422. %
  2423. % Phew. Only a few more left now. The user text ones.
  2424. %
  2425. % \begin{macrocode}
  2426. \coldef >#1{\tabuserpretype{#1}}
  2427. \coldef <#1{\tabuserposttype{#1}}
  2428. % \end{macrocode}
  2429. %
  2430. % The strange column type.
  2431. %
  2432. % \begin{macrocode}
  2433. \coldef ##1#2{\tabcoltype{#1}{#2}}
  2434. % \end{macrocode}
  2435. %
  2436. % And \lit{*}, which repeats a preamble spec. This is really easy, and not
  2437. % at all like the original one.
  2438. %
  2439. % \begin{macrocode}
  2440. \coldef *#1#2{%
  2441. \count@#1%
  2442. \loop\ifnum\count@>0\relax%
  2443. \tab@doreadpream{#2}%
  2444. \advance\count@\m@ne%
  2445. \repeat%
  2446. }
  2447. % \end{macrocode}
  2448. %
  2449. %
  2450. % \subsection{Paragraph handling}
  2451. %
  2452. % First of all, starting new paragraphs: the vbox token is already there, and
  2453. % we have the width as an argument.
  2454. %
  2455. % \begin{macro}{\tab@bpar}
  2456. %
  2457. % There are some gymnastics to do here to support lists which form the
  2458. % complete text of the parbox. One of the odd things I'll do here is to
  2459. % not insert a strut on the first line: instead, I'll put the text into a
  2460. % box register so that I can inspect it later. So that I have access to
  2461. % the height of the first line, I'll use a |\vtop| -- I can get at the
  2462. % final depth by using |\prevdepth|, so this seems to be the most general
  2463. % solution.
  2464. %
  2465. % \begin{macrocode}
  2466. \def\tab@bpar#1{%
  2467. \bgroup%
  2468. \hsize#1\relax%
  2469. \@arrayparboxrestore%
  2470. \setbox\z@\vtop\bgroup
  2471. \global\@minipagetrue%
  2472. \everypar{%
  2473. \global\@minipagefalse%
  2474. \everypar{}%
  2475. }%
  2476. }
  2477. % \end{macrocode}
  2478. %
  2479. % \end{macro}
  2480. %
  2481. % \begin{macro}{\tab@epar}
  2482. %
  2483. % To end the paragraph, close the box. That sounds easy, doesn't it?
  2484. % I need to space out the top and bottom of the box so that it looks as if
  2485. % struts have been applied.
  2486. %
  2487. % \begin{macrocode}
  2488. \def\tab@epar{%
  2489. % \end{macrocode}
  2490. %
  2491. % Anyway, I should end the current paragraph if I'm still in horizontal
  2492. % mode. A simple |\par| will do this nicely. I'll also remove any trailing
  2493. % vertical glue (which may be left there by a list environment), because
  2494. % things will look very strange otherwise.
  2495. %
  2496. % \begin{macrocode}
  2497. \ifhmode\@maybe@unskip\par\fi%
  2498. \unskip%
  2499. % \end{macrocode}
  2500. %
  2501. % Now I'll look at the depth of the last box: if it's less deep than my
  2502. % special strut, I'll cunningly backpedal by a bit, and add a box with the
  2503. % appropriate depth. Since this will lie on the previous baseline, it won't
  2504. % alter the effective height of the box. There's a snag here. |\prevdepth|
  2505. % may be wrong for example if the last thing inserted was a rule, or the
  2506. % box is just empty. Check for this specially. (Thanks to Rowland for
  2507. % spotting this.)
  2508. %
  2509. % \begin{macrocode}
  2510. \ifdim\prevdepth>-\@m\p@\ifdim\prevdepth<\dp\@arstrutbox%
  2511. \kern-\prevdepth%
  2512. \nointerlineskip%
  2513. \vtop to\dp\@arstrutbox{}%
  2514. \fi\fi%
  2515. % \end{macrocode}
  2516. %
  2517. % I've finished the bottom of the box now: I'll close it, and start work on
  2518. % the top again.
  2519. %
  2520. % \begin{macrocode}
  2521. \egroup%
  2522. % \end{macrocode}
  2523. %
  2524. % For top-alignment to work, the first item in the box must be another box.
  2525. % (This is why I couldn't just set |\prevdepth| at the beginning.) If the
  2526. % box isn't high enough, I'll add a box of the right height and then kern
  2527. % backwards so that the `real' first box ends up in the right place.
  2528. %
  2529. % \begin{macrocode}
  2530. \ifdim\ht\z@<\ht\@arstrutbox%
  2531. \vbox to\ht\@arstrutbox{}%
  2532. \kern-\ht\z@%
  2533. \fi%
  2534. \unvbox\z@%
  2535. \egroup%
  2536. }
  2537. % \end{macrocode}
  2538. %
  2539. % \end{macro}
  2540. %
  2541. %
  2542. % \subsection{Gentle persuasion}
  2543. %
  2544. % To persuade \package{longtable} to work, we emulate some features of
  2545. % the \package{array} way of doing things. It's a shame, but we have to do
  2546. % it, because \package{longtable} came first.
  2547. %
  2548. % Note the horribleness with the grouping here. In order to get everything
  2549. % expanded at the right time, |\@preamble| just replaces itself with the (not
  2550. % expanded!) preamble string, using |\the|. This means that the preamble
  2551. % string must be visible in the group just above us. Now,
  2552. % \package{longtable} (and \package{array} for that matter) does
  2553. % |\@mkpreamble| immediately after opening a new group. So all we need to do
  2554. % is close that group, do our stuff, and reopen the group again. (Evil
  2555. % laughter\dots)
  2556. %
  2557. % \begin{macrocode}
  2558. \def\@mkpream#1{%
  2559. \endgroup%
  2560. \colset{tabular}%
  2561. \tab@initread%
  2562. \def\tab@multicol{\@arstrut}%
  2563. \tab@preamble{\tab@multicol}%
  2564. \def\tab@midtext{\ignorespaces\@sharp\@sharp\@maybe@unskip}%
  2565. \tab@readpreamble{#1}%
  2566. \gdef\@preamble{\the\tab@preamble}%
  2567. \let\tab@bgroup\begingroup%
  2568. \let\tab@egroup\endgroup%
  2569. \begingroup%
  2570. }
  2571. % \end{macrocode}
  2572. %
  2573. %
  2574. % \subsection{Debugging}
  2575. %
  2576. % This macro just parses a preamble and displays it on the terminal. It
  2577. % means I can see whether the thing's working.
  2578. %
  2579. % \begin{macrocode}
  2580. \def\showpream#1{%
  2581. \tab@initread%
  2582. \tab@readpreamble{#1}%
  2583. \showthe\tab@preamble%
  2584. \showthe\tab@shortline%
  2585. }
  2586. % \end{macrocode}
  2587. %
  2588. % A quick macro for showing column types.
  2589. %
  2590. % \begin{macrocode}
  2591. \def\showcol#1{%
  2592. \expandafter\show\csname\tab@colset!col.\string#1\endcsname%
  2593. }
  2594. % \end{macrocode}
  2595. %
  2596. %
  2597. % \subsection{The \env{tabular} and \env{array} environments}
  2598. %
  2599. % This is where we define the actual environments which users play with.
  2600. %
  2601. % \subsubsection{The environment routines}
  2602. %
  2603. % The real work is done in the |\@array| macro later. We just set up lots
  2604. % (and I mean \emph{lots}) of parameters first, and then call |\@array|.
  2605. %
  2606. % \begin{macro}{\tab@array}
  2607. %
  2608. % The |\tab@array| macro does most of the common array things.
  2609. %
  2610. % \begin{macrocode}
  2611. \def\tab@array{%
  2612. \tab@width\z@%
  2613. \let\tab@bgroup\tab@bmaths%
  2614. \let\tab@egroup\tab@emaths%
  2615. \@tabarray%
  2616. }
  2617. % \end{macrocode}
  2618. %
  2619. % \end{macro}
  2620. %
  2621. % \begin{macro}{\tab@btext}
  2622. % \begin{macro}{\tab@bmaths}
  2623. % \begin{macro}{\tab@etext}
  2624. % \begin{macro}{\tab@emaths}
  2625. %
  2626. % These macros contain appropriate things to use when typesetting
  2627. % text or maths macros. They're all trivial. They're here only for
  2628. % later modification by funny things like the \env{smarray} environment.
  2629. %
  2630. % \begin{macrocode}
  2631. \def\tab@btext{\begingroup}
  2632. \def\tab@bmaths{$}
  2633. \def\tab@etext{\endgroup}
  2634. \def\tab@emaths{\m@th$}
  2635. % \end{macrocode}
  2636. %
  2637. % \end{macro}
  2638. % \end{macro}
  2639. % \end{macro}
  2640. % \end{macro}
  2641. %
  2642. % \begin{environment}{array}
  2643. %
  2644. % Now for the \env{array} environment. The `|$|' signs act as a group, so we
  2645. % don't need to do extra grouping this time. Closing the environment is
  2646. % easy.
  2647. %
  2648. % \begin{macrocode}
  2649. \def\array{%
  2650. \col@sep\arraycolsep%
  2651. \let\tab@extrasep\arrayextrasep%
  2652. \tab@normalstrut%
  2653. \tab@array%
  2654. }
  2655. \def\endarray{%
  2656. \crcr%
  2657. \egroup%
  2658. \tab@right%
  2659. \tab@restorehlstate%
  2660. }
  2661. % \end{macrocode}
  2662. %
  2663. % \end{environment}
  2664. %
  2665. % \begin{environment}{smarray}
  2666. %
  2667. % Now for something a little different. The \env{smarray} environment
  2668. % gives you an array with lots of small text.
  2669. %
  2670. % \begin{macrocode}
  2671. \def\smarray{%
  2672. \extrarowheight\z@%
  2673. \col@sep\smarraycolsep%
  2674. \let\tab@extrasep\smarrayextrasep%
  2675. \def\tab@bmaths{$\scriptstyle}%
  2676. \def\tab@btext{\begingroup\scriptsize}%
  2677. \setbox\z@\hbox{\scriptsize\strut}%
  2678. \dimen@\ht\z@\dimen\tw@\dp\z@\tab@setstrut%
  2679. \tab@array%
  2680. }
  2681. \let\endsmarray\endarray
  2682. % \end{macrocode}
  2683. %
  2684. % \end{environment}
  2685. %
  2686. % \begin{macro}{\tabstyle}
  2687. %
  2688. % This is a little hook that document designers can use to modify the
  2689. % appearance of tables throughout a document. For example, I've set it to
  2690. % make the text size |\small| in all tables in this document. Macro writers
  2691. % shouldn't try to use it as a hook for their own evilness, though. I've
  2692. % used |\providecommand| to avoid nobbling an existing definition.
  2693. %
  2694. % \begin{macrocode}
  2695. \providecommand\tabstyle{}
  2696. % \end{macrocode}
  2697. %
  2698. % \end{macro}
  2699. %
  2700. % \begin{macro}{\@tabular}
  2701. %
  2702. % The two \env{tabular} environments share lots of common code, so we
  2703. % separate that out. (This needs to be done better.) All we really do here
  2704. % is set up the |\tab@bgroup| and |\tab@egroup| to localise things properly,
  2705. % and then go.
  2706. %
  2707. % \begin{macrocode}
  2708. \def\@tabular#1{%
  2709. \tabstyle%
  2710. \tab@width#1%
  2711. \let\tab@bgroup\tab@btext%
  2712. \let\tab@egroup\tab@etext%
  2713. \col@sep\tabcolsep%
  2714. \let\tab@extrasep\tabextrasep%
  2715. \tab@normalstrut%
  2716. \@tabarray%
  2717. }
  2718. % \end{macrocode}
  2719. %
  2720. % \end{macro}
  2721. %
  2722. % \begin{environment}{tabular}
  2723. % \begin{environment}{tabular*}
  2724. %
  2725. % These environments just call a macro which does all the common stuff.
  2726. %
  2727. % \begin{macrocode}
  2728. \def\tabular{\@tabular\z@}
  2729. \expandafter\let\csname tabular*\endcsname\@tabular
  2730. \let\endtabular\endarray
  2731. \expandafter\let\csname endtabular*\endcsname\endarray
  2732. % \end{macrocode}
  2733. %
  2734. % \end{environment}
  2735. % \end{environment}
  2736. %
  2737. % \subsubsection{Setting the strut height}
  2738. %
  2739. % \begin{macro}{\tab@setstrut}
  2740. %
  2741. % We use a magical strut, called |\@arstrut|, which keeps the table from
  2742. % collapsing around our heads. This is where we set it up.
  2743. %
  2744. % It bases the array strut size on the given values of |\dimen@| and
  2745. % |\dimen\tw@|, amended by various appropriate fiddle values added in by
  2746. % various people.
  2747. %
  2748. % \begin{macrocode}
  2749. \def\tab@setstrut{%
  2750. \setbox\@arstrutbox\hbox{%
  2751. \vrule%
  2752. \@height\arraystretch\dimen@%
  2753. \@depth\arraystretch\dimen\tw@%
  2754. \@width\z@%
  2755. }%
  2756. }
  2757. % \end{macrocode}
  2758. %
  2759. % \end{macro}
  2760. %
  2761. % \begin{macro}{\tab@normalstrut}
  2762. %
  2763. % This sets the strut the normal way, from the size of |\strutbox|.
  2764. %
  2765. % \begin{macrocode}
  2766. \def\tab@normalstrut{%
  2767. \dimen@\ht\strutbox\advance\dimen@\extrarowheight%
  2768. \dimen\tw@\dp\strutbox%
  2769. \tab@setstrut%
  2770. }
  2771. % \end{macrocode}
  2772. %
  2773. % \end{macro}
  2774. %
  2775. % \subsubsection{Setting up the alignment}
  2776. %
  2777. % The following bits are mainly for other packages to hook themselves onto.
  2778. %
  2779. % \begin{macrocode}
  2780. \let\@arrayleft\relax%
  2781. \let\@arrayright\relax%
  2782. % \end{macrocode}
  2783. %
  2784. % \begin{macrocode}
  2785. \def\@tabarray{%
  2786. \let\@arrayleft\relax%
  2787. \let\@arrayright\relax%
  2788. \@ifnextchar[\@array{\@array[c]}%
  2789. }
  2790. % \end{macrocode}
  2791. %
  2792. % \begin{macro}{\@array}
  2793. %
  2794. % The |\@array| macro does most of the real work for the environments. The
  2795. % first job is to set up the row strut, which keeps the table rows at the
  2796. % right height. We just take the normal strut box, and extend its height by
  2797. % the |\extrarowheight| length parameter.
  2798. %
  2799. % \begin{macrocode}
  2800. \def\@array[#1]#2{%
  2801. % \end{macrocode}
  2802. %
  2803. % Sort out the hline state variable. We'll store the old value in a
  2804. % control sequence to avoid wasting any more count registers.
  2805. %
  2806. % \begin{macrocode}
  2807. \edef\tab@restorehlstate{%
  2808. \global\tab@endheight\the\tab@endheight%
  2809. \gdef\noexpand\tab@hlstate{\tab@hlstate}%
  2810. }%
  2811. \def\tab@hlstate{n}%
  2812. % \end{macrocode}
  2813. %
  2814. % Now we read the preamble. All the clever things we've already done are
  2815. % terribly useful here.
  2816. %
  2817. % The |\tab@setcr| sets up |\\| to be a newline even if users have changed it
  2818. % using something like |\raggedright|.
  2819. %
  2820. % \begin{macrocode}
  2821. \colset{tabular}%
  2822. \tab@initread%
  2823. \def\tab@midtext{\tab@setcr\ignorespaces####\@maybe@unskip}%
  2824. \def\tab@multicol{\@arstrut\tab@startrow}%
  2825. \tab@preamble{\tab@multicol\tabskip\z@skip}%
  2826. \tab@readpreamble{#2}%
  2827. % \end{macrocode}
  2828. %
  2829. % Set up the default tabskip glue. This is easy: there isn't any.
  2830. %
  2831. % \begin{macrocode}
  2832. \tab@leftskip\z@skip%
  2833. \tab@rightskip\z@skip%
  2834. % \end{macrocode}
  2835. %
  2836. % Now set up the positioning of the table. This is put into a separate macro
  2837. % because it's rather complicated.
  2838. %
  2839. % \begin{macrocode}
  2840. \tab@setposn{#1}%
  2841. % \end{macrocode}
  2842. %
  2843. % Now work out how to start the alignment.
  2844. %
  2845. % \begin{macrocode}
  2846. \ifdim\tab@width=\z@%
  2847. \def\tab@halign{}%
  2848. \else%
  2849. \def\tab@halign{to\tab@width}%
  2850. \fi%
  2851. % \end{macrocode}
  2852. %
  2853. % Finally, do all the normal things we need to do before an alignment. Note
  2854. % that we define |\tabularnewline| first, then set |\\| from that (using
  2855. % |\tab@setcr|). Since |\\| is reset in the |\tab@midtext| of every table
  2856. % cell, it becomes secondary to |\tabularnewline|. Doing things this way
  2857. % avoids the problems with declarations like |\raggedright| which redefine
  2858. % |\\| in their own (usually rather strange) way, so you don't need to mess
  2859. % about with things like the |\PreserveBackslash| command given in the
  2860. % \textit{\LaTeX\ Companion}.
  2861. %
  2862. % \begin{macrocode}
  2863. \lineskip\z@\baselineskip\z@%
  2864. \m@th%
  2865. \def\tabularnewline{\tab@arraycr\tab@penalty}%
  2866. \tab@setcr%
  2867. \let\par\@empty%
  2868. \everycr{}\tabskip\tab@leftskip%
  2869. \tab@left\halign\tab@halign\expandafter\bgroup%
  2870. \the\tab@preamble\tabskip\tab@rightskip\cr%
  2871. }
  2872. % \end{macrocode}
  2873. %
  2874. % \end{macro}
  2875. %
  2876. % You've no doubt noticed the |\tab@left| and |\tab@right| macros above.
  2877. % These are set up here and elsewhere to allow other things to gain control
  2878. % at various points of the table (they include and take the place of the
  2879. % |\@arrayleft| and |\@arrayright| hooks in \package{array}, put in for
  2880. % \package{delarray}'s use.
  2881. %
  2882. % \subsubsection{Positioning the table}
  2883. %
  2884. % \begin{macro}{\tab@setposn}
  2885. %
  2886. % This macro sets everything up for the table's positioning. It's rather
  2887. % long, but not all that complicated. Honest.
  2888. %
  2889. % First, we set up some defaults (for centring). If anything goes wrong, we
  2890. % just do the centring things.
  2891. %
  2892. % \begin{macrocode}
  2893. \def\tab@setposn#1{%
  2894. \def\tab@left{%
  2895. \savenotes%
  2896. \leavevmode\hbox\bgroup$\@arrayleft\vcenter\bgroup%
  2897. }%
  2898. \def\tab@right{%
  2899. \egroup%
  2900. \m@th\@arrayright$\egroup%
  2901. \spewnotes%
  2902. }%
  2903. \global\tab@endheight\z@%
  2904. % \end{macrocode}
  2905. %
  2906. % For the standard positioning things, we just do appropriate boxing things.
  2907. % Note that the dollar signs are important, since \package{delarray} might
  2908. % want to put its delimiters in here.
  2909. %
  2910. % The |\if@tempswa| switch it used to decide if we're doing an unboxed
  2911. % tabular. We'll set it if we find an unbox-type position code, and then
  2912. % check that everything's OK for this.
  2913. %
  2914. % \begin{macrocode}
  2915. \@tempswafalse%
  2916. \let\tab@penalty\relax%
  2917. \if#1t%
  2918. \def\tab@left{%
  2919. \savenotes%
  2920. \leavevmode\setbox\z@\hbox\bgroup$\@arrayleft\vtop\bgroup%
  2921. }%
  2922. \def\tab@right{%
  2923. \egroup%
  2924. \m@th\@arrayright$\egroup%
  2925. \tab@raisebase%
  2926. \spewnotes%
  2927. }%
  2928. \gdef\tab@hlstate{t}%
  2929. \global\tab@endheight\ht\@arstrutbox%
  2930. \else\if#1b%
  2931. \def\tab@left{%
  2932. \savenotes%
  2933. \leavevmode\setbox\z@\hbox\bgroup$\@arrayleft\vbox\bgroup%
  2934. }%
  2935. \def\tab@right{%
  2936. \egroup%
  2937. \m@th\@arrayright$\egroup%
  2938. \tab@lowerbase%
  2939. \spewnotes%
  2940. }%
  2941. \gdef\tab@hlstate{b}%
  2942. \else%
  2943. \if#1L\@tempswatrue\fi%
  2944. \if#1C\@tempswatrue\fi%
  2945. \if#1R\@tempswatrue\fi%
  2946. \fi\fi%
  2947. % \end{macrocode}
  2948. %
  2949. % Now for some tests to make sure we're allowed to do the unboxing. We text
  2950. % for |\@arrayleft| being defined, because people trying to hook us won't
  2951. % understand unboxed tabulars.
  2952. %
  2953. % \begin{macrocode}
  2954. \if@tempswa\ifhmode%
  2955. \ifinner\tab@err@unbrh\@tempswafalse\else\par\fi%
  2956. \fi\fi%
  2957. \if@tempswa\ifmmode\tab@err@unbmm\@tempswafalse\fi\fi%
  2958. \if@tempswa\ifx\@arrayleft\relax\else%
  2959. \tab@err@unbext\@tempswafalse%
  2960. \fi\fi%
  2961. % \end{macrocode}
  2962. %
  2963. % Finally, if we're still doing an unboxed alignment, we need to sort out the
  2964. % spacing. We know that no-one's tried to hook on to the environment, so we
  2965. % clear |\tab@left| and |\tab@right|.
  2966. %
  2967. % \begin{macrocode}
  2968. \if@tempswa%
  2969. \def\tab@left{\vskip\parskip\medskip}%
  2970. \def\tab@right{\par\@endpetrue\global\@ignoretrue}%
  2971. % \end{macrocode}
  2972. %
  2973. % Now we need to sort out the alignment. The only way we can do this is by
  2974. % playing with tabskip glue. There are two possiblities:
  2975. %
  2976. % \begin{itemize}
  2977. %
  2978. % \item If this is a straight \env{tabular} or an \env{array}, we just use
  2979. % infinite glue. This is reasonable, I think.
  2980. %
  2981. % \item If we have a width for the table, we calculate the fixed values of
  2982. % glue on either side. This is fairly easy, and forces the table to
  2983. % the required width.
  2984. %
  2985. % \end{itemize}
  2986. %
  2987. % First, set up the left and right glues to represent the prevailing
  2988. % margins set up by \env{list} environments. I think this is the right
  2989. % thing to do.
  2990. %
  2991. % \begin{macrocode}
  2992. \tab@leftskip\@totalleftmargin%
  2993. \tab@rightskip\hsize%
  2994. \advance\tab@rightskip-\linewidth%
  2995. \advance\tab@rightskip-\@totalleftmargin%
  2996. % \end{macrocode}
  2997. %
  2998. % First of all, deal with the simple case. I'm using 10000\,fill glue here,
  2999. % in an attempt to suppress |\extracolsep| glue from making the table the
  3000. % wrong width. It can always use filll glue if it really needs to, though.
  3001. %
  3002. % \begin{macrocode}
  3003. \ifdim\tab@width=\z@%
  3004. \if#1L\else\advance\tab@leftskip\z@\@plus10000fill\fi%
  3005. \if#1R\else\advance\tab@rightskip\z@\@plus10000fill\fi%
  3006. % \end{macrocode}
  3007. %
  3008. % Now for the fun bit. This isn't too hard really. The extra space I must
  3009. % add around the table adds up to $|\linewidth| - |\tab@width|$. I just
  3010. % need to add this onto the appropriate sides of the table.
  3011. %
  3012. % \begin{macrocode}
  3013. \else%
  3014. \dimen@\linewidth%
  3015. \advance\dimen@-\tab@width%
  3016. \if#1L\advance\tab@rightskip\dimen@\fi%
  3017. \if#1R\advance\tab@leftskip\dimen@\fi%
  3018. \if#1C%
  3019. \advance\[email protected]\dimen@%
  3020. \advance\[email protected]\dimen@%
  3021. \fi%
  3022. \fi%
  3023. % \end{macrocode}
  3024. %
  3025. % Don't allow page breaks. David Carlisle's wonderful \env{longtable}
  3026. % package does page breaks far better than I could possibly do here, and
  3027. % we're compatible with it (wahey!).
  3028. %
  3029. % \begin{macrocode}
  3030. \def\tab@penalty{\penalty\@M}%
  3031. % \end{macrocode}
  3032. %
  3033. % Finally, set the new width of the table, and leave.
  3034. %
  3035. % \begin{macrocode}
  3036. \tab@width\hsize%
  3037. \fi%
  3038. }
  3039. % \end{macrocode}
  3040. %
  3041. % \end{macro}
  3042. %
  3043. % \subsubsection{Handling tops and bottoms}
  3044. %
  3045. % This is how the tops and bottoms of tables are made to line up with the
  3046. % text on the same line, in the presence of arbitrary rules and space. The
  3047. % old method, based on the way the \package{array} package worked, wasn't
  3048. % terribly good. This new version copes much better with almost anything
  3049. % that gets thrown at it.
  3050. %
  3051. % I'll keep a state in a macro (|\tab@hlstate|), which tells me what I'm
  3052. % meant to be doing. The possible values are \lit{n}, which means I don't
  3053. % have to do anything, \lit{t}, which means that I'm meant to be handling
  3054. % top-aligned tables, and \lit{b}, which means that I'm meant to be lining
  3055. % up the bottom. There are several other `substates' which have various
  3056. % magic meanings.
  3057. %
  3058. % \begin{macrocode}
  3059. \def\tab@hlstate{n}
  3060. % \end{macrocode}
  3061. %
  3062. % When all's said and done, I extract the box containing the table, and
  3063. % play with the height and depth to try and make it correct.
  3064. %
  3065. % \begin{macro}{\tab@addruleheight}
  3066. %
  3067. % This macro is called by `inter-row' things to add their height to our
  3068. % dimen register.
  3069. %
  3070. % Only do this if the state indicates that it's sensible.
  3071. %
  3072. % \begin{macrocode}
  3073. \def\tab@addruleheight#1{%
  3074. \if\tab@hlstate n\else%
  3075. \global\advance\tab@endheight#1\relax%
  3076. \fi%
  3077. }
  3078. % \end{macrocode}
  3079. %
  3080. % \end{macro}
  3081. %
  3082. % \begin{macro}{\tab@startrow}
  3083. %
  3084. % This is called at the start of a row, from within the array preamble.
  3085. % Currently, this assumes that the rows aren't bigger than their struts:
  3086. % this is reasonable, although slightly limiting, and it could be done better
  3087. % if I was willing to rip the alignment apart and put it back together
  3088. % again.
  3089. %
  3090. % \begin{macrocode}
  3091. \def\tab@startrow{%
  3092. \if\tab@hlstate t%
  3093. \gdef\tab@hlstate{n}%
  3094. \else\if\tab@hlstate b%
  3095. \global\tab@endheight\dp\@arstrutbox%
  3096. \fi\fi%
  3097. }
  3098. % \end{macrocode}
  3099. %
  3100. % \end{macro}
  3101. %
  3102. % \begin{macro}{\tab@raisebase}
  3103. %
  3104. % This macro is called at the end of it all, to set the height and depth
  3105. % of the box correctly. It sets the height to |\tab@endheight|, and the
  3106. % depth to everything else. The box is in |\box|~0 currently.
  3107. %
  3108. % \begin{macrocode}
  3109. \def\tab@raisebase{%
  3110. \global\advance\tab@endheight-\ht\z@%
  3111. \raise\tab@endheight\box\z@%
  3112. }
  3113. % \end{macrocode}
  3114. %
  3115. % \end{macro}
  3116. %
  3117. % \begin{macro}{\tab@lowerbase}
  3118. %
  3119. % And, for symmetry's sake, here's how to set the bottom properly instead.
  3120. %
  3121. % \begin{macrocode}
  3122. \def\tab@lowerbase{%
  3123. \global\advance\tab@endheight-\dp\z@%
  3124. \lower\tab@endheight\box\z@%
  3125. }
  3126. % \end{macrocode}
  3127. %
  3128. % \end{macro}
  3129. %
  3130. %
  3131. % \subsection{Breaking tables into bits}
  3132. %
  3133. % Unboxed tables have a wonderful advantage over boxed ones: you can stop
  3134. % halfway through and do something else for a bit. Here's how:
  3135. %
  3136. % \begin{macro}{\tabpause}
  3137. %
  3138. % I'd like to avoid forbidding catcode changes here. I'll use |\doafter|
  3139. % now I've got it, to ensure that colour handling and things occur
  3140. % \emph{inside} the |\noalign| (otherwise they'll mess up the alignment
  3141. % very seriously).
  3142. %
  3143. % We have to be careful here to ensure that everything works correctly within
  3144. % lists. (The \package{amsmath} package had this problem in its
  3145. % |\intertext| macro, so I'm not alone here.)
  3146. %
  3147. % \begin{macrocode}
  3148. \def\tabpause#{%
  3149. \noalign{\ifnum0=`}\fi%
  3150. \@parboxrestore%
  3151. \tab@startpause%
  3152. \vskip-\parskip%
  3153. \parshape\@ne\@totalleftmargin\linewidth%
  3154. \noindent%
  3155. \doafter\tabpause@i%
  3156. }
  3157. \def\tabpause@i{%
  3158. \nobreak%
  3159. \tab@endpause%
  3160. \ifnum0=`{\fi}%
  3161. }
  3162. % \end{macrocode}
  3163. %
  3164. % \end{macro}
  3165. %
  3166. %
  3167. % \subsection{The wonderful world of \cmd\multicolumn}
  3168. %
  3169. % \begin{macro}{\multicolumn}
  3170. %
  3171. % This is actually fantasitcally easy. Watch and learn. Make sure you
  3172. % notice the |\long|s here: remember that some table cells can contain
  3173. % paragraphs, so it seems sensible to allow |\par| into the argument.
  3174. % (As far as I know, most other |\multicolumn| commands don't do this,
  3175. % which seems a little silly. Then again, I forgot to do it the first
  3176. % time around.)
  3177. %
  3178. % \begin{macrocode}
  3179. \long\def\multicolumn#1#2#3{%
  3180. \multispan{#1}%
  3181. \begingroup%
  3182. \tab@multicol%
  3183. \tab@initread%
  3184. \tab@preamble{}%
  3185. \long\def\tab@midtext{#3}%
  3186. \let\tab@looped\tab@err@multi%
  3187. \tab@readpreamble{#2}%
  3188. \the\tab@preamble%
  3189. \endgroup%
  3190. \ignorespaces%
  3191. }
  3192. % \end{macrocode}
  3193. %
  3194. % \end{macro}
  3195. %
  3196. %
  3197. % \subsection{Interlude: range lists}
  3198. %
  3199. % For processing arguments to |\vgap| and |\cline|, we need to be able to
  3200. % do things with lists of column ranges. To save space, and to make my
  3201. % fingers do less typing, here's some routines which do range handling.
  3202. %
  3203. % \begin{macro}{\ranges}
  3204. %
  3205. % Given a macro name and a comma separated list of ranges and simple numbers,
  3206. % this macro will call the macro giving it each range in the list in turn.
  3207. % Single numbers~$n$ will be turned into ranges $n$--$n$.
  3208. %
  3209. % The first job is to read the macro to do (which may already have some
  3210. % arguments attached to it). We'll also start a group to make sure that
  3211. % our changes to temp registers don't affect anyone else.
  3212. %
  3213. % There's a space before the delimiting |\q@delim| to stop numbers being
  3214. % parsed to far and expanding our quark (which will stop \TeX\ dead in its
  3215. % tracks). Since we use |\@ifnextchar| to look ahead, spaces in range lists
  3216. % are perfectly all right.
  3217. %
  3218. % \begin{macrocode}
  3219. \def\ranges#1#2{%
  3220. \gdef\ranges@temp{#1}%
  3221. \begingroup%
  3222. \ranges@i#2 \q@delim%
  3223. }
  3224. % \end{macrocode}
  3225. %
  3226. %
  3227. % We're at the beginning of the list. We expect either the closing marker
  3228. % (if this is an empty list) or a number, which we can scoop up into a
  3229. % scratch register.
  3230. %
  3231. % \begin{macrocode}
  3232. \def\ranges@i{%
  3233. \@ifnextchar\q@delim\ranges@done{\afterassignment\ranges@ii\count@}%
  3234. }
  3235. % \end{macrocode}
  3236. %
  3237. % We've read the first number in the range. If there's another number, we'll
  3238. % expect a `|-|' sign to be next. If there is no `|-|', call the user's code
  3239. % with the number duplicated and then do the rest of the list.
  3240. %
  3241. % \begin{macrocode}
  3242. \def\ranges@ii{%
  3243. \@ifnextchar-\ranges@iii{\ranges@do\count@\count@\ranges@v}%
  3244. }
  3245. % \end{macrocode}
  3246. %
  3247. % Now we strip the `|-|' off and read the other number into a temporary
  3248. % register.
  3249. %
  3250. % \begin{macrocode}
  3251. \def\ranges@iii-{\afterassignment\ranges@iv\@tempcnta}
  3252. % \end{macrocode}
  3253. %
  3254. % We have both ends of the range now, so call the user's code, passing it
  3255. % both ends of the range.
  3256. %
  3257. % \begin{macrocode}
  3258. \def\ranges@iv{\ranges@do\count@\@tempcnta\ranges@v}
  3259. % \end{macrocode}
  3260. %
  3261. % We've finished doing an item now. If we have a `|,|' next, then start
  3262. % over with the next item. Otherwise, if we're at the end of the list,
  3263. % we can end happily. Finally, if we're totally confused, raise an
  3264. % error.
  3265. %
  3266. % \begin{macrocode}
  3267. \def\ranges@v{%
  3268. \@ifnextchar,%
  3269. \ranges@vi%
  3270. {%
  3271. \@ifnextchar\q@delim%
  3272. \ranges@done%
  3273. {\tab@err@range\ranges@vi,}%
  3274. }%
  3275. }
  3276. % \end{macrocode}
  3277. %
  3278. % We had a comma, so gobble it, read the next number, and go round again.
  3279. %
  3280. % \begin{macrocode}
  3281. \def\ranges@vi,{\afterassignment\ranges@ii\count@}
  3282. % \end{macrocode}
  3283. %
  3284. % Here's how we call the user's code, now. We close the group, so that the
  3285. % user's code doesn't have to do global things to remember its results, and
  3286. % we expand the two range ends from their count registers. We also ensure
  3287. % that the range is the right way round.
  3288. %
  3289. % \begin{macrocode}
  3290. \def\ranges@do#1#2{%
  3291. \ifnum#1>#2\else%
  3292. \expandafter\endgroup%
  3293. \expandafter\ranges@temp%
  3294. \expandafter{%
  3295. \the\expandafter#1%
  3296. \expandafter}%
  3297. \expandafter{%
  3298. \the#2%
  3299. }%
  3300. \begingroup%
  3301. \fi%
  3302. }
  3303. % \end{macrocode}
  3304. %
  3305. % And finishing the scan is really easy. We close the group after gobbling
  3306. % the close token.
  3307. %
  3308. % \begin{macrocode}
  3309. \def\ranges@done\q@delim{\endgroup}
  3310. % \end{macrocode}
  3311. %
  3312. % \end{macro}
  3313. %
  3314. % \begin{macro}{\ifinrange}
  3315. %
  3316. % Something a little more useful, now. |\ifinrange| takes four arguments:
  3317. % a number, a range list (as above), and two token lists which I'll call
  3318. % \emph{then} and \emph{else}. If the number is in the list, I'll do
  3319. % \emph{then}, otherwise I'll do \emph{else}.
  3320. %
  3321. % \begin{macrocode}
  3322. \def\ifinrange#1#2{%
  3323. \@tempswafalse%
  3324. \count@#1%
  3325. \ranges\ifinrange@i{#2}%
  3326. \if@tempswa%
  3327. \expandafter\@firstoftwo%
  3328. \else%
  3329. \expandafter\@secondoftwo%
  3330. \fi%
  3331. }
  3332. \def\ifinrange@i#1#2{%
  3333. \ifnum\count@<#1 \else\ifnum\count@>#2 \else\@tempswatrue\fi\fi%
  3334. }
  3335. % \end{macrocode}
  3336. %
  3337. % \end{macro}
  3338. %
  3339. %
  3340. % \subsection{Horizontal rules OK}
  3341. %
  3342. % This is where all the gubbins for |\vgap| and friends is kept, lest it
  3343. % contaminate fairly clean bits of code found elsewhere.
  3344. %
  3345. % \subsubsection{Drawing horizontal rules}
  3346. %
  3347. % \begin{macro}{\hline}
  3348. %
  3349. % Note the funny use of |\noalign| to allow \TeX\ stomach ops like
  3350. % |\futurelet| without starting a new table row. This lets us see if there's
  3351. % another |\hline| coming up, so we can see if we need to insert extra
  3352. % vertical space.
  3353. %
  3354. % \begin{macrocode}
  3355. \def\hline{%
  3356. \tab@dohline%
  3357. \noalign{\ifnum0=`}\fi%
  3358. \tab@penalty%
  3359. \futurelet\@let@token\hline@i%
  3360. }
  3361. % \end{macrocode}
  3362. %
  3363. % We check here for another |\hline| command, and insert glue if there is.
  3364. % This looks terrible, though, and |\hlx{hvh}| is much nicer. Still\dots
  3365. %
  3366. % \begin{macrocode}
  3367. \def\hline@i{%
  3368. \ifx\@let@token\hline%
  3369. \vskip\doublerulesep%
  3370. \tab@addruleheight\doublerulesep%
  3371. \fi%
  3372. \ifnum0=`{\fi}%
  3373. }
  3374. % \end{macrocode}
  3375. %
  3376. % \end{macro}
  3377. %
  3378. % \begin{macro}{\tab@dohline}
  3379. %
  3380. % This is where hlines actually get drawn.
  3381. % Drawing lines is more awkward than it used to be, particularly in unboxed
  3382. % tables. It used to be a case simply of saying |\noalign{\hrule}|.
  3383. % However, since unboxed tables are actually much wider than they look, this
  3384. % would make the rules stretch right across the page and look generally
  3385. % horrible.
  3386. %
  3387. % The solution is simple: we basically do a dirty big |\cline|.
  3388. %
  3389. % \begin{macrocode}
  3390. \def\tab@dohline{%
  3391. \multispan{\tab@columns}%
  3392. \leaders\hrule\@height\arrayrulewidth\hfil%
  3393. \tab@addruleheight\arrayrulewidth%
  3394. \cr%
  3395. }
  3396. % \end{macrocode}
  3397. %
  3398. % \end{macro}
  3399. %
  3400. % \subsubsection{Vertical rules}
  3401. %
  3402. % I couldn't fit these in anywhere else, so they'll have to go here. I'll
  3403. % provide a new optional argument which specifies the width of the rule; this
  3404. % gets rid of the problem described in the \emph{Companion}, where to get
  3405. % an unusually wide vertical rule, you have to play with things like
  3406. % \syntax{"\\vrule width" <dimen>} which really isn't too nice.
  3407. %
  3408. % \begin{macro}{\vline}
  3409. %
  3410. % The new |\vline| has an optional argument which gives the width of the
  3411. % rule. The |\relax| stops \TeX\ trying to parse a \<rule-specification> for
  3412. % too long, in case someone says something like `|\vline depthcharges|' or
  3413. % something equally unlikely.
  3414. %
  3415. % \begin{macrocode}
  3416. \renewcommand\vline[1][\arrayrulewidth]{\vrule\@width#1\relax}
  3417. % \end{macrocode}
  3418. %
  3419. % \end{macro}
  3420. %
  3421. % \subsubsection{Drawing bits of lines}
  3422. %
  3423. % Just for a bit of fun, here's an extended version of |\cline| which takes
  3424. % a list of columns to draw lines under, rather than just a single range.
  3425. %
  3426. % \begin{macro}{\cline}
  3427. %
  3428. % Not a single line of code written yet, and we already have a dilemma on
  3429. % our hands. Multiple consecutive |\cline| commands are meant to draw
  3430. % on the same vertical bit of table. But horizontal lines are meant to have
  3431. % thickness now. Oh, well [sigh], we'll skip back on it after all.
  3432. %
  3433. % Now the problem remains how best to do the job. The way I see it, there
  3434. % are three possibilities:
  3435. %
  3436. % \begin{itemize}
  3437. %
  3438. % \item We can start a table row, and then for each column of the table
  3439. % (as recorded in |\tab@columns|) we look to see if that column is
  3440. % listed in the range list and if so draw the rule. This requires
  3441. % lots of scanning of the range list.
  3442. %
  3443. % \item We can take each range in the list, and draw rules appropriately,
  3444. % just like the old |\cline| used to do, and starting a new table row
  3445. % for each.
  3446. %
  3447. % \item We can start a table row, and then for each range remember where we
  3448. % stopped drawing the last row, move to the start of the new one, and
  3449. % draw it. If we start moving backwards, we close the current row
  3450. % and open a new one.
  3451. %
  3452. % \end{itemize}
  3453. %
  3454. % The last option looks the most efficient, and the most difficult. This
  3455. % is therefore what I shall do |;-)|.
  3456. %
  3457. % The first thing to do is to add in a little negative space, and start a
  3458. % table row (omitting the first item). Then scan the range list, and finally
  3459. % close the table row and add some negative space again.
  3460. %
  3461. % We need a global count register to keep track of where we are. Mixing
  3462. % local and global assignments causes all sorts of tragedy, so I shall hijack
  3463. % |\tab@state|.
  3464. %
  3465. % \begin{macrocode}
  3466. \def\cline#1{%
  3467. \noalign{\kern-.5\arrayrulewidth\tab@penalty}%
  3468. \omit%
  3469. \global\tab@state\@ne%
  3470. \ranges\cline@i{#1}%
  3471. \cr%
  3472. \noalign{\kern-.5\arrayrulewidth\tab@penalty}%
  3473. }
  3474. % \end{macrocode}
  3475. %
  3476. % Now for the tricky bit. When we're given a range, we look to see if the
  3477. % first number is less than |\tab@state|. If so, we quickly close the
  3478. % current row, kern backwards and start again with an |\omit| and reset
  3479. % |\tab@state| to 1, and try again.
  3480. %
  3481. % \begin{macrocode}
  3482. \def\cline@i#1#2{%
  3483. \ifnum#1<\tab@state\relax%
  3484. \tab@@cr%
  3485. \noalign{\kern-\arrayrulewidth\tab@penalty}%
  3486. \omit%
  3487. \global\tab@state\@ne%
  3488. \fi%
  3489. % \end{macrocode}
  3490. %
  3491. % We are now either at or in front of the column position required. If
  3492. % we're too far back, we must |\hfil&\omit| our way over to the correct%
  3493. % column.
  3494. %
  3495. % \begin{macrocode}
  3496. \@whilenum\tab@state<#1\do{%
  3497. \hfil\tab@@tab@omit%
  3498. \global\advance\tab@state\@ne%
  3499. }%
  3500. % \end{macrocode}
  3501. %
  3502. % We've found the start correctly. We must deal with a tiny problem now:
  3503. % if this is not the first table cell, the left hand vertical rule is in the
  3504. % column to the left, so our horizontal rule won't match up properly. So
  3505. % we skip back by a bit to compensate. If there isn't actually a vertical
  3506. % rule to line up with, no-one will notice, because the rules are so thin.
  3507. % This adds a little touch of quality to the whole thing, which is after all
  3508. % the point of this whole exercise.
  3509. %
  3510. % \begin{macrocode}
  3511. \ifnum\tab@state>\@ne%
  3512. \kern-\arrayrulewidth%
  3513. \fi%
  3514. % \end{macrocode}
  3515. %
  3516. % Now we must stretch this table cell to the correct width.
  3517. %
  3518. % \begin{macrocode}
  3519. \@whilenum\tab@state<#2\do{%
  3520. \tab@@span@omit%
  3521. \global\advance\tab@state\@ne%
  3522. }%
  3523. % \end{macrocode}
  3524. %
  3525. % We're ready. Draw the rule. Note that this is |\hfill| glue, just in case
  3526. % we start putting in |\hfil| glue when we step onto the next cell.
  3527. %
  3528. % \begin{macrocode}
  3529. \leaders\hrule\@height\arrayrulewidth\hfill%
  3530. }
  3531. % \end{macrocode}
  3532. %
  3533. % Some alignment primitives are hidden inside macros so they don't get seen
  3534. % at the wrong time. This is what they look like:
  3535. %
  3536. % \begin{macrocode}
  3537. \def\tab@@cr{\cr}
  3538. \def\tab@@tab@omit{&\omit}
  3539. \def\tab@@span@omit{\span\omit}
  3540. % \end{macrocode}
  3541. %
  3542. % \end{macro}
  3543. %
  3544. % \subsubsection{Drawing short table rows}
  3545. %
  3546. % Before I start on a description of more code, I think I'll briefly discuss
  3547. % my reasons for leaving the |\vgap| command in its current state. There's a
  3548. % reasonable case for introducing an interface between |\vgap| and
  3549. % |\multicolumn|, to avoid all the tedious messing about with column
  3550. % ranges. There are good reasons why I'm not going to do this:
  3551. %
  3552. % \begin{itemize}
  3553. %
  3554. % \item It's very difficult to do: it requires either postprocessing of
  3555. % the table or delaying processing of each row until I know exactly
  3556. % what's in it; a |\multicolumn| in a row should be able to affect
  3557. % a |\vgap| before the row, which gets very nasty. This package is
  3558. % probably far too large already, and adding more complexity and
  3559. % running the risk of exhausting \TeX's frustratingly finite capacity
  3560. % for the sake of relieving the user of a fairly trivial job doesn't
  3561. % seem worthwhile.
  3562. %
  3563. % \item Perhaps more importantly, there are perfectly valid occasions when
  3564. % it's useful to have the current vgap behaviour. For example, the
  3565. % \texttt{MIX} word layout diagrams found in \emph{The Art of
  3566. % Computer Programming} use the little `stub lines' to show where
  3567. % data items cross byte boundaries:
  3568. %
  3569. % ^^A This actually looks terrifyingly similar to the original.
  3570. % ^^A The leading @{} is there to stop the table looking off-centre,
  3571. % ^^A because there's no left hand rule telling you where the table
  3572. % ^^A starts, like there is on the right, just the \tabcolsep glue.
  3573. %
  3574. % \begingroup
  3575. % \newcommand{\wide}[2]{\multicolumn{#1}{c|}{\ttfamily #2}}
  3576. % \begin{tabular}[C]{@{} r @{\qquad} | Mc | *{5}{c|}} \hlx{c{2-7} v}
  3577. % empty & - & 1 & 0 & 0 & 0 & 0 \\ \hlx{v c{2-7} v}
  3578. % occupied & + & \wide{2}{LINK} & \wide{3}{KEY} \\ \hlx{v c{2-7}}
  3579. % \end{tabular}
  3580. % \endgroup
  3581. %
  3582. % \end{itemize}
  3583. %
  3584. % That's my excuses out of the way; now I'll press on with the actual
  3585. % programming.
  3586. %
  3587. % \begin{macro}{\tab@checkrule}
  3588. %
  3589. % We have a range list in |\tab@xcols| and a number as an argument. If we
  3590. % find the number in the list, wejust space out the following group,
  3591. % otherwise we let it be.
  3592. %
  3593. % \begin{macrocode}
  3594. \def\tab@checkrule#1{%
  3595. \count@#1\relax%
  3596. \expandafter\ifinrange%
  3597. \expandafter\count@%
  3598. \expandafter{\tab@xcols}%
  3599. {\tab@checkrule@i}%
  3600. {}%
  3601. }
  3602. \def\tab@checkrule@i#1{\setbox\z@\hbox{#1}\hb@xt@\wd\z@{}}
  3603. % \end{macrocode}
  3604. %
  3605. % \end{macro}
  3606. %
  3607. % \begin{macro}{\vgap}
  3608. %
  3609. % We must tread carefully here. A single misplaced stomach operation can
  3610. % cause error messages. We therefore start with an |\omit| so we can search
  3611. % for optional arguments.
  3612. %
  3613. % So that |\hlx| can get control after |\vgap| has finished, we provide a
  3614. % hook called |\vgap@after| which is expanded after |\vgap| has finished.
  3615. % Here we make it work like |\@empty|, which expands to nothing. (Note that
  3616. % |\relax| will start a new table row, so we can't use that.) There are
  3617. % some penalty items here to stick the |\vgap| row to the text row and
  3618. % |\hline| that are adjacent to it. The \package{longtable} package will
  3619. % split an |\hline| in half, so this is the correct thing to do.
  3620. %
  3621. % \begin{macrocode}
  3622. \def\vgap{%
  3623. \noalign{\nobreak}%
  3624. \omit%
  3625. \global\let\vgap@after\@empty%
  3626. \iffalse{\fi\ifnum0=`}\fi%
  3627. \@ifnextchar[\vgap@i\vgap@simple%
  3628. }
  3629. % \end{macrocode}
  3630. %
  3631. % We set up two different sorts of |\vgap| -- a simple one which allows all
  3632. % rules to be passed through, and a specific one which carefully vets each
  3633. % one (and is therefore slower). We decide which to so based on the presence
  3634. % of an optional argument.
  3635. %
  3636. % The optional argument handler just passes its argument to an interface
  3637. % routine which is used by |\hlx|.
  3638. %
  3639. % \begin{macrocode}
  3640. \def\vgap@i[#1]{\vgap@spec{#1}}
  3641. % \end{macrocode}
  3642. %
  3643. % Now we handle specified columns. Since we're in an omitted table cell, we
  3644. % must set things up globally. Assign the column spec to a macro, and set up
  3645. % vetting by the routine above. Then just go and do the job.
  3646. %
  3647. % \begin{macrocode}
  3648. \def\vgap@spec#1#2{%
  3649. \gdef\tab@xcols{#1}%
  3650. \global\let\tab@ckr\tab@checkrule%
  3651. \vgap@do{#2}%
  3652. }
  3653. % \end{macrocode}
  3654. %
  3655. % Handle all columns. Just gobble the column number for each rule, and let
  3656. % the drawing pass unharmed. Easy.
  3657. %
  3658. % \begin{macrocode}
  3659. \def\vgap@simple#1{%
  3660. \global\let\tab@ckr\@gobble%
  3661. \vgap@do{#1}%
  3662. }
  3663. % \end{macrocode}
  3664. %
  3665. % This is where stuff actually gets done. We set the |\vgap| flag on while
  3666. % we do the short row. Then just expand the token list we built while
  3667. % scanning the preamble.
  3668. %
  3669. % Note that the flag is cleared at the end of the last column, to allow other
  3670. % funny things like |\noalign| and |\omit| before a new row is started.
  3671. %
  3672. % \begin{macrocode}
  3673. \def\vgap@do#1{%
  3674. \ifnum0=`{}\fi%
  3675. \global\tab@vgaptrue%
  3676. \the\tab@shortline%
  3677. \vrule\@height#1\@width\z@%
  3678. \global\tab@vgapfalse
  3679. \tab@addruleheight{#1}%
  3680. \cr%
  3681. \noalign{\nobreak}%
  3682. \vgap@after%
  3683. }
  3684. % \end{macrocode}
  3685. %
  3686. % \end{macro}
  3687. %
  3688. % \subsubsection{Prettifying syntax}
  3689. %
  3690. % \begin{macro}{\hlx}
  3691. %
  3692. % This is like a poor cousin to the preamble parser. The whole loop is
  3693. % carefully written to take place \emph{only} in \TeX's mouth, so the
  3694. % alignment handling bits half way down the gullet don't see any of this.
  3695. %
  3696. % First, pass the string to another routine.
  3697. %
  3698. % \begin{macrocode}
  3699. \def\hlx#1{\hlx@loop#1\q@delim}
  3700. % \end{macrocode}
  3701. %
  3702. % Now peel off a token, and dispatch using |\csname|. We handle
  3703. % undefinedness of the command in a fairly messy way, although it probably
  3704. % works. Maybe.
  3705. %
  3706. % \begin{macrocode}
  3707. \def\hlx@loop#1{%
  3708. \ifx#1\q@delim\else%
  3709. \@ifundefined{hlx@cmd@\string#1}{%
  3710. \expandafter\hlx@loop%
  3711. }{%
  3712. \csname hlx@cmd@\string#1\expandafter\endcsname%
  3713. }%
  3714. \fi%
  3715. }
  3716. % \end{macrocode}
  3717. %
  3718. % \end{macro}
  3719. %
  3720. % \begin{macro}{\hlxdef}
  3721. %
  3722. % New |\hlx| commands can be defined using |\hlxdef|. This is a simple
  3723. % abbreviation.
  3724. %
  3725. % \begin{macrocode}
  3726. \def\hlxdef#1{\@namedef{hlx@cmd@#1}}
  3727. % \end{macrocode}
  3728. %
  3729. % \end{macro}
  3730. %
  3731. % \begin{macro}{\hlx h}
  3732. %
  3733. % Handle an \lit{h} character. Just do an |\hline| and return to the loop.
  3734. % We look ahead to see if there's another \lit{h} coming up, and if so
  3735. % insert two |\hline| commands. This strange (and inefficient) behaviour
  3736. % keeps packages which redefine |\hline| happy.
  3737. %
  3738. % \begin{macrocode}
  3739. \hlxdef h#1{%
  3740. \noalign{%
  3741. \ifx#1h%
  3742. \def\@tempa{\hline\hline\hlx@loop}%
  3743. \else%
  3744. \def\@tempa{\hline\hlx@loop#1}%
  3745. \fi%
  3746. \expandafter
  3747. }%
  3748. \@tempa%
  3749. }
  3750. % \end{macrocode}
  3751. %
  3752. % \end{macro}
  3753. %
  3754. % \begin{macro}{\hlx b}
  3755. %
  3756. % The \lit{b} character does a nifty backspace, for \package{longtable}'s
  3757. % benefit.
  3758. %
  3759. % \begin{macrocode}
  3760. \hlxdef b{\noalign{\kern-\arrayrulewidth}\hlx@loop}
  3761. % \end{macrocode}
  3762. %
  3763. % \end{macro}
  3764. %
  3765. % \begin{macro}{\hlx /}
  3766. %
  3767. % The `"/"' character allows a page break at the current position.
  3768. %
  3769. % \begin{macrocode}
  3770. \hlxdef /{%
  3771. \noalign{\ifnum0=`}\fi%
  3772. \@ifnextchar[\hlx@cmd@break@i{\hlx@cmd@break@i[0]}%
  3773. }
  3774. \def\hlx@cmd@break@i[#1]{\ifnum0=`{\fi}\pagebreak[0]\hlx@loop}
  3775. % \end{macrocode}
  3776. %
  3777. % \end{macro}
  3778. %
  3779. % \begin{macro}{\hlx v}
  3780. %
  3781. % Handle a \lit{v} character. This is rather like the |\vgap| code above,
  3782. % although there are syntactic differences.
  3783. %
  3784. % \begin{macrocode}
  3785. \hlxdef v{%
  3786. \noalign{\nobreak}%
  3787. \omit%
  3788. \iffalse{\fi\ifnum0=`}\fi%
  3789. \global\let\vgap@after\hlx@loop%
  3790. \@ifnextchar[\hlx@vgap@i{\hlx@vgap@ii\vgap@simple}%
  3791. }
  3792. \def\hlx@vgap@i[#1]{%
  3793. \ifx!#1!%
  3794. \def\@tempa{\hlx@vgap@ii\vgap@simple}%
  3795. \else%
  3796. \def\@tempa{\hlx@vgap@ii{\vgap@spec{#1}}}%
  3797. \fi%
  3798. \@tempa%
  3799. }
  3800. \def\hlx@vgap@ii#1{%
  3801. \@ifnextchar[{\hlx@vgap@iii{#1}}{\hlx@vgap@iii{#1}[\doublerulesep]}%
  3802. }
  3803. \def\hlx@vgap@iii#1[#2]{#1{#2}}
  3804. % \end{macrocode}
  3805. %
  3806. % \end{macro}
  3807. %
  3808. % \begin{macro}{\hlx s}
  3809. %
  3810. % Allow the user to leave a small gap using the \lit{s} command.
  3811. %
  3812. % \begin{macrocode}
  3813. \hlxdef s{%
  3814. \noalign{\ifnum0=`}\fi%
  3815. \nobreak%
  3816. \@ifnextchar[\hlx@space@i{\hlx@space@i[\doublerulesep]}%
  3817. }
  3818. \def\hlx@space@i[#1]{%
  3819. \vskip#1%
  3820. \tab@addruleheight{#1}%
  3821. \ifnum0=`{\fi}%
  3822. \hlx@loop%
  3823. }
  3824. % \end{macrocode}
  3825. %
  3826. % \end{macro}
  3827. %
  3828. % \begin{macro}{\hlx c}
  3829. %
  3830. % We might as well allow a \lit{c} command to do a |\cline|.
  3831. %
  3832. % \begin{macrocode}
  3833. \hlxdef c#1{\cline{#1}\hlx@loop}
  3834. % \end{macrocode}
  3835. %
  3836. % \end{macro}
  3837. %
  3838. % \begin{macro}{\hlx .}
  3839. %
  3840. % The \lit{.} character forces a start of the new column. There's a little
  3841. % problem here. Since the \lit{.} character starts the next column, we need
  3842. % to gobble any spaces following the |\hlx| command before the cell contents
  3843. % actually starts. Unfortunately, |\ignorespaces| will start the column for
  3844. % us, so we can't put it in always. We'll handle it here, then. We'll take
  3845. % the rest of the `preamble' string, and warn if it's not empty. Then we'll
  3846. % |\ignorespaces| -- this will start the column for us, so we don't need to
  3847. % |\relax| any more.
  3848. %
  3849. % \begin{macrocode}
  3850. \hlxdef .#1\q@delim{%
  3851. \ifx @#1@\else%
  3852. \PackageWarning{mdwtab}{%
  3853. Ignoring \protect\hlx\space command characters following a
  3854. `.'\MessageBreak command%
  3855. }%
  3856. \fi%
  3857. \ignorespaces%
  3858. }
  3859. % \end{macrocode}
  3860. %
  3861. % \end{macro}
  3862. %
  3863. %
  3864. % \subsection{Starting new table rows}
  3865. %
  3866. % We take a break from careful mouthery at last, and start playing with
  3867. % newlines. The standard one allows pagebreaks in unboxed tables, which
  3868. % isn't really too desirable.
  3869. %
  3870. % Anyway, we'll try to make this macro rather more reusable than the standard
  3871. % one. Here goes.
  3872. %
  3873. % \begin{macro}{\@arraycr}
  3874. %
  3875. % We pass lots of information to a main parser macro, and expect it to cope.
  3876. %
  3877. % \begin{macrocode}
  3878. \def\@arraycr{\tab@arraycr{}}
  3879. \def\tab@arraycr#1{\tab@cr{\tab@tabcr{#1}}{}{}}
  3880. % \end{macrocode}
  3881. %
  3882. % Now to actually do the work. |\tab@cr| passes us the skip size, and the
  3883. % appropriate one of the two arguments given above (both of which are empty)
  3884. % depending on the presence of the $*$.
  3885. %
  3886. % \begin{macrocode}
  3887. \def\tab@tabcr#1#2{%
  3888. % \end{macrocode}
  3889. %
  3890. % If the total height I need to add between rows (from the optional argument
  3891. % and the `extrasep' parameter) is greater than zero, I'll handle this by
  3892. % extending the strut slightly. I'm not actually sure whether this is the
  3893. % right thing to do, to be honest, although it's easier than trying to
  3894. % to an automatic |\vgap|, because I need to know which columns to skip.
  3895. % If the space is less than zero, I'll just insert the vertical space with
  3896. % in a |\noalign|.
  3897. %
  3898. % First, to calculate how much space needs adding.
  3899. %
  3900. % \begin{macrocode}
  3901. \dimen@#2%
  3902. \advance\dimen@\tab@extrasep%
  3903. % \end{macrocode}
  3904. %
  3905. % If the height is greater than zero, I need to play with the strut. I must
  3906. % bear in mind that the current table cell (which I'm still in, remember)
  3907. % may be in vertical mode, and I may or may not be in a paragraph.
  3908. %
  3909. % If I am in vertical mode, I'll backpedal to the previous box and put the
  3910. % strut in an hbox superimposed on the previous baseline. Otherwise, I can
  3911. % just put the strut at the end of the text. (This works in either LR
  3912. % or paragraph mode as long as I'm not between paragraphs.) Again, Rowland's
  3913. % empty cell bug strikes. (See |\tab@epar| for details.)
  3914. %
  3915. % \begin{macrocode}
  3916. \ifdim\dimen@>\z@%
  3917. \ifvmode%
  3918. \unskip\ifdim\prevdepth>-\@m\p@\kern-\prevdepth\fi%
  3919. \nointerlineskip\expandafter\hbox%
  3920. \else%
  3921. \@maybe@unskip\expandafter\@firstofone%
  3922. \fi%
  3923. {\advance\dimen@\dp\@arstrutbox\vrule\@depth\dimen@\@width\z@}%
  3924. \fi%
  3925. % \end{macrocode}
  3926. %
  3927. % This table cell works as a group (which is annoying here). I'll copy the
  3928. % interrow gap into a global register so that I can use it in the |\noalign|.
  3929. %
  3930. % \begin{macrocode}
  3931. \global\dimen\@ne\dimen@%
  3932. \cr%
  3933. \noalign{%
  3934. #1%
  3935. \ifdim\dimen\@ne<\z@\vskip\dimen\@ne\relax\fi%
  3936. }%
  3937. \@gobble%
  3938. }
  3939. % \end{macrocode}
  3940. %
  3941. % \end{macro}
  3942. %
  3943. % \begin{macro}{\tab@setcr}
  3944. %
  3945. % To set the |\\| command correctly in each table cell, we make it a part of
  3946. % the preamble (in |\tab@midtext|) to call this routine. It's easy -- just
  3947. % saves the preamble from being huge.
  3948. %
  3949. % \begin{macrocode}
  3950. \def\tab@setcr{\let\\\tabularnewline}
  3951. % \end{macrocode}
  3952. %
  3953. % \end{macro}
  3954. %
  3955. % \begin{macro}{\tab@cr}
  3956. %
  3957. % Now we do the parsing work. This is fun. Note the revenge of the funny
  3958. % braces here. Nothing to worry about, honest. The tricky bit is to keep
  3959. % track of which arguments are which. (Thanks to David Carlisle for pointing
  3960. % out that I'd missed out the |\relax| here.)
  3961. %
  3962. % \begin{macrocode}
  3963. \def\tab@cr#1#2#3{%
  3964. \relax%
  3965. \iffalse{\fi\ifnum0=`}\fi%
  3966. \@ifstar{\tab@cr@i{#1}{#3}}{\tab@cr@i{#1}{#2}}%
  3967. }
  3968. \def\tab@cr@i#1#2{%
  3969. \@ifnextchar[{\tab@cr@ii{#1}{#2}}{\tab@cr@ii{#1}{#2}[\z@]}%
  3970. }
  3971. \def\tab@cr@ii#1#2[#3]{%
  3972. \ifnum0=`{}\fi%
  3973. #1{#3}{#2}%
  3974. }
  3975. % \end{macrocode}
  3976. %
  3977. % \end{macro}
  3978. %
  3979. %
  3980. % \subsection{Gratuitous grotesquery}
  3981. %
  3982. % So far we've had an easy-ish ride (or should that be \emph{queasy}?). Now
  3983. % for something unexplainably evil. We convince \LaTeX\ that it's loaded the
  3984. % \package{array} package, so that packages which need it think they've got
  3985. % it.
  3986. %
  3987. % The bogus date is the same as the date for the \package{array} package I've
  3988. % got here -- this will raise a warning if Frank updates his package which
  3989. % should filter back to me telling me that there's something I need to
  3990. % know about.
  3991. %
  3992. % The messing with |\xdef| and the funny parsing ought to insert the current
  3993. % \package{mdwtab} version and date into the fake \package{array} version
  3994. % string, giving a visible clue to the user that this isn't the real
  3995. % \package{array} package.
  3996. %
  3997. % \begin{macrocode}
  3998. \begingroup
  3999. \catcode`.=11
  4000. \def\@tempa#1 #2 #3\@@{#1 #2}
  4001. \xdef\[email protected]
  4002. {1995/11/19 [mdwtab.sty \expandafter\@tempa\[email protected]\@@]}
  4003. \endgroup
  4004. % \end{macrocode}
  4005. %
  4006. %
  4007. % \subsection{Error messages}
  4008. %
  4009. % I've put all the error messages together, where I can find them, translate
  4010. % them or whatever.
  4011. %
  4012. % First, some token-space saving (which also saves my fingers):
  4013. %
  4014. % \begin{macrocode}
  4015. \def\tab@error{\PackageError{mdwtab}}
  4016. % \end{macrocode}
  4017. %
  4018. % Now do the error messages.
  4019. %
  4020. % \begin{macrocode}
  4021. \def\tab@err@misscol{%
  4022. \tab@error{Missing column type}{%
  4023. I'm lost. I was expecting something describing^^J%
  4024. the type of the current column, but you seem to^^J%
  4025. have missed it out. I've inserted a type `l'^^J%
  4026. column here in the hope that this makes sense.%
  4027. }%
  4028. }
  4029. % \end{macrocode}
  4030. %
  4031. % \begin{macrocode}
  4032. \def\tab@err@oddgroup{%
  4033. \tab@error{Misplaced group in table preamble}{%
  4034. I've found an open brace character in your preamble^^J%
  4035. when I was expecting a specifier character. I'm^^J%
  4036. going to gobble the whole group and carry on as if^^J%
  4037. I'd never seen it.%
  4038. }%
  4039. }
  4040. % \end{macrocode}
  4041. %
  4042. % \begin{macrocode}
  4043. \def\tab@err@undef#1{%
  4044. \tab@error{Unknown `\tab@colset' preamble character `\string#1'}{%
  4045. I don't understand what you meant by typing this^^J%
  4046. character. Anyway, I'll ignore it this time around.^^J%
  4047. Just don't you do it again.%
  4048. }%
  4049. }
  4050. % \end{macrocode}
  4051. %
  4052. % \begin{macrocode}
  4053. \def\tab@err@unbrh{%
  4054. \tab@error{Can't use unboxed tabular in LR mode}{%
  4055. You've asked for a tabular or array environment with^^J%
  4056. `L', `C' or `R' as the position specifier, but you're^^J%
  4057. in LR (restricted horizontal) mode, so it won't work.^^J%
  4058. I'll assume you really meant `c' and soldier on.%
  4059. }%
  4060. }
  4061. % \end{macrocode}
  4062. %
  4063. % \begin{macrocode}
  4064. \def\tab@err@unbmm{%
  4065. \tab@error{Can't use unboxed tabular in maths mode}{%
  4066. You've asked for a tabular or array environment with^^J%
  4067. `L', `C' or `R' as the position specifier, but you're^^J%
  4068. in maths mode, so it won't work. I'll pretend that^^J%
  4069. you really typed `c', and that this is all a bad dream.%
  4070. }%
  4071. }
  4072. % \end{macrocode}
  4073. %
  4074. % \begin{macrocode}
  4075. \def\tab@err@unbext{%
  4076. \tab@error{Can't extend unboxed tabulars}{%
  4077. You're trying to use kludgy extensions (e.g.,^^J%
  4078. `delarray') on an array or tabular with `L', `C'^^J%
  4079. or `R' as the position specifier. I'll assume you^^J%
  4080. subconsciously wanted a `c' type all along.%
  4081. }%
  4082. }
  4083. % \end{macrocode}
  4084. %
  4085. % \begin{macrocode}
  4086. \def\tab@err@multi{%
  4087. \tab@error{More than one column in a \protect\multicolumn}{%
  4088. You've put more than one column into a \string\multicolumn^^J%
  4089. descriptor. It won't work. I have no idea what^^J%
  4090. will happen, although it won't be pleasant. Hold^^J%
  4091. on tight now...%
  4092. }%
  4093. }
  4094. % \end{macrocode}
  4095. %
  4096. % \begin{macrocode}
  4097. \def\tab@err@range{%
  4098. \tab@error{Expected `,' or `<end>' in range list}{%
  4099. I was expecting either the end of the range list,^^J%
  4100. or a comma, followed by another range. I've^^J%
  4101. inserted a comma to try and get me back on track.^^J%
  4102. Good luck.%
  4103. }%
  4104. }
  4105. % \end{macrocode}
  4106. %
  4107. % That's it. No more. Move along please.
  4108. %
  4109. % \begin{macrocode}
  4110. %</mdwtab>
  4111. % \end{macrocode}
  4112. %
  4113. %
  4114. %^^A-------------------------------------------------------------------------
  4115. % \section{Implementation of \package{mathenv}}
  4116. %
  4117. %
  4118. % This is in a separate package, mainly to avoid wasting people's memory.
  4119. %
  4120. % \begin{macrocode}
  4121. %<*mathenv>
  4122. % \end{macrocode}
  4123. %
  4124. %
  4125. % \subsection{Options handling}
  4126. %
  4127. % We need to be able to cope with \textsf{fleqn} and \textsf{leqno} options.
  4128. % This will adjust our magic modified \env{eqnarray} environment
  4129. % appropriately.
  4130. %
  4131. % \begin{macrocode}
  4132. \newif\if@fleqn
  4133. \newif\if@leqno
  4134. \DeclareOption{fleqn}{\@fleqntrue}
  4135. \DeclareOption{leqno}{\@leqnotrue}
  4136. \ProcessOptions
  4137. % \end{macrocode}
  4138. %
  4139. % We use the \package{mdwtab} package for all its nice table handling things.
  4140. % (Oh, and to inflict it on users who want to do nice equations and don't
  4141. % care about our tables.)
  4142. %
  4143. % \begin{macrocode}
  4144. \RequirePackage{mdwtab}
  4145. % \end{macrocode}
  4146. %
  4147. %
  4148. % \subsection{Some useful registers}
  4149. %
  4150. % The old \LaTeX\ version puts the equation numbers in by keeping a count of
  4151. % where it is in the alignment. Since I don't know how may columns there are
  4152. % going to be, I'll just use a switch in the preamble to tell me to stop
  4153. % tabbing.
  4154. %
  4155. % \begin{macrocode}
  4156. \newif\if@eqalast
  4157. % \end{macrocode}
  4158. %
  4159. % Now define some useful length parameters. First allocate them:
  4160. %
  4161. % \begin{macrocode}
  4162. \newskip\eqaopenskip
  4163. \newskip\eqacloseskip
  4164. \newskip\eqacolskip
  4165. \newskip\eqainskip
  4166. \newskip\splitleft
  4167. \newskip\splitright
  4168. % \end{macrocode}
  4169. %
  4170. % Now assign some default values. Users can play with these if they really
  4171. % want although I can't see the point myself.
  4172. %
  4173. % \begin{macrocode}
  4174. \AtBeginDocument{%
  4175. \eqacloseskip\@centering%
  4176. \eqacolskip1.5em\@plus\@m\p@
  4177. \eqainskip\z@%
  4178. \if@fleqn%
  4179. \eqaopenskip\mathindent%
  4180. \splitleft\mathindent\relax%
  4181. \splitright\mathindent\@minus\mathindent\relax%
  4182. \else%
  4183. \eqaopenskip\@centering%
  4184. \splitleft2.5em\@minus2.5em%
  4185. \splitright\splitleft%
  4186. \fi%
  4187. \relax%
  4188. }
  4189. % \end{macrocode}
  4190. %
  4191. %
  4192. % \subsection{A little display handling}
  4193. %
  4194. % I'm probably going a little far here, and invading territory already
  4195. % claimed by the \package{amsmath} stuff (and done a good deal better than
  4196. % I can be bothered to do), but just for completeness, this is how we handle
  4197. % attempts to put displays inside other displays without screwing up the
  4198. % spacing.
  4199. %
  4200. % \begin{macro}{\dsp@startouter}
  4201. %
  4202. % This is how we start an outermost display. It's fairly easy really. We
  4203. % make |\dsp@start| start an inner display, and make |\dsp@end| close the
  4204. % outer display.
  4205. %
  4206. % \begin{macrocode}
  4207. \def\dsp@startouter{%
  4208. \let\dsp@end\dsp@endouter%
  4209. $$%
  4210. }
  4211. % \end{macrocode}
  4212. %
  4213. % \end{macro}
  4214. %
  4215. % \begin{macro}{\dsp@endouter}
  4216. %
  4217. % Ending the outer display is utterly trivial.
  4218. %
  4219. % \begin{macrocode}
  4220. \def\dsp@endouter{$$}
  4221. % \end{macrocode}
  4222. %
  4223. % \end{macro}
  4224. %
  4225. % \begin{macro}{\dsp@startinner}
  4226. %
  4227. % Starting inner displays is done in a vbox (actually I choose |\vbox| or
  4228. % |\vtop| depending on the setting of \textsf{leqno} to put the equation
  4229. % number the right way round).
  4230. %
  4231. % \begin{macrocode}
  4232. \def\dsp@startinner{%
  4233. \let\dsp@end\dsp@endinner%
  4234. \if@fleqn\kern-\mathindent\fi%
  4235. \if@leqno\vtop\else\vtop\fi\bgroup%
  4236. }
  4237. % \end{macrocode}
  4238. %
  4239. % \end{macro}
  4240. %
  4241. % \begin{macro}{\dsp@endinner}
  4242. %
  4243. % Ending an inner display is also really easy.
  4244. %
  4245. % \begin{macrocode}
  4246. \def\dsp@endinner{\egroup}
  4247. % \end{macrocode}
  4248. %
  4249. % \end{macro}
  4250. %
  4251. % \begin{macro}{\dsp@start}
  4252. %
  4253. % This is what other bits of code uses to start displays. It's one of the
  4254. % start macros up above, and outer by default.
  4255. %
  4256. % \begin{macrocode}
  4257. \def\dsp@start{%
  4258. \ifmmode%
  4259. \ifinner\mth@err@mdsp\fi%
  4260. \expandafter\dsp@startinner%
  4261. \else%
  4262. \ifhmode\ifinner\mth@err@hdsp\fi\fi%
  4263. \expandafter\dsp@startouter%
  4264. \fi%
  4265. }
  4266. % \end{macrocode}
  4267. %
  4268. % \end{macro}
  4269. %
  4270. % \begin{macro}{\dsp@tabpause}
  4271. %
  4272. % This sets up the correct pre- and postambles for the |\tabpause| macro in
  4273. % maths displays. This is fairly simple stuff.
  4274. %
  4275. % \begin{macrocode}
  4276. \def\dsp@tabpause{%
  4277. \def\tab@startpause%
  4278. {\penalty\postdisplaypenalty\vskip\belowdisplayskip}%
  4279. \def\tab@endpause%
  4280. {\penalty\predisplaypenalty\vskip\abovedisplayskip}%
  4281. }
  4282. % \end{macrocode}
  4283. %
  4284. % \end{macro}
  4285. %
  4286. %
  4287. % \subsection{The \env{eqnarray} environment}
  4288. %
  4289. % We allow the user to play with the style if this is really wanted. I dunno
  4290. % why, really. Maybe someone wants very small alignments.
  4291. %
  4292. % \begin{macrocode}
  4293. \let\eqastyle\displaystyle
  4294. % \end{macrocode}
  4295. %
  4296. % \subsubsection{The main environments}
  4297. %
  4298. % \begin{environment}{eqnarray}
  4299. % \begin{environment}{eqnarray*}
  4300. %
  4301. % We define the toplevel commands here. They just add in default arguments
  4302. % and then call |\@eqnarray| with a preamble string. We handle equation
  4303. % numbers by setting up a default (|\eqa@defnumber|) which is put into
  4304. % the final column. At the beginning of each row, we globally |\let|
  4305. % |\eqa@number| equal to |\eqa@defnumber|. The |\eqnumber| macro just
  4306. % changes |\eqa@number| as required. Since |\eqa@number| is changed globally
  4307. % we must save it in this environment.
  4308. %
  4309. % First, we must sort out the optional arguments and things. This is really
  4310. % easy. The only difference between the starred and non-starred environments
  4311. % is the default definition of |\eqa@defnumber|.
  4312. %
  4313. % \begin{macrocode}
  4314. \def\eqnarray{%
  4315. \eqnarray@i\eqa@eqcount%
  4316. }
  4317. \@namedef{eqnarray*}{\eqnarray@i{}}
  4318. \def\eqnarray@i#1{\@ifnextchar[{\eqnarray@ii{#1}}{\eqnarray@ii{#1}[rcl]}}
  4319. % \end{macrocode}
  4320. %
  4321. % Right. Now for the real work. The first argument is the default numbering
  4322. % tokens; the second is the preamble string.
  4323. %
  4324. % \begin{macrocode}
  4325. \def\eqnarray@ii#1[#2]{%
  4326. % \end{macrocode}
  4327. %
  4328. % Set up the equation counter and labels correctly.
  4329. %
  4330. % \medskip\par\noindent|\begin{rant}|\par
  4331. % The hacking with |\@currentlabel| is here because (in the author's opinion)
  4332. % \LaTeX's |\refstepcounter| macro is broken. It's currently defined as
  4333. % \begin{listing}
  4334. %\def\refstepcounter#1{%
  4335. % \stepcounter{#1}%
  4336. % \protected@edef\@currentlabel%
  4337. % {\csname p@#1\endcsname\csname the#1\endcsname}%
  4338. %}
  4339. % \end{listing}
  4340. % which means that the current label gets `frozen' as soon as you do the
  4341. % counter step. By redefining the macro as
  4342. % \begin{listing}
  4343. %\def\refstepcounter#1{%
  4344. % \stepcounter{#1}%
  4345. % \edef\@currentlabel{%
  4346. % \expandafter\noexpand\csname p@#1\endcsname%
  4347. % \expandafter\noexpand\csname the#1\endcsname%
  4348. % }%
  4349. %}
  4350. % \end{listing}
  4351. % these sorts of problems would be avoided, without any loss of functionality
  4352. % or compatibility that I can see.
  4353. % \par\noindent|\end{rant}|\par
  4354. %
  4355. % \begin{macrocode}
  4356. \stepcounter{equation}%
  4357. \def\@currentlabel{\p@equation\theequation}%
  4358. % \end{macrocode}
  4359. %
  4360. % The next step is to set up the numbering. I must save the old numbering
  4361. % so I can restore it later (once in the alignment, I must assign these
  4362. % things globally).
  4363. %
  4364. % \begin{macrocode}
  4365. \let\eqa@oldnumber\eqa@number%
  4366. \def\eqa@defnumber{#1}%
  4367. \global\let\eqa@number\eqa@defnumber%
  4368. % \end{macrocode}
  4369. %
  4370. % The |\if@eqalastfalse| switch is false everywhere except when we're in the
  4371. % final column.
  4372. %
  4373. % \begin{macrocode}
  4374. \@eqalastfalse%
  4375. % \end{macrocode}
  4376. %
  4377. % Remove the |\mathsurround| kerning, since it will look very odd inside
  4378. % the display. We have our own spacing parameters for configuring these
  4379. % things, so |\mathsurround| is unnecessary.
  4380. %
  4381. % \begin{macrocode}
  4382. \m@th%
  4383. % \end{macrocode}
  4384. %
  4385. % Time to parse the preamble string now. I must choose the correct column
  4386. % set, initialise the preamble parser and set up the various macros. The%
  4387. % extra `|@{\tabskip\eqacloseskip}|' item sets up the tabskip glue to centre
  4388. % the alignment properly.
  4389. %
  4390. % \begin{macrocode}
  4391. \colset{eqnarray}%
  4392. \tab@initread%
  4393. \def\tab@tabtext{&\tabskip\z@skip}%
  4394. \tab@preamble{\tabskip\z@skip}%
  4395. \tab@readpreamble{#2@{\tabskip\eqacloseskip}}%
  4396. \dsp@tabpause%
  4397. % \end{macrocode}
  4398. %
  4399. % Now for some final setting up. The column separation is set from the
  4400. % user's parameter, the |\everycr| tokens are cleared, and I set up the
  4401. % newline command appropriately.
  4402. %
  4403. % \begin{macrocode}
  4404. \[email protected]\eqainskip%
  4405. \everycr{}%
  4406. \let\\\@eqncr%
  4407. % \end{macrocode}
  4408. %
  4409. % Now start a maths display and do the alignment. Set up the left hand
  4410. % tabskip glue to centre the alignment, and do the actual alignment.
  4411. % The preamble used is mainly that generated from the user's string, although
  4412. % the stuff at the end is how we set up the equation number -- it repeats
  4413. % appropriately so we can always find it.
  4414. %
  4415. % \begin{macrocode}
  4416. \dsp@start%
  4417. \tabskip\eqaopenskip%
  4418. \halign to\displaywidth\expandafter\bgroup%
  4419. \the\tab@preamble%
  4420. &&\eqa@lastcol\hb@xt@\z@{\hss##}\tabskip\z@\cr%
  4421. }
  4422. % \end{macrocode}
  4423. %
  4424. % Now for the end of the environment. This is really easy. Set the final
  4425. % equation number, close the |\halign|, tidy up the equation counter (it's
  4426. % been stepped once too many times) and close the display.
  4427. %
  4428. % \begin{macrocode}
  4429. \def\endeqnarray{%
  4430. \eqa@eqnum%
  4431. \egroup%
  4432. \dsp@end%
  4433. \global\let\eqa@number\eqa@oldnumber%
  4434. \global\@ignoretrue%
  4435. \global\advance\c@equation\m@ne%
  4436. }
  4437. \expandafter\let\csname endeqnarray*\endcsname\endeqnarray
  4438. % \end{macrocode}
  4439. %
  4440. % \end{environment}
  4441. % \end{environment}
  4442. %
  4443. % Now we can define the column types.
  4444. %
  4445. % \begin{macrocode}
  4446. \colpush{eqnarray}
  4447. % \end{macrocode}
  4448. %
  4449. % Note the positioning of ord atoms in the stuff below. This will space out
  4450. % relations and binops correctly when they occur at the edges of columns, and
  4451. % won't affect ord atoms at the edges, because ords pack closely.
  4452. %
  4453. % First the easy onces. Just stick |\hfil| in the right places and
  4454. % everything will be all right.
  4455. %
  4456. % \begin{macrocode}
  4457. \coldef r{\tabcoltype{\hfil$\eqastyle}{{}$}}
  4458. \coldef c{\tabcoltype{\hfil$\eqastyle{}}{{}$\hfil}}
  4459. \coldef l{\tabcoltype{$\eqastyle{}}{$\hfil}}
  4460. \coldef x{\tabcoltype{\if@fleqn\else\hfil\fi$\eqastyle}{$\hfil}}
  4461. % \end{macrocode}
  4462. %
  4463. % Now for the textual ones. This is also fairly easy.
  4464. %
  4465. % \begin{macrocode}
  4466. \collet T [tabular]T
  4467. % \end{macrocode}
  4468. %
  4469. % Sort of split types of equations. I mustn't use |\rlap| here, or
  4470. % everything goes wrong -- |\\| doesn't get noticed by \TeX\ in the same way
  4471. % as |\cr| does.
  4472. %
  4473. % \begin{macrocode}
  4474. \coldef L{\tabcoltype{\hb@xt@2em\bgroup$\eqastyle}{$\hss\egroup}}
  4475. % \end{macrocode}
  4476. %
  4477. % The \lit{:} column type is fairly simple.
  4478. %
  4479. % \begin{macrocode}
  4480. \coldef :{\tabspctype{\tabskip\eqacolskip}}
  4481. \coldef q{\tabspctype{\quad}}
  4482. % \end{macrocode}
  4483. %
  4484. % The other column types just insert given text in an appropriate way.
  4485. %
  4486. % \begin{macrocode}
  4487. \collet > [tabular]>
  4488. \collet < [tabular]<
  4489. \collet * [tabular]*
  4490. \collet @ [tabular]@
  4491. % \end{macrocode}
  4492. %
  4493. % Finally, the magical `|\magic|' column type, which sets the equation
  4494. % number. We set up the |\tabskip| glue properly, tab on, and set the flag
  4495. % which marks the final column. The |\eqa@lastcol| command is there to
  4496. % raise an error if the user tabs over to this column. I'll temporarily
  4497. % redefine it to |\@eqalasttrue| when I enter this column legitimately.
  4498. % The extra magical bits here will make the final column repeat, so that we
  4499. % can find it if necessary. Well is this column type named.
  4500. %
  4501. % That's it. We can return to normal now.
  4502. %
  4503. % \begin{macrocode}
  4504. \colpop
  4505. % \end{macrocode}
  4506. %
  4507. % \subsubsection{Newline codes}
  4508. %
  4509. % Newline sequences (|\\|) get turned into calls of |\@eqncr|. The job is
  4510. % fairly simple, really.
  4511. %
  4512. % \begin{macrocode}
  4513. \def\@eqncr{\tab@cr\eqacr@i\interdisplaylinepenalty\@M}%
  4514. \def\eqacr@i#1#2{%
  4515. \eqa@eqnum%
  4516. \noalign{\penalty#2\vskip\jot\vskip#1}%
  4517. }
  4518. % \end{macrocode}
  4519. %
  4520. % \subsubsection{Setting equation numbers}
  4521. %
  4522. % \begin{macro}{\eqa@eqpos}
  4523. %
  4524. % Before we start, we need to generalise the flush-left number handling bits.
  4525. % The macro |\eqa@eqpos| will put its argument in the right place.
  4526. %
  4527. % \begin{macrocode}
  4528. \if@leqno
  4529. \def\eqa@eqpos#1{%
  4530. \hb@[email protected]\p@{}\rlap{\normalfont\normalcolor\hskip-\displaywidth#1}%
  4531. }
  4532. \else
  4533. \def\eqa@eqpos#1{\normalfont\normalcolor#1}
  4534. \fi
  4535. % \end{macrocode}
  4536. %
  4537. % \end{macro}
  4538. %
  4539. % \begin{macro}{\eqa@eqnum}
  4540. %
  4541. % Here we typeset an equation number in roughly the right place. First I'll
  4542. % redefine |\eqa@lastcol| so that it tells me I'm in the right place, and
  4543. % start a loop to find that place.
  4544. %
  4545. % \begin{macrocode}
  4546. \def\eqa@eqnum{%
  4547. \global\let\eqa@lastcol\@eqalasttrue%
  4548. \eqa@eqnum@i%
  4549. }
  4550. % \end{macrocode}
  4551. %
  4552. % Now for the loop. The |\relax| here is absolutely vital -- it starts the
  4553. % table column, inserting useful tokens like `|\eqa@lastcol|' which tell
  4554. % me where I am in the alignment. Then, if I've reached the end, I can
  4555. % typeset the equation number; otherwise I go off into another macro and
  4556. % step on to the next column.
  4557. %
  4558. % \begin{macrocode}
  4559. \def\eqa@eqnum@i{%
  4560. \relax%
  4561. \if@eqalast%
  4562. \expandafter\eqa@eqnum@ii%
  4563. \else%
  4564. \expandafter\eqa@eqnum@iii%
  4565. \fi%
  4566. }
  4567. \def\eqa@eqnum@ii{%
  4568. \eqa@eqpos\eqa@number%
  4569. \global\let\eqa@number\eqa@defnumber%
  4570. \global\let\eqa@lastcol\eqa@@lastcol%
  4571. \cr%
  4572. }
  4573. \def\eqa@eqnum@iii{&\eqa@eqnum@i}
  4574. % \end{macrocode}
  4575. %
  4576. % \end{macro}
  4577. %
  4578. % \begin{macro}{\eqa@lastcol}
  4579. %
  4580. % This is used as a marker for the final column in an \env{eqnarray}
  4581. % environment. By default it informs the user that they've been very
  4582. % silly and swallows the contents of the column. I'll redefine it to
  4583. % something more useful at appropriate times, and then turn it back again.
  4584. %
  4585. % \begin{macrocode}
  4586. \def\eqa@@lastcol{\mth@err@number\setbox\z@}
  4587. \let\eqa@lastcol\eqa@@lastcol
  4588. % \end{macrocode}
  4589. %
  4590. % \end{macro}
  4591. %
  4592. % \subsubsection{Numbering control}
  4593. %
  4594. % \begin{macro}{\eqnumber}
  4595. %
  4596. % The |\eqnumber| command sets the equation number on the current equation.
  4597. % This is really easy, actually.
  4598. %
  4599. % \begin{macrocode}
  4600. \newcommand\eqnumber[1][\eqa@eqcount]{\gdef\eqa@number{#1}}
  4601. % \end{macrocode}
  4602. %
  4603. % \end{macro}
  4604. %
  4605. % \begin{macro}{\eqa@eqcount}
  4606. %
  4607. % This is how a standard equation number is set, stepping the counter and
  4608. % all. It's really easy and obvious.
  4609. %
  4610. % \begin{macrocode}
  4611. \def\eqa@eqcount{(\theequation)\global\advance\c@equation\@ne}
  4612. % \end{macrocode}
  4613. %
  4614. % \end{macro}
  4615. %
  4616. % \begin{macro}{\nonumber}
  4617. %
  4618. % The \LaTeX\ |\nonumber| command could be defined by saying
  4619. % \begin{listing}
  4620. %\renewcommand{\nonumber}{\eqnumber[]}
  4621. % \end{listing}
  4622. % but I'll be slightly more efficient and redefine |\eqa@number| directly.
  4623. %
  4624. % \begin{macrocode}
  4625. \def\nonumber{\global\let\eqa@number\@empty}
  4626. % \end{macrocode}
  4627. %
  4628. % \end{macro}
  4629. %
  4630. % \subsubsection{The \env{eqnalign} environment}
  4631. %
  4632. % As a sort of companion to \env{eqnarray}, here's an environment which does
  4633. % similar things inside a box, rather than taking up the whole display width.
  4634. % It uses the same column types that we've already created, so there should
  4635. % be no problems.
  4636. %
  4637. % \begin{environment}{eqnalign}
  4638. %
  4639. % First, sort out some simple things like optional arguments.
  4640. %
  4641. % \begin{macrocode}
  4642. \def\eqnalign{\@ifnextchar[\eqnalign@i{\eqnalign@i[rcl]}}
  4643. \def\eqnalign@i[#1]{%
  4644. \@ifnextchar[{\eqnalign@ii{#1}}{\eqnalign@ii{#1}[c]}%
  4645. }
  4646. % \end{macrocode}
  4647. %
  4648. % Now we actually do the environment. This is fairly easy, actually.
  4649. %
  4650. % \begin{macrocode}
  4651. \def\eqnalign@ii#1[#2]{%
  4652. \let\\\eqn@cr%
  4653. \colset{eqnarray}%
  4654. \tab@initread%
  4655. \def\tab@tabtext{&\tabskip\z@skip}%
  4656. \tabskip\z@skip%
  4657. \[email protected]\eqainskip%
  4658. \tab@readpreamble{#1}%
  4659. \everycr{}%
  4660. \if#2t\vtop\else%
  4661. \if#2b\vbox\else%
  4662. \vcenter%
  4663. \fi%
  4664. \fi%
  4665. \bgroup%
  4666. \halign\expandafter\bgroup\the\tab@preamble\cr%
  4667. }
  4668. % \end{macrocode}
  4669. %
  4670. % Finishing the environment is even simpler.
  4671. %
  4672. % \begin{macrocode}
  4673. \def\endeqnalign{%
  4674. \crcr%
  4675. \egroup%
  4676. \egroup%
  4677. }
  4678. % \end{macrocode}
  4679. %
  4680. % \end{environment}
  4681. %
  4682. % \begin{macro}{\eqn@cr}
  4683. %
  4684. % Newlines are really easy here.
  4685. %
  4686. % \begin{macrocode}
  4687. \def\eqn@cr{\tab@cr\eqn@cr@i{}{}}
  4688. \def\eqn@cr@i#1{\cr\noalign{\vskip\jot\vskip#1}\@gobble}
  4689. % \end{macrocode}
  4690. %
  4691. % \end{macro}
  4692. %
  4693. %
  4694. % \subsection{Simple multiline equations}
  4695. %
  4696. % As a sort of example and abbreviation, here's a multiline display
  4697. % environment which just centres everything.
  4698. %
  4699. % \begin{environment}{eqlines}
  4700. %
  4701. % We just get |\eqnarray| to do everything for us. This is really easy.
  4702. %
  4703. % \begin{macrocode}
  4704. \def\eqlines{\eqnarray[x]}
  4705. \let\endeqlines\endeqnarray
  4706. % \end{macrocode}
  4707. %
  4708. % \end{environment}
  4709. %
  4710. % \begin{environment}{eqlines*}
  4711. %
  4712. % There's a $*$ version which omits numbers. This is easy too. Lots of
  4713. % hacking with expansion here to try and reduce the number of tokens being
  4714. % used. Is it worth it?
  4715. %
  4716. % \begin{macrocode}
  4717. \expandafter\edef\csname eqlines*\endcsname{%
  4718. \expandafter\noexpand\csname eqnarray*\endcsname[x]%
  4719. }
  4720. \expandafter\let\csname endeqlines*\expandafter\endcsname
  4721. \csname endeqnarray*\endcsname
  4722. % \end{macrocode}
  4723. %
  4724. % \end{environment}
  4725. %
  4726. %
  4727. % \subsection{Split equations}
  4728. %
  4729. % Based on an idea from \textit{The \TeX book}, we provide some simple
  4730. % environments for doing split equations. These's plenty of scope for
  4731. % improvement here, though.
  4732. %
  4733. % \begin{environment}{spliteqn}
  4734. % \begin{environment}{spliteqn*}
  4735. %
  4736. % The only difference between these two is that the $*$-version doesn't put
  4737. % in an equation number by default (although this behaviour can be
  4738. % changed by |\eqnumber|).
  4739. %
  4740. % The fun here mainly concerns putting in the equation number at the right
  4741. % place -- for |leqno| users, we need to put the number on the first line;
  4742. % otherwise we put it on the last line.
  4743. %
  4744. % The way we handle this is to have two macros, |\\| (which clearly does
  4745. % all the user line breaks) and |\seq@lastcr| which is used at the end of
  4746. % the environment to wrap everything up. The |\seq@eqnocr| macro puts an
  4747. % equation number on the current line and then does a normal |\\|. It also
  4748. % resets |\\| and |\seq@lastcr| so that they don't try to put another
  4749. % equation number in. This must be done globally, although anyone who tries
  4750. % to nest maths displays will get what they deserve.
  4751. %
  4752. % For the non-$*$ environment, then, we need to step the equation counter,
  4753. % and set |\\| to |\seq@cr| or |\seq@eqnocr| as appropriate for the setting
  4754. % of the |leqno| flag -- |\seq@lastcr| always gets set to put an equation
  4755. % number in (because it will be reset if the number actually gets done
  4756. % earlier -- this catches stupid users trying to put a single row into
  4757. % a split environment).
  4758. %
  4759. % \begin{macrocode}
  4760. \def\spliteqn{%
  4761. \let\eqa@oldnumber\eqa@number%
  4762. \global\let\eqa@number\eqa@eqcount%
  4763. \spliteqn@i%
  4764. }
  4765. % \end{macrocode}
  4766. %
  4767. % For the $*$ variant, we don't need to bother with equation numbering, so
  4768. % this is really easy.
  4769. %
  4770. % \begin{macrocode}
  4771. \@namedef{spliteqn*}{%
  4772. \let\eqa@oldnumber\eqa@number%
  4773. \gdef\eqa@number{}%
  4774. \spliteqn@i%
  4775. }
  4776. % \end{macrocode}
  4777. %
  4778. % Ending the environments is easy. Most of the stuff here will be described
  4779. % later.
  4780. %
  4781. % \begin{macrocode}
  4782. \def\endspliteqn{%
  4783. \hfilneg\seq@lastcr%
  4784. \egroup%
  4785. \dsp@end%
  4786. \global\let\eqa@number\eqa@oldnumber%
  4787. \global\advance\c@equation\m@ne%
  4788. }
  4789. \expandafter\let\csname endspliteqn*\endcsname\endspliteqn
  4790. % \end{macrocode}
  4791. %
  4792. % \end{environment}
  4793. % \end{environment}
  4794. %
  4795. % \begin{macro}{\spliteqn@i}
  4796. %
  4797. % Here we handle the full display splits. Start a maths display, and make
  4798. % each row of the alignment take up the full display width.
  4799. %
  4800. % The macro |\seq@dosplit| does most of the real work for us -- setting up
  4801. % the alignment and so forth. The template column is interesting. There
  4802. % are two items glue on both sides of the actual text:
  4803. %
  4804. % \begin{itemize}
  4805. %
  4806. % \item Some glue which can shrink. This keeps the display from the edges
  4807. % of the page unless we get a really wide item.
  4808. %
  4809. % \item An |\hfil| to do the alignment. By default, this centres the
  4810. % equations. On the first line, however, we put a leading |\hfilneg|
  4811. % which cancels the first |\hfil|, making the first row left aligned.
  4812. % Similarly, at the end, we put an |\hfilneg| after the last equation
  4813. % to right align the last line.
  4814. %
  4815. % \end{itemize}
  4816. %
  4817. % We pass this information on as an argument. It's easy really.
  4818. %
  4819. % \begin{macrocode}
  4820. \def\spliteqn@i{%
  4821. % \end{macrocode}
  4822. %
  4823. % First, set up equation numbering properly. See my rant about
  4824. % |\refstepcounter| above.
  4825. %
  4826. % \begin{macrocode}
  4827. \stepcounter{equation}%
  4828. \def\@currentlabel{\p@equation\theequation}%
  4829. % \end{macrocode}
  4830. %
  4831. % Right; now to sort out the numbering and newline handling. If the number's
  4832. % meant to be on the first line (for \textsf{leqno} users), then it gets
  4833. % typeset on the first like; otherwise we just do a normal newline on
  4834. % all lines except the first. Once |\seq@eqnocr| has done its stuff, it
  4835. % redefines all the newline handling not to insert another number.
  4836. %
  4837. % \begin{macrocode}
  4838. \if@leqno%
  4839. \global\let\seq@docr\seq@eqnocr%
  4840. \else%
  4841. \global\let\seq@docr\seq@cr%
  4842. \fi%
  4843. \global\let\seq@lastcr\seq@eqnocr%
  4844. % \end{macrocode}
  4845. %
  4846. % For my next trick, I'll do some display handling -- start a (possibly
  4847. % nested) maths display, set up the |\tabpause| macro appropriately, and
  4848. % set the newline command to do the right thing.
  4849. %
  4850. % \begin{macrocode}
  4851. \dsp@start%
  4852. \dsp@tabpause%
  4853. \def\\{\seq@docr}%
  4854. % \end{macrocode}
  4855. %
  4856. % Finally, call another macro to do the remaining bits of setting up.
  4857. %
  4858. % \begin{macrocode}
  4859. \seq@dosplit%
  4860. {\hb@xt@\displaywidth{%
  4861. \hskip\splitleft\hfil$\displaystyle##$%
  4862. \hfil\hskip\splitright}}%
  4863. {\hfilneg}%
  4864. }
  4865. % \end{macrocode}
  4866. %
  4867. % \end{macro}
  4868. %
  4869. % \begin{environment}{subsplit}
  4870. %
  4871. % For doing splits in the middle of equations, we provide a similar
  4872. % environment. Here, we make |\\| just start a new line. We also use
  4873. % a |\vcenter| rather than a full maths display. The glue items are also
  4874. % a bit different: we use plain double-quads on each side of the item, and
  4875. % we need to remove them by hand at the extremeties of the environment.
  4876. %
  4877. % \begin{macrocode}
  4878. \def\subsplit{%
  4879. \let\\\seq@cr%
  4880. \vcenter\bgroup%
  4881. \seq@dosplit{\hfil\qquad$##$\qquad\hfil}{\hfilneg\hskip-2em}%
  4882. }
  4883. % \end{macrocode}
  4884. %
  4885. % Ending the environment is fairly easy. We remove the final glue item,
  4886. % and close the alignment and the vbox.
  4887. %
  4888. % \begin{macrocode}
  4889. \def\endsubsplit{%
  4890. \hfilneg\hskip-2em\cr%
  4891. \egroup\egroup%
  4892. }
  4893. % \end{macrocode}
  4894. %
  4895. % \end{environment}
  4896. %
  4897. % \begin{macro}{\seq@dosplit}
  4898. %
  4899. % Here we do most of the real work. Actually, since the preamble is passed
  4900. % in as an argument, most of the work is already done. The only thing to
  4901. % really note is the template for subsequent columns. To stop users putting
  4902. % in extra columns (which is where we put the equation number) we raise an
  4903. % error and discard the input in a scratch box register. This template is
  4904. % repeated infinitely so as to allow us to put the equation number in nicely.
  4905. % However, the final negative glue item won't work properly, so the equation
  4906. % will look awful.
  4907. %
  4908. % \begin{macrocode}
  4909. \def\seq@dosplit#1#2{%
  4910. \halign\bgroup%
  4911. #1&&\mth@err@number\setbox\z@\hbox{##}\cr%
  4912. #2\relax%
  4913. }
  4914. % \end{macrocode}
  4915. %
  4916. % \end{macro}
  4917. %
  4918. % \begin{macro}{\seq@eqnocr}
  4919. %
  4920. % Here's how we set equation numbers. Since the column provided raises
  4921. % errors as soon as a token finds its way into it, we start with a |&\omit|.
  4922. % Then we just put the equation number in a zero-width box. Finally, we
  4923. % reset the newline commands to avoid putting in more than one equation
  4924. % number, and do normal newline things.
  4925. %
  4926. % \begin{macrocode}
  4927. \def\seq@eqnocr{%
  4928. &\omit%
  4929. \hb@xt@\z@{\hss\eqa@eqpos\eqa@number}%
  4930. \global\let\seq@docr\seq@cr%
  4931. \global\let\seq@lastcr\seq@cr%
  4932. \seq@cr%
  4933. }
  4934. % \end{macrocode}
  4935. %
  4936. % \end{macro}
  4937. %
  4938. % \begin{macro}{\seq@cr}
  4939. %
  4940. % Newlines are very easy. We add a |\jot| of extra space, since this is
  4941. % a nice thing to do.
  4942. %
  4943. % \begin{macrocode}
  4944. \def\seq@cr{\tab@cr\seq@cr@i\interdisplaylinepenalty\@M}
  4945. \def\seq@cr@i#1#2{\cr\noalign{\penalty#2\vskip\jot\vskip#1}}
  4946. % \end{macrocode}
  4947. %
  4948. % \end{macro}
  4949. %
  4950. %
  4951. % \subsection{Matrix handling}
  4952. %
  4953. % There's been a complete and total overhaul of the spacing calculations
  4954. % for matrices here. The vertical spacing now bears an uncanny similarity
  4955. % to the rules \TeX\ uses to space out |\atop|-like fractions, the difference
  4956. % being that you can have more than one column in a matrix. This has the
  4957. % interesting side-effect that we get an \package{amsmath}-style
  4958. % sub/superscript environment almost free of charge with the matrix handling
  4959. % (it just ends up being a script-size single-column matrix).
  4960. %
  4961. % What is rather gratifying is that our \env{matrix} environment looks
  4962. % rather nicer than \package{amsmath}'s (which is based directly on
  4963. % \env{array}, giving it nasty restrictions on the numbers of columns and
  4964. % so on); in particular, the version here gives the `correct' result for
  4965. % Knuth's exercise~18.42 (which states categorically that a |\smallskip|
  4966. % should be placed between the rows of the big matrix).
  4967. %
  4968. % The reason the interrow space doesn't come out in the AMS version is
  4969. % that \env{array} inserts extra vertical space by extending the depth of
  4970. % the final row using a strut: the big matrix already extends deeper than
  4971. % this, so the strut doesn't make any difference. If the space was added
  4972. % by |\hlx{s[\smallskipamount]}| instead of the |\\| command, things would
  4973. % be different.
  4974. %
  4975. % \begin{figure}
  4976. %
  4977. % ^^A This is essentially what amsmath (version 1.2b) does. The real
  4978. % ^^A implementation requires a counter MaxMatrixCols, and has fewer braces:
  4979. % ^^A that's all the difference. Oh, and I turn off \arrayextrasep here,
  4980. % ^^A since amsmath doesn't expect it to be there (accurate emulation, see?)
  4981. % ^^A and I've used \hspace instead of \hskip since everything else is
  4982. % ^^A `proper' LaTeX stuff.
  4983. %
  4984. % \newenvironment{ams-pmatrix}{^^A
  4985. % \setlength{\arrayextrasep}{0pt}^^A
  4986. % \left(^^A
  4987. % \hspace{-\arraycolsep}^^A
  4988. % \begin{array}{*{10}{c}}^^A
  4989. % }{^^A
  4990. % \end{array}^^A
  4991. % \hspace{-\arraycolsep}^^A
  4992. % \right)^^A
  4993. % }
  4994. %
  4995. % \begin{demo}{Exercise 18.42 from \emph{The \TeX book}}
  4996. %\newcommand{\domatrix}[1]{
  4997. % \def\mat##1
  4998. % {\begin{#1}##1\end{#1}}
  4999. % \[ \begin{#1}
  5000. % \mat{a & b \\ c & d} &
  5001. % \mat{e & f \\ g & h}
  5002. % \\[\smallskipamount]
  5003. % 0 &
  5004. % \mat{i & j \\ k & l}
  5005. % \end{#1}
  5006. % \]
  5007. %}
  5008. %\domatrix{pmatrix}
  5009. %\domatrix{ams-pmatrix}
  5010. % \end{demo}
  5011. %
  5012. % \end{figure}
  5013. %
  5014. % \begin{environment}{genmatrix}
  5015. %
  5016. % The first job is to store my maths style and font away, because I'll be
  5017. % needing it lots later.
  5018. %
  5019. % \begin{macrocode}
  5020. \def\genmatrix#1#2#3#4#5{%
  5021. \let\mat@style#1%
  5022. \ifx#2\scriptstyle%
  5023. \let\mat@font\scriptfont%
  5024. \else\ifx#2\scriptscriptstyle%
  5025. \let\mat@font\scriptscriptfont%
  5026. \else%
  5027. \let\mat@font\textfont%
  5028. \fi\fi%
  5029. % \end{macrocode}
  5030. %
  5031. % Now to cope with inserted text. This is easy.
  5032. %
  5033. % \begin{macrocode}
  5034. \ifx\mat@style\scriptstyle%
  5035. \let\mat@textsize\scriptsize%
  5036. \else\ifx\mat@style\scriptscriptstyle%
  5037. \let\mat@textsize\scriptscriptsize%
  5038. \else%
  5039. \let\mat@textsize\relax%
  5040. \fi\fi%
  5041. % \end{macrocode}
  5042. %
  5043. % Now for some fun. I'll remember how to start and end the matrix in a
  5044. % couple of macros |\mat@left| and |\mat@right|. I haven't yet worked out
  5045. % exactly what needs to be in |\mat@right| yet, though, so I'll build that
  5046. % up in a scratch token list while I'm making my mind up.
  5047. %
  5048. % Initially, I want to open a group (to trap the style changes), set the
  5049. % maths style (to get the right spacing), insert the left delimiter, insert
  5050. % some spacing around the matrix, and start a centred box. The ending just
  5051. % closes all the groups and delimiters I opened.
  5052. %
  5053. % \begin{macrocode}
  5054. \def\mat@left{\bgroup\mat@style\left#4#3\vcenter\bgroup}%
  5055. \toks@{\egroup#3\right#5\egroup}%
  5056. % \end{macrocode}
  5057. %
  5058. % Now comes a slightly trickier bit. If the maths style is script or
  5059. % scriptscript, then I need to raise the box by a little bit to make it look
  5060. % really good. The right amount is somewhere around \smallf 3/4\,pt, I
  5061. % think, so that's what I'll use.
  5062. %
  5063. % \begin{macrocode}
  5064. \@tempswatrue%
  5065. \ifx\mat@style\displaystyle\else\ifx\mat@style\textstyle\else%
  5066. \@tempswafalse%
  5067. \setbox\z@\hbox\bgroup$%
  5068. \toks@\expandafter{\the\toks@$\m@th\egroup\raise.75\p@\box\z@}%
  5069. \fi\fi%
  5070. % \end{macrocode}
  5071. %
  5072. % If I'm not in maths mode right now, then I should enter maths mode, and
  5073. % remember to leave it later.
  5074. %
  5075. % \begin{macrocode}
  5076. \if@tempswa\ifmmode\else%
  5077. $\m@th%
  5078. \toks@\expandafter{\the\toks@$}%
  5079. \fi\fi%
  5080. % \end{macrocode}
  5081. %
  5082. % Now I've sorted out how to end the environment properly, so I can set up
  5083. % the macro, using |\edef|.
  5084. %
  5085. % \begin{macrocode}
  5086. \edef\mat@right{\the\toks@}%
  5087. % \end{macrocode}
  5088. %
  5089. % Now see if there's an optional argument. If not, create lots of centred
  5090. % columns.
  5091. %
  5092. % \begin{macrocode}
  5093. \@ifnextchar[\genmatrix@i{\genmatrix@i[[c]}%
  5094. }
  5095. % \end{macrocode}
  5096. %
  5097. % Now to sort out everything else.
  5098. %
  5099. % \begin{macrocode}
  5100. \def\genmatrix@i[#1]{%
  5101. % \end{macrocode}
  5102. %
  5103. % Some initial setting up: choose the correct column set, and set up some
  5104. % variables for reading the preamble.
  5105. %
  5106. % \begin{macrocode}
  5107. \colset{matrix}%
  5108. \tab@initread%
  5109. % \end{macrocode}
  5110. %
  5111. % Now comes some of the tricky stuff. The space between columns should be
  5112. % 12\,mu (by trial and error). We put the space in a box so we can measure
  5113. % it in the correct mathstyle.
  5114. %
  5115. % \begin{macrocode}
  5116. \setbox\z@\hbox{$\mat@style\mskip12mu$}%
  5117. \edef\tab@tabtext{&\kern\the\wd\z@}%
  5118. \tab@readpreamble{#1}%
  5119. % \end{macrocode}
  5120. %
  5121. % Now we need to decide how to space out the rows. The code here is based
  5122. % on the information in appendix~G of \emph{The \TeX book}: I think it'd be
  5123. % nice if my matrices were spaced out in the same way as normal fractions
  5124. % (particularly |\choose|y things). The standard |\baselineskip| and
  5125. % |\lineskip| parameters come in really handy here.
  5126. %
  5127. % The parameters vary according to the size of the text, so I need to see
  5128. % if we have scriptsize or less, or not. The tricky |\if| sorts this out.
  5129. %
  5130. % \begin{macrocode}
  5131. \if1\ifx\mat@style\scriptstyle1\else%
  5132. \ifx\mat@style\scriptscriptstyle1\else0\fi\fi%
  5133. \baselineskip\fontdimen10\mat@font\tw@%
  5134. \advance\baselineskip\fontdimen12\mat@font\tw@%
  5135. \lineskip\thr@@\fontdimen8\mat@font\thr@@%
  5136. \else%
  5137. \baselineskip\fontdimen8\mat@font\tw@%
  5138. \advance\baselineskip\fontdimen11\mat@font\tw@%
  5139. \lineskip7\fontdimen8\mat@font\thr@@%
  5140. \fi%
  5141. \lineskiplimit\lineskip%
  5142. % \end{macrocode}
  5143. %
  5144. % Now actually set up for the alignment. Assign |\\| to the correct value.
  5145. % Set up the |\tabskip|. Do the appropriate |\mat@left| thing set up above.
  5146. % And then start the alignment.
  5147. %
  5148. % \begin{macrocode}
  5149. \let\\\mat@cr%
  5150. \tabskip\z@skip%
  5151. \col@sep\z@%
  5152. \mat@left%
  5153. \halign\expandafter\bgroup\the\tab@preamble\tabskip\z@skip\cr%
  5154. % \end{macrocode}
  5155. %
  5156. % Now for a little hack to make the spacing consistent between matrices of
  5157. % the same height. This comes directly from \PlainTeX. This appears to
  5158. % make the spacing \emph{exactly} the same as the \TeX\ primites, oddly
  5159. % enough.
  5160. %
  5161. % \begin{macrocode}
  5162. \ifx\mat@font\textfont%
  5163. \omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}%
  5164. \fi%
  5165. }
  5166. % \end{macrocode}
  5167. %
  5168. % Finishing the environment is really easy. We do the spacing hack again
  5169. % at the bottom, close the alignment and then tidy whatever we started in
  5170. % |\mat@left|.
  5171. %
  5172. % \begin{macrocode}
  5173. \def\endgenmatrix{%
  5174. \crcr%
  5175. \ifx\mat@font\textfont%
  5176. \omit$\mat@style\mathstrut$\cr\noalign{\kern-\baselineskip}%
  5177. \fi%
  5178. \egroup%
  5179. \mat@right%
  5180. }
  5181. % \end{macrocode}
  5182. %
  5183. % \end{environment}
  5184. %
  5185. % \begin{macro}{\mat@cr}
  5186. %
  5187. % Newlines are really easy. The $*$-form means nothing here, so we ignore
  5188. % it.
  5189. %
  5190. % \begin{macrocode}
  5191. \def\mat@cr{\tab@cr\mat@cr@i{}{}}
  5192. \def\mat@cr@i#1{\cr\noalign{\vskip#1}\@gobble}
  5193. % \end{macrocode}
  5194. %
  5195. % \end{macro}
  5196. %
  5197. % \begin{macro}{\newmatrix}
  5198. %
  5199. % This is how we define new matrix environments. It's simple fun with
  5200. % |\csname| and |\expandafter|.
  5201. %
  5202. % \begin{macrocode}
  5203. \def\newmatrix#1#2{%
  5204. \@namedef{#1}{\genmatrix#2}%
  5205. \expandafter\let\csname end#1\endcsname\endgenmatrix%
  5206. }
  5207. % \end{macrocode}
  5208. %
  5209. % \end{macro}
  5210. %
  5211. % \begin{environment}{matrix}
  5212. % \begin{environment}{pmatrix}
  5213. % \begin{environment}{dmatrix}
  5214. % \begin{environment}{smatrix}
  5215. % \begin{environment}{spmatrix}
  5216. % \begin{environment}{sdmatrix}
  5217. % \begin{environment}{smatrix*}
  5218. % \begin{environment}{spmatrix*}
  5219. % \begin{environment}{sdmatrix*}
  5220. %
  5221. % Now we define all the other environments we promised. This is easy.
  5222. %
  5223. % \begin{macrocode}
  5224. \newmatrix{matrix}{{\textstyle}{\textstyle}{\,}{.}{.}}
  5225. \newmatrix{pmatrix}{{\textstyle}{\textstyle}{\,}{(}{)}}
  5226. \newmatrix{dmatrix}{{\textstyle}{\textstyle}{\,}}
  5227. \newmatrix{smatrix}{{\scriptstyle}{\scriptstyle}{}{.}{.}}
  5228. \newmatrix{spmatrix}{{\scriptstyle}{\scriptstyle}{}{(}{)}}
  5229. \newmatrix{sdmatrix}{{\scriptstyle}{\scriptstyle}{}}
  5230. \newmatrix{smatrix*}{{\scriptstyle}{\textstyle}{}{.}{.}}
  5231. \newmatrix{spmatrix*}{{\scriptstyle}{\textstyle}{}{(}{)}}
  5232. \newmatrix{sdmatrix*}{{\scriptstyle}{\textstyle}{}}
  5233. % \end{macrocode}
  5234. %
  5235. % \end{environment}
  5236. % \end{environment}
  5237. % \end{environment}
  5238. % \end{environment}
  5239. % \end{environment}
  5240. % \end{environment}
  5241. % \end{environment}
  5242. % \end{environment}
  5243. % \end{environment}
  5244. %
  5245. % \begin{environment}{script}
  5246. %
  5247. % Now for superscripts and subscripts. This is fairly easy, because I
  5248. % took so much care over the matrix handling.
  5249. %
  5250. % \begin{macrocode}
  5251. \def\script{%
  5252. \let\mat@style\scriptstyle%
  5253. \def\mat@left{\vcenter\bgroup}%
  5254. \def\mat@right{\egroup}%
  5255. \let\mat@font\scriptfont%
  5256. \let\mat@textsize\scriptsize%
  5257. \@ifnextchar[\genmatrix@i{\genmatrix@i[c]}%
  5258. }
  5259. \let\endscript\endgenmatrix
  5260. % \end{macrocode}
  5261. %
  5262. % \end{environment}
  5263. %
  5264. % Now define the column types.
  5265. %
  5266. % \begin{macrocode}
  5267. \colpush{matrix}
  5268. \coldef l{\tabcoltype{\kern\z@$\mat@style}{\m@th$\hfil}}
  5269. \coldef c{\tabcoltype{\hfil$\mat@style}{\m@th$\hfil}}
  5270. \coldef r{\tabcoltype{\hfil$\mat@style}{\m@th$}}
  5271. \coldef T#1{\tab@aligncol{#1}{\begingroup\mat@textsize}{\endgroup}}
  5272. % \end{macrocode}
  5273. %
  5274. % The repeating type is more awkward. Things will go wrong if this is
  5275. % given before the first column, so we must do a whole repeat by hand. We
  5276. % can tell if we haven't contributed a column yet, since |\tab@column| will
  5277. % be zero. Otherwise, we fiddle the parser state to start a new column, and
  5278. % insert the |&| character to make \TeX\ repeat the preamble.
  5279. %
  5280. % \begin{macrocode}
  5281. \coldef {[}{%
  5282. \@firstoftwo{%
  5283. \ifnum\tab@columns=\z@%
  5284. \def\@tempa##1\q@delim{%
  5285. \tab@mkpreamble##1[##1\q@delim%
  5286. }%
  5287. \expandafter\@tempa%
  5288. \else%
  5289. \tab@setstate\tab@prestate%
  5290. \tab@append\tab@preamble{&}%
  5291. \expandafter\tab@mkpreamble%
  5292. \fi%
  5293. }%
  5294. }
  5295. % \end{macrocode}
  5296. %
  5297. % We're done defining columns now.
  5298. %
  5299. % \begin{macrocode}
  5300. \colpop
  5301. % \end{macrocode}
  5302. %
  5303. %
  5304. % \subsection{Dots\dots}
  5305. %
  5306. % Nothing whatsoever to do with alignments, although vertical and diagonal
  5307. % dots in small matrices look really silly. The following hacky definitions
  5308. % work rather better.
  5309. %
  5310. % \begin{macro}{\mdw@dots}
  5311. %
  5312. % First of all, here's some definitions common to both of the dots macros.
  5313. % The macro takes as an argument the actual code to draw the dots, passing
  5314. % it the scaled size of a point in the scratch register |\dimen@|; the
  5315. % register |\box 0| is set to contain a dot of the appropriate size.
  5316. %
  5317. % \begin{macrocode}
  5318. \def\mdw@dots#1{\ensuremath{\mathpalette\mdw@dots@i{#1}}}
  5319. \def\mdw@dots@i#1#2{%
  5320. \setbox\z@\hbox{$#1\mskip1.8mu$}%
  5321. \dimen@\wd\z@%
  5322. \setbox\z@\hbox{$#1.$}%
  5323. #2%
  5324. }
  5325. % \end{macrocode}
  5326. %
  5327. % \end{macro}
  5328. %
  5329. % \begin{macro}{\vdots}
  5330. %
  5331. % I'll start with the easy one. This is a simple translation of the original
  5332. % implementation.
  5333. %
  5334. % \begin{macrocode}
  5335. \def\vdots{%
  5336. \mdw@dots{\vbox{%
  5337. \baselineskip4\dimen@%
  5338. \lineskiplimit\z@%
  5339. \kern6\dimen@%
  5340. \copy\z@\copy\z@\box\z@%
  5341. }}%
  5342. }
  5343. % \end{macrocode}
  5344. %
  5345. % \end{macro}
  5346. %
  5347. % \begin{macro}{\ddots}
  5348. %
  5349. % And I'll end with the other easy one\dots
  5350. %
  5351. % \begin{macrocode}
  5352. \def\ddots{%
  5353. \mdw@dots{\mathinner{%
  5354. \mkern1mu%
  5355. \raise7\dimen@\vbox{\kern7\dimen@\copy\z@}%
  5356. \mkern2mu%
  5357. \raise4\dimen@\copy\z@%
  5358. \mkern2mu%
  5359. \raise\dimen@\box\z@%
  5360. \mkern1mu%
  5361. }}%
  5362. }
  5363. % \end{macrocode}
  5364. %
  5365. % \end{macro}
  5366. %
  5367. %
  5368. % \subsection{Lucky dip}
  5369. %
  5370. % Time to round off with some trivial environments, just to show how easy
  5371. % this stuff is.
  5372. %
  5373. % \begin{environment}{cases}
  5374. % \begin{environment}{smcases}
  5375. %
  5376. % These are totally and utterly trivial.
  5377. %
  5378. % \begin{macrocode}
  5379. \def\cases{\left\{\,\array{@{}lTl@{}}}
  5380. \def\endcases{\endarray\,\right.}
  5381. \def\smcases{\left\{\smarray{@{}lTl@{}}}
  5382. \def\endsmcases{\endsmarray\,\right.}
  5383. % \end{macrocode}
  5384. %
  5385. % \end{environment}
  5386. % \end{environment}
  5387. %
  5388. % \subsection{Error messages}
  5389. %
  5390. % Some token saving:
  5391. %
  5392. % \begin{macrocode}
  5393. \def\mth@error{\PackageError{mathenv}}
  5394. % \end{macrocode}
  5395. %
  5396. % Now for the error messages.
  5397. %
  5398. % \begin{macrocode}
  5399. \def\mth@err@number{%
  5400. \mth@error{Too many `&' characters found}{%
  5401. You've put too many `&' characters in an alignment^^J%
  5402. environment (like `eqnarray' or `spliteqn') and wandered^^J%
  5403. into trouble. I've gobbled the contents of that column^^J%
  5404. and hopefully I can recover fairly easily.%
  5405. }%
  5406. }
  5407. % \end{macrocode}
  5408. %
  5409. % \begin{macrocode}
  5410. \def\mth@err@mdsp{%
  5411. \mth@error{Can't do displays in nondisplay maths mode}{%
  5412. You're trying to start a display environment, but you're^^J%
  5413. in nondisplay maths mode. The display will appear but^^J%
  5414. don't blame me when it looks horrible.%
  5415. }%
  5416. }
  5417. % \end{macrocode}
  5418. %
  5419. % \begin{macrocode}
  5420. \def\mth@err@hdsp{%
  5421. \mth@error{Can't do displays in LR mode}{%
  5422. You're trying to start a display environment, but you're^^J%
  5423. in LR (restricted horizontal) mode. Everything will go^^J%
  5424. totally wrong, so your best bet is to type `X', fix the^^J%
  5425. mistake and start again.%
  5426. }%
  5427. }
  5428. % \end{macrocode}
  5429. %
  5430. % \vskip\parskip\vbox{ ^^A The best way I could find of keeping this lot
  5431. % ^^A together, I'm afraid.
  5432. % That's all there is. Byebye.
  5433. %
  5434. % \begin{macrocode}
  5435. %</mathenv>
  5436. % \end{macrocode}
  5437. % \nopagebreak
  5438. %
  5439. % \hfill Mark Wooding, \today
  5440. % }
  5441. %
  5442. % \Finale
  5443. %
  5444. \endinput