summaryrefslogtreecommitdiff
path: root/tex/context/base/node-rul.mkiv
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
committerMarius <mariausol@gmail.com>2010-07-04 15:32:09 +0300
commit85b7bc695629926641c7cb752fd478adfdf374f3 (patch)
tree80293f5aaa7b95a500a78392c39688d8ee7a32fc /tex/context/base/node-rul.mkiv
downloadcontext-85b7bc695629926641c7cb752fd478adfdf374f3.tar.gz
stable 2010-05-24 13:10
Diffstat (limited to 'tex/context/base/node-rul.mkiv')
-rw-r--r--tex/context/base/node-rul.mkiv343
1 files changed, 343 insertions, 0 deletions
diff --git a/tex/context/base/node-rul.mkiv b/tex/context/base/node-rul.mkiv
new file mode 100644
index 000000000..1270eb81d
--- /dev/null
+++ b/tex/context/base/node-rul.mkiv
@@ -0,0 +1,343 @@
+%D \module
+%D [ file=node-rul,
+%D version=2009.11.03, % 1995.10.10,
+%D title=\CONTEXT\ Core Macros,
+%D subtitle=Bars,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+% todo: ex and and em traveling with attribute
+
+\writestatus{loading}{ConTeXt Core Macros / Bars}
+
+%D The name of this file might change.
+
+%D \macros
+%D {underbar,underbars,
+%D overbar,overbars,
+%D overstrike,overstrikes,
+%D setupbar}
+%D
+%D In the rare case that we need undelined words, for instance
+%D because all font alternatives are already in use, one can
+%D use \type{\underbar} and \type{\overstrike} and their plural
+%D forms.
+%D
+%D \startbuffer
+%D \underbars{drawing \underbar{bars} under words is a typewriter leftover}
+%D \overstrikes{striking words makes them \overstrike{unreadable} but
+%D sometimes even \overbar{top lines} come into view.}
+%D \stopbuffer
+%D
+%D \typebuffer
+%D
+%D \startvoorbeeld
+%D \startlines
+%D \getbuffer
+%D \stoplines
+%D \stopvoorbeeld
+%D
+%D The next macros are derived from the \PLAIN\ \TEX\ one, but
+%D also supports nesting. The \type{$} keeps us in horizontal
+%D mode and at the same time applies grouping.
+%D
+%D \showsetup{underbar}
+%D \showsetup{underbars}
+%D \showsetup{overbar}
+%D \showsetup{overbars}
+%D \showsetup{overstrike}
+%D \showsetup{overstrikes}
+%D
+%D \showsetup{setupunderbar}
+
+\unprotect
+
+%definesystemattribute[ruled]
+%definesystemattribute[shifted]
+
+\registerctxluafile{node-rul}{1.001}
+
+\newtoks\checkalldefinedbars
+
+\def\barparameter #1{\csname\dobarparameter\currentbar#1\endcsname}
+\def\dobarparameter #1#2{\ifcsname\??on#1#2\endcsname\??on#1#2\else\expandafter\dobarparentparameter\csname\??on#1\s!parent\endcsname#2\fi}
+\def\dobarparentparameter#1#2{\ifx#1\relax\s!empty\else\dobarparameter#1#2\fi}
+
+\unexpanded\def\definebar
+ {\dotripleempty\dodefinebar}
+
+\def\dodefinebar[#1][#2][#3]%
+ {\ifthirdargument
+ \getparameters[\??on#1][\s!parent=#2,#3]%
+ \else
+ \getparameters[\??on#1][\s!parent=,#2]%
+ \fi
+ %
+ %\setvalue{\??on:#1}{0}%
+ %
+ \ifcsname\??on:#1:c\endcsname
+ \csname\??on:#1:c\endcsname\zerocount
+ \else
+ \expandafter\newcount\csname\??on:#1:c\endcsname
+ \fi
+ \normalexpanded{\checkalldefinedbars{\noexpand\doredefinebar{#1}\the\checkalldefinedbars}}%
+ \dodefinebarindeed{#1}%
+ \setuvalue{#1}{\doruled{#1}}}
+
+\def\dodefinebarindeed#1%
+ {\bgroup
+ \def\currentbar{#1}%
+ \doifsomethingelse{\barparameter\c!color}
+ {\donetrue\colored[\barparameter\c!color]}
+ {\donefalse}%
+ \normalexpanded
+ {\egroup
+ \scratchcounter\ctxlua{nodes.rules.define {
+ method = \barparameter\c!method,
+ offset = \barparameter\c!offset,
+ continue = "\barparameter\c!continue",
+ dy = \barparameter\c!dy,
+ rulethickness = \barparameter\c!rulethickness,
+ unit = "\barparameter\c!unit",
+ order = "\barparameter\c!order",
+ max = \barparameter\c!max,
+ ma = \ifdone\the\attribute\colormodelattribute \else0\fi,
+ ca = \ifdone\the\attribute\colorattribute \else0\fi,
+ ta = \ifdone\the\attribute\transparencyattribute\else0\fi
+ }}}%
+ \setevalue{\??on#1:a}{\the\scratchcounter}}
+
+\let\doredefinebar\dodefinebarindeed
+
+\def\doruled#1%
+ {\groupedcommand{\dodoruled{#1}}\relax}
+
+\def\dodoruled
+ {\ctxlua{nodes.rules.enable()}%
+ \glet\dodoruled\dodoruledindeed
+ \dodoruled}
+
+\def\dodoruledindeed#1%
+ {\advance\csname\??on:#1:c\endcsname\plusone
+ \scratchcounter\csname\??on:#1:c\endcsname
+ \attribute\ruledattribute\numexpr1000*\scratchcounter
+ +\csname\??on#1\ifcsname\??on#1:\number\scratchcounter\s!parent\endcsname:\number\scratchcounter\fi:a\endcsname}
+
+% ungrouped
+
+\unexpanded\def\startbar[#1]%
+ {\begingroup
+ \dodoruled{#1}}
+
+\unexpanded\def\stopbar
+ {\endgroup}
+
+\newcount\currentbarnesting % todo: same as colors
+
+\unexpanded\def\pushbar[#1]%
+ {\global\advance\currentbarnesting\plusone
+ \expandafter\edef\csname\??on:s:\number\currentbarnesting\endcsname
+ {\attribute\ruledattribute\the\attribute\ruledattribute}% stack
+ \dodoruled{#1}}
+
+\unexpanded\def\popbar
+ {\csname\??on:s:\number\currentbarnesting\endcsname
+ \global\advance\currentbarnesting\minusone}
+
+\unexpanded\def\setupbars
+ {\dodoubleempty\dosetupbars}
+
+\def\dosetupbars[#1][#2]% not that efficient
+ {\ifsecondargument
+ \getparameters[\??on#1][#2]%
+ \dodefinebarindeed{#1}%
+ \else
+ \getparameters[\??on][#1]%
+ \the\checkalldefinedbars
+ \fi}
+
+\setupbars
+ [\c!method=0, % new: 0=center nested, 1=stack nested
+ \c!continue=\v!no,
+ \c!offset=0, % upwards, replaces: topoffset bottomoffset
+ \c!dy=0,
+ \c!max=3,
+ \c!rulethickness=.1,
+ \c!order=\v!foreground,
+ \c!unit=ex, % so now we are relative
+ \c!color=] % replaces: rulecolor
+
+% \definebar[touchbar] [\c!method=0,\c!dy=-0.4,\c!offset=-0.0]
+% \definebar[touchbars] [touchbar] [\c!continue=\v!yes]
+
+\definebar[\v!overstrike] [\c!method=0,\c!dy= 0.4,\c!offset= 0.5,\c!continue=\v!yes]
+\definebar[\v!underbar] [\c!method=1,\c!dy=-0.4,\c!offset=-0.3,\c!continue=\v!yes]
+\definebar[\v!overbar] [\c!method=1,\c!dy= 0.4,\c!offset= 1.8,\c!continue=\v!yes]
+
+\definebar[\v!overstrikes] [\v!overstrike] [\c!continue=\v!no]
+\definebar[\v!underbars] [\v!underbar] [\c!continue=\v!no]
+\definebar[\v!overbars] [\v!overbar] [\c!continue=\v!no]
+
+% we want these always so ...
+
+\expandafter\let\expandafter\overstrike \csname\v!overstrike \endcsname
+\expandafter\let\expandafter\underbar \csname\v!underbar \endcsname
+\expandafter\let\expandafter\overbar \csname\v!overbar \endcsname
+\expandafter\let\expandafter\overstrikes\csname\v!overstrikes\endcsname
+\expandafter\let\expandafter\underbars \csname\v!underbars \endcsname
+\expandafter\let\expandafter\overbars \csname\v!overbars \endcsname
+
+\unexpanded\def\setupunderbar[#1]% too incompatible for the moment
+ {}
+
+%D This will move: (a bit duplicated)
+
+\newtoks\checkalldefinedshifts
+
+\def\shiftparameter #1{\csname\doshiftparameter\currentshift#1\endcsname}
+\def\shiftparameterhash#1{\doshiftparameterhash{\??ra\currentshift}#1}
+
+\def\doshiftparameter #1#2{\ifcsname\??ra#1#2\endcsname\??ra#1#2\else\expandafter\doshiftparentparameter\csname\??ra#1\s!parent\endcsname#2\fi}
+\def\doshiftparameterhash#1#2{\ifcsname#1#2\endcsname#1\else\expandafter\doshiftparentparameterhash\csname#1\s!parent\endcsname#2\fi}
+
+\def\doshiftparentparameter #1#2{\ifx#1\relax\s!empty\else\doshiftparameter #1#2\fi}
+\def\doshiftparentparameterhash#1#2{\ifx#1\relax \else\doshiftparameterhash#1#2\fi}
+
+\def\dosetshiftattributes#1#2% style color
+ {\edef\fontattributehash {\shiftparameterhash#1}%
+ \edef\colorattributehash{\shiftparameterhash#2}%
+ \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash #1\fi
+ \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash#2\fi}
+
+\unexpanded\def\defineshift
+ {\dotripleempty\dodefineshift}
+
+\def\dodefineshift[#1][#2][#3]%
+ {\ifthirdargument
+ \getparameters[\??ra#1][\s!parent=#2,#3]%
+ \else
+ \getparameters[\??ra#1][\s!parent=,#2]%
+ \fi
+ %
+ %\setvalue{\??ra:#1}{0}%
+ %
+ \ifcsname\??ra:#1:c\endcsname
+ \csname\??ra:#1:c\endcsname\zerocount
+ \else
+ \expandafter\newcount\csname\??ra:#1:c\endcsname
+ \fi
+ \normalexpanded{\checkalldefinedshifts{\noexpand\doredefineshift{#1}\the\checkalldefinedshifts}}%
+ \dodefineshiftindeed{#1}%
+ \setuvalue{#1}{\doshifted{#1}}}
+
+\def\dodefineshiftindeed#1%
+ {\bgroup
+ \def\currentshift{#1}%
+ \normalexpanded
+ {\egroup
+ \scratchcounter\ctxlua{nodes.shifts.define {
+ method = \shiftparameter\c!method,
+ continue = "\shiftparameter\c!continue",
+ dy = \shiftparameter\c!dy,
+ unit = "\shiftparameter\c!unit",
+ }}}%
+ \setevalue{\??ra#1:a}{\the\scratchcounter}}
+
+\let\doredefineshift\dodefineshiftindeed
+
+\def\doshifted#1%
+ {\groupedcommand{\dodoshifted{#1}}\relax}
+
+\def\dodoshifted
+ {\ctxlua{nodes.shifts.enable()}%
+ \glet\dodoshifted\dodoshiftedindeed
+ \dodoshifted}
+
+% \def\dodoshiftedindeed#1%
+% {\def\currentshift{#1}%
+% \advance\csname\??ra:#1:c\endcsname\plusone
+% \scratchcounter\csname\??ra:#1:c\endcsname
+% \attribute\shiftedattribute\numexpr1000*\scratchcounter
+% +\csname\??ra#1\ifcsname\??ra#1:\number\scratchcounter\s!parent\endcsname:\number\scratchcounter\fi:a\endcsname
+% \setupalign[\shiftparameter\c!align]%
+% \dosetshiftattributes\c!style\c!color}
+
+\def\dostartisolation{\char0 }
+\def\dostopisolation {\char0 }
+\def\doisolator {\char0 }
+
+\def\doisolatedgroupedalign#1#2%
+ {\groupedcommand
+ {\begingroup\dostartisolation\begingroup#1}
+ {#2\endgroup\dostopisolation\endgroup}}
+
+\def\dosetupisolatedalign#1%
+ {\doisolator
+ \setupalign[#1]\relax}
+
+\def\dodoshiftedindeed#1%
+ {\def\currentshift{#1}%
+ \advance\csname\??ra:#1:c\endcsname\plusone
+ \scratchcounter\csname\??ra:#1:c\endcsname
+ \attribute\shiftedattribute\numexpr1000*\scratchcounter
+ +\csname\??ra#1\ifcsname\??ra#1:\number\scratchcounter\s!parent\endcsname:\number\scratchcounter\fi:a\endcsname
+ \dosetshiftattributes\c!style\c!color
+ \dosetupisolatedalign{\shiftparameter\c!align}}
+
+\def\doshifted#1%
+ {\doisolatedgroupedalign{\dodoshifted{#1}}{}}
+
+\unexpanded\def\startshift[#1]%
+ {\begingroup
+ \dodoshifted{#1}}
+
+\unexpanded\def\stopshift
+ {\endgroup}
+
+\unexpanded\def\setupshifts
+ {\dodoubleempty\dosetupshifts}
+
+\def\dosetupshifts[#1][#2]% not that efficient
+ {\ifsecondargument
+ \getparameters[\??ra#1][#2]%
+ \dodefineshiftindeed{#1}%
+ \else
+ \getparameters[\??ra][#1]%
+ \the\checkalldefinedshifts
+ \fi}
+
+\setupshifts
+ [\c!method=0,
+ \c!continue=\v!no,
+ \c!dy=0,
+ \c!unit=ex,
+ \c!align=,
+ \c!style=,
+ \c!color=]
+
+\def\v!shiftup {shiftup}
+\def\v!shiftdown{shiftdown}
+
+\defineshift [\v!shiftup] [\c!method=0,\c!dy=-1,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]
+\defineshift [\v!shiftdown] [\c!method=1,\c!dy=.3,\c!unit=ex,\c!continue=\v!yes,\c!style=\txx,\c!color=]
+
+% we want these always so ...
+
+\expandafter\let\expandafter\shiftup \csname\v!shiftup \endcsname
+\expandafter\let\expandafter\shiftdown \csname\v!shiftdown \endcsname
+
+\protect \endinput
+
+% obsolete:
+
+\setupunderbar
+ [\c!alternative=a,
+ \c!rulethickness=\linewidth,
+ \c!bottomoffset=1.5pt,
+ \c!topoffset=2.5pt,
+ \c!rulecolor=]