core-var.mkii / last modification: 2020-01-30 14:15
%D \module
%D   [       file=core-var,
%D        version=1998.02.21,
%D          title=\CONTEXT\ Core Macros,
%D       subtitle=Variables,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Core Macros / Variables}

\unprotect

%D We introduce a couple of variables that are used all over
%D \CONTEXT. Alternatively we could define them in each module
%D but as they are part of the bigger picture we prefer to do
%D it here.

%D \macros
%D   {every...}
%D
%D A few every's. Some are only used in \MKII\ or \MKIV.

%D Output routine:

\newtoks \everybeforeoutput
\newtoks \everyafteroutput

%D Shipout:

\newtoks \everyshipout
\newtoks \everybeforeshipout
\newtoks \everyaftershipout
\newtoks \everyfirstshipout
\newtoks \everylastshipout

%D End of run:

\newtoks \everybye
\newtoks \everygoodbye
\newtoks \everynotabene

%D Document

\newtoks \everysetupdocument
\newtoks \everyendoftextbody

\newtoks \everystarttext
\newtoks \everystoptext

%D Purity:

\newtoks \everyforgetall
\newtoks \everycleanupfeatures

\def\cleanupfeatures{\the\everycleanupfeatures}
\def\forgetall      {\the\everyforgetall}

%D Page building:

\newtoks \everybeforepagebody
\newtoks \everyafterpagebody

\let \everypagebody \everybeforepagebody % backward compatible

%D Multipass:

\newtoks \everybeforeutilityread
\newtoks \everyafterutilityread

%D Floats:

\newtoks \everyinsidefloat

%D Sectioning:

\newtoks \everyheadstart

%D Par building (experimental, used in xml <p> .. </p>)

\newtoks \everybeginofpar
\newtoks \everyendofpar
%newtoks \everyparflush

\def\bpar{\the\everybeginofpar\ignorespaces} % may interfere with \everypar
\def\epar{\ifhmode\removeunwantedspaces\the\everyendofpar\fi} % test prevents problems with \bpar\epar

%D Lists:

\newtoks \everylistentry
\newtoks \everysavesortkeys

%D Marks:

\newtoks \everymarking

%D Fonts:

\newtoks \everyfont
\newtoks \everyglobalbodyfont
\newtoks \everydefinedfont

\newevery \everybodyfont   \EveryBodyFont
\newevery \everyfontswitch \EveryFontSwitch

%D Math:

\newtoks \everybeforedisplayformula
\newtoks \everymathematics

\prependtoks \the\everymathematics \to \everymath
\prependtoks \the\everymathematics \to \everydisplay

%D Tables

\newtoks \everytable

%D State mess:

\newtoks \everypushsomestate
\newtoks \everypopsomestate

\def\pushsomestates{\the\everypushsomestate}
\def\popsomestates {\the\everypopsomestate }

%D More generic (used to be pushcolor etc)

\newtoks\everypushproperties
\newtoks\everypopproperties
\newtoks\everypopsplitproperties

\newtoks\everystarttextproperties
\newtoks\everystoptextproperties

\def\pushproperties     {\the\everypushproperties}
\def\popproperties      {\the\everypopproperties}
\def\popsplitproperties {\the\everypopsplitproperties}

\def\starttextproperties{\the\everystarttextproperties}
\def\stoptextproperties {\the\everystoptextproperties}

%D This is pretty important (esp since we now ignore shipouts).
%D Actually we should nil all writes, marks, specials.

\appendtoks \globallet\popproperties     \relax \to \everylastshipout
\appendtoks \globallet\popsplitproperties\relax \to \everylastshipout

%D \macros
%D   {defineinputmode,setinputmode}
%D
%D New. Some work needs to be done.

% not in mkiv

\def\defineinputmode[#1]{\@EA\newtoks\csname every#1inputmode\endcsname}
\def\setinputmode   [#1]{\the\executeifdefined{every#1inputmode}\emptytoks}

\defineinputmode [TEX]
\defineinputmode [XML]

\setinputmode    [TEX]

%D \macros
%D   {trialtypesetting}
%D
%D We disable trial typesetting in the output routine,
%D just to be sure.

\newif\iftrialtypesetting

\prependtoks \trialtypesettingfalse \to \everybeforepagebody

%D \macros
%D   {ifinpagebody,ifinsidecolumns,ifdoublesided,ifsinglesided}

\newif \ifinpagebody
\newif \ifinsidecolumns
\newif \ifdoublesided   \doublesidedfalse
\newif \ifsinglesided   \singlesidedtrue
\newif \ifinsidefloat
\newif \ifdoingblocks
\newif \ifgridsnapping

%D \macros
%D   {ifprocessingXML}
%D
%D We need this one even if no \XML\ is supported.

\newif\ifprocessingXML % old way

%D \macros
%D   {ifproductionrun}
%D
%D This boolean can be used to bypass certain
%D initializations.

\ifx\protectionlevel\undefined \newcount\protectionlevel \fi

\newif\ifproductionrun

\appendtoks \productionruntrue \to \everydump

\appendtoks \ifcase\protectionlevel\else\reportunprotection\fi \to \everydump

%D \macros
%D   {everyboxedcontent, ifboxedcontent,
%D    startboxedcontent, stopboxedcontent}
%D
%D This one is relatively new and will be used as a more
%D robust test for inner situations.

\newif  \ifboxedcontent
\newtoks\everyboxedcontent

\appendtoks \boxedcontenttrue \to \everyboxedcontent

\def\startboxedcontent{\bgroup\the\everyboxedcontent}
\let\stopboxedcontent  \egroup

%D \macros
%D   {fastmode,silentmode}
%D
%D These commands are obsolete.

\let\fastmode  \relax
\let\silentmode\relax

%D \macros
%D   {defineselector,setupselector}
%D
%D \starttyping
%D \defineselector[caption][max=2,n=2]
%D
%D \start
%D     \setupselector[caption][n=1]
%D     \placelist[figure][criterium=all]
%D \stop
%D
%D \starttext
%D     \placefigure
%D       {\select{caption}{zapf}{\input zapf \relax}}
%D       {}
%D \stoptext
%D \stoptyping

\def\defineselector{\dodoubleargument\dodefineselector}
\def\setupselector {\dodoubleargument\dosetupselector}

\def\dodefineselector[#1][#2]{\getparameters[\??sx#1][\c!max=2,\c!n=1,#2]}
\def\dosetupselector [#1][#2]{\getparameters[\??sx#1][#2]}

\unexpanded\def\select#1%
  {\filterfromnext
     {\executeifdefined{\??sx#1\c!max}1}
     {\executeifdefined{\??sx#1\c!n  }1}}

%D We store some original meanings, maybe in \type
%D {math-ini}.

\let\normalat   \at
\let\normalin   \in
\let\normalfrom \from
%let\normalover \over
\let\normalabout\about

%D Add-ons:

\let\startlayoutcomponent\gobbletwoarguments
\let\stoplayoutcomponent \relax

%D Concepts:

\chardef\conceptmode\zerocount

\def\doifconcepttracing
  {\ifnum\conceptmode>\plustwo
     \expandafter\firstofoneargument
   \else
     \expandafter\gobbleoneargument
   \fi}

\protect \endinput