%D \module %D [ file=anch-bar, %D version=2003.03.16, %D title=\CONTEXT\ Anchoring Macros, %D subtitle=Margin Bars and alike, %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 Anchoring Macros / Margin Bars} \unprotect %D We will implement a sidebar mechanism using the %D functionality from \type {core-pos}. %D %D \starttyping %D \definesidebar[whow][rulecolor=green,distance=] %D %D \input tufte \par %D \startsidebar %D \input tufte \par %D \input tufte \par %D \startsidebar[whow] %D \input tufte \par %D \input tufte \par %D \input tufte %D \stopsidebar \par %D \input tufte \par %D \input tufte %D \stopsidebar \par %D \input tufte \par %D \input tufte \par %D \startsidebar %D \input tufte \par %D \input tufte \par %D \input tufte \par %D \input tufte \par %D \input tufte %D \stopsidebar \par %D \input tufte \par %D \input tufte \par %D \startsidebar %D \input tufte %D \input tufte %D \input tufte %D \input tufte %D \input tufte %D \stopsidebar %D \stoptyping \installcorenamespace{sidebar} \installcommandhandler \??sidebar {sidebar} \??sidebar \newcount\c_anch_sidebars_n \newdimen\c_anch_sidebars_distance % \setupMPvariables % [mpos:sidebar] % [linecolor=red, % linewidth=2pt, % distance=5pt] \setupsidebar [\c!rulethickness=2pt, \c!rulecolor=\s!black, \c!alternative=0, \c!topoffset=0pt, \c!bottomoffset=0pt, \c!distance=.5\bodyfontsize] \let\setupsidebars\setupsidebar \unexpanded\def\startsidebar {\dosingleempty\anch_sidebars_start} \def\anch_sidebars_start[#1]% {\bgroup \def\currentsidebar{#1}% \dontleavehmode \global\advance\c_anch_sidebars_n\plusone \advance\c_anch_sidebars_distance\sidebarparameter\c!distance \startpositionoverlay{text-1}% \normalexpanded{\setMPpositiongraphicrange % maybe expand in definition {b:sidebar:\the\c_anch_sidebars_n}% {e:sidebar:\the\c_anch_sidebars_n}% {mpos:sidebar}% {self=sidebar:\the\c_anch_sidebars_n, linewidth=\sidebarparameter\c!rulethickness, linecolor=\sidebarparameter\c!rulecolor, alternative=\sidebarparameter\c!alternative, topoffset=\sidebarparameter\c!topoffset, bottomoffset=\sidebarparameter\c!bottomoffset, distance=\the\c_anch_sidebars_distance}}% \stoppositionoverlay \bpos{sidebar:\the\c_anch_sidebars_n}} \unexpanded\def\stopsidebar {\removelastspace \epos{sidebar:\the\c_anch_sidebars_n} \carryoverpar\egroup} %D Let's keep this nice and simple (okay, we could pass the 6 variables in %D one lua call). \startMPpositionmethod{mpos:sidebar} \startMPpositiongraphic{mpos:sidebar}{linecolor,linewidth,distance,alternative}% if unknown context_apos : input mp-apos.mpiv ; fi ; anch_sidebars_draw ( \MPp\MPbself,\MPp\MPeself,\MPy\MPbself,\MPy\MPeself,\MPh\MPbself,\MPd\MPeself, \MPx{\textanchor},\MPy{\textanchor},\MPw{\textanchor},\MPh{\textanchor}, \MPvar{alternative},\MPvar{distance},\MPvar{linewidth},\MPvar{linecolor}, \MPvar{topoffset}, \MPvar{bottomoffset} ) ; \stopMPpositiongraphic \MPpositiongraphic{mpos:sidebar}{}% \stopMPpositionmethod %D We now reimplement the margin rules handler defined in %D \type {core-rul}: %D %D \setupmarginrules[level=5] %D %D \startmarginrule[1] %D First we set the level at~5. Next we typeset this first %D paragraph as a level~1 one. As expected no rule show up. %D \stopmarginrule %D %D \startmarginrule[5] %D The second paragraph is a level~5 one. As we can see here, %D the marginal rule gets a width according to its level. %D \stopmarginrule %D %D \startmarginrule[8] %D It will of course be no surprise that this third paragraph %D has a even thicker margin rule. This behavior can be %D overruled by specifying the width explictly. %D \stopmarginrule \definesidebar [\v!margin] [\c!rulethickness=\@@karulethickness, \c!distance=\dimexpr\leftmargindistance-\@@karulethickness/2\relax] \definecomplexorsimple\startmarginrule \def\simplestartmarginrule {\complexstartmarginrule[1]} \def\complexstartmarginrule[#1]% {\bgroup \ifnum#1<\@@kalevel\relax \let\stopmarginrule\egroup \else \def\@@kadefaultwidth{#1}% \let\stopmarginrule\dostopmarginrule \normalexpanded{\startsidebar[\v!margin]}% why expanded \fi} \def\dostopmarginrule {\stopsidebar \egroup} \protect \endinput