summaryrefslogtreecommitdiff
path: root/tex/context/base/node-rul.mkiv
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/node-rul.mkiv')
-rw-r--r--tex/context/base/node-rul.mkiv202
1 files changed, 202 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..246e8d222
--- /dev/null
+++ b/tex/context/base/node-rul.mkiv
@@ -0,0 +1,202 @@
+%D \module
+%D [ file=node-bar,
+%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.
+
+\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]
+
+\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}
+
+\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}%
+ \unexpanded\setvalue{#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(
+ \barparameter\c!method,
+ \barparameter\c!offset,
+ "\barparameter\c!continue",
+ \barparameter\c!dy,
+ \barparameter\c!rulethickness,
+ "\barparameter\c!unit",
+ "\barparameter\c!order",
+ \barparameter\c!max,
+ \ifdone\the\attribute\colormodelattribute\else0\fi,
+ \ifdone\the\attribute\colorattribute\else0\fi,
+ \ifdone\the\attribute\transparencyattribute\else0\fi)}}%
+ \setevalue{\??on#1:a}{\the\scratchcounter}}
+
+\let\doredefinebar\dodefinebarindeed
+
+\def\doruled
+ {\ctxlua{nodes.rules.enable()}%
+ \glet\doruled\doruledindeed
+ \doruledindeed}
+
+\def\doruledindeed#1%
+ {\groupedcommand{\dodoruled{#1}}\relax}
+
+\def\dodoruled#1%
+ {\advance\csname\??on:#1:c\endcsname\plusone
+ \scratchcounter\csname\??on:#1:c\endcsname
+ \dosetattribute{ruled}{\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
+
+\unexpanded\def\pushbar[#1]%
+ {\global\advance\currentbarnesting\plusone
+ \setevalue{\??on:s:\number\currentbarnesting}{\dogetattribute{ruled}}% stack
+ \dodoruled{#1}}
+
+\unexpanded\def\popbar
+ {\dosetattribute{ruled}{\getvalue{\??on:s:\number\currentbarnesting}}%
+ \global\advance\currentbarnesting\minusone}
+
+\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]
+\definebar[\v!underbar] [\c!method=1,\c!dy=-0.4,\c!offset=-0.3]
+\definebar[\v!overbar] [\c!method=1,\c!dy= 0.4,\c!offset= 1.8]
+
+\definebar[\v!overstrikes] [\v!overstrike] [\c!continue=\v!yes]
+\definebar[\v!underbars] [\v!underbar] [\c!continue=\v!yes]
+\definebar[\v!overbars] [\v!overbar] [\c!continue=\v!yes]
+
+% 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
+
+\def\setupunderbar[#1]% too incompatible for the moment
+ {}
+
+\protect \endinput
+
+% obsolete:
+
+\setupunderbar
+ [\c!alternative=a,
+ \c!rulethickness=\linewidth,
+ \c!bottomoffset=1.5pt,
+ \c!topoffset=2.5pt,
+ \c!rulecolor=]