summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/strc-tnt.mkiv
blob: 0b092b35fcccea3d21ea17db0bfc212b8d41a4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%D \module
%D   [       file=strc-tnt,
%D        version=2019.05.30, % based on older code
%D          title=\CONTEXT\ Structure Macros,
%D       subtitle=Text Notes,
%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.

\unprotect

%D \macros
%D   {definetextnote,setuptextnote}
%D
%D \startbuffer
%D \definetextnote
%D   [textnote]
%D
%D \startbuffer
%D Test test test \textnote [n=5] {alpha}. test test test test tets test test
%D \textnote [n=10] {beta}. Test test test test tets test test \textnote [n=12]
%D {gamma}. Test test test test tets test test \textnote [n=24] {delta}. Test test
%D test test test test \textnote {epsilon} test test \textnote [n=*] {zeta}.
%D \stopbuffer
%D
%D \blank {\setuptextnote[empty=yes]    \getbuffer\par} \blank
%D \blank {\setuptextnote[empty=number] \getbuffer\par} \blank
%D \blank {\setuptextnote[empty=none]   \getbuffer\par} \blank
%D \blank {                             \getbuffer\par} \blank
%D
%D \blank[2*big]
%D
%D \placenotes[textnote:note][criterium=text]
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\installcorenamespace{textnote}

\installcommandhandler \??textnote {textnote} \??textnote

\definebar
  [\v!textnote:\v!underbar]
  [\v!underbar]

\definenote
  [\v!textnote:\v!note]

\setuptextnote
  [\c!rule=\v!textnote:\v!underbar,
   \c!note=\v!textnote:\v!note,
   \c!n=10] % * will use the real space

\appendtoks
    \setuevalue{\currenttextnote}{\educ_textnote{\currenttextnote}}%
\to \everydefinetextnote

\unexpanded\def\educ_textnote#1%
  {\dontleavehmode
   \begingroup
   \def\currenttextnote{#1}%
   \dosingleempty\educ_textnote_indeed}

\def\educ_textnote_indeed[#1]#2% we could use setups but it's overkill
  {\iffirstargument\setupcurrenttextnote[#1]\fi
   \edef\p_n{\textnoteparameter\c!n}%
   \edef\p_empty{\textnoteparameter\c!empty}%
   \edef\currentbar{\textnoteparameter\c!rule}%
   \edef\currentnote{\textnoteparameter\c!note}%
   \ifx\p_n\wildcardsymbol
     \donefalse
     \ifx\p_empty\v!yes
       \donetrue
     \else\ifx\p_empty\v!number
       \donetrue
     \else\ifx\p_empty\v!none
       \donetrue
     \fi\fi\fi
     \ifdone
       \setupbar[\currentbar][\c!empty=\v!yes]%
     \fi
     \inlinebar[\currentbar]\bgroup
       \wordboundary#2%
       \ifx\p_empty\v!yes
         \setnotetext[\currentnote]{#2}%
       \else\ifx\p_empty\v!number
         \runninghbox{\resetbar\setnote[\currentnote]{#2}}%
       \else\ifx\p_empty\v!none
         \setupnote[\currentnote][\c!location=\v!none]%
         \runninghbox{\resetbar\setnote[\currentnote]{#2}}%
       \fi\fi\fi
     \egroup
   \else
     \inlinebar[\currentbar]\bgroup
       \scratchcounter\numexpr\p_n/\plustwo\relax
       \ifx\p_empty\v!yes
         \interwordspacesbefore\scratchcounter
         \setnotetext[\currentnote]{#2}%
         \interwordspacesafter\scratchcounter
       \else\ifx\p_empty\v!number
         \interwordspacesbefore\scratchcounter
         \zwnj\runninghbox{\resetbar\setnote[\currentnote]{#2}}\zwnj
         \interwordspacesafter\scratchcounter
       \else\ifx\p_empty\v!none
         \setupnote[\currentnote][\c!location=\v!none]%
         \interwordspacesbefore\scratchcounter
         \zwnj\runninghbox{\resetbar\setnote[\currentnote]{#2}}\zwnj
         \interwordspacesafter\scratchcounter
       \else
          #2%
       \fi\fi\fi
     \egroup
   \fi
   \endgroup}

\protect \endinput