java-ini.mkxl /size: 4272 b    last modification: 2021-10-28 13:51
1%D \module
2%D   [       file=java-ini,
3%D        version=1998.01.30,
4%D          title=\CONTEXT\ JavaScript Macros,
5%D       subtitle=Initialization,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt JavaScript Macros / Initialization}
15
16\registerctxluafile{java-ini}{}
17
18\unprotect
19
20%D \macros
21%D   {JS*}
22%D
23%D Because \JAVASCRIPT's are activated by the user, for instance by activating on a
24%D button, their support is closely related to the referencing mechanism.
25%D Integration takes place by
26%D
27%D \starttyping
28%D \goto{calculate total}[Sum()]
29%D \stoptyping
30%D
31%D The \type {()} classify this as a script. If they are absent, the keyword is
32%D treated as a normal reference. One can pass arguments to such a script by saying:
33%D
34%D \starttyping
35%D \goto{calculate total}[Sum(1.5,2.3)]
36%D \stoptyping
37
38%D \macros
39%D   {startJScode}
40%D
41%D A piece of \JAVASCRIPT\ code is defined by saying:
42%D
43%D \starttyping
44%D \startJScode{name}
45%D   name = 4 ;
46%D \stopJScode
47%D \stoptyping
48%D
49%D This assumes uses no preamble or presumes that the preamble is always loaded, the
50%D next definition also tells \CONTEXT\ to actually include the preamble needed.
51%D
52%D \starttyping
53%D \startJScode{uses} used {later}
54%D   uses = 6 ;
55%D \stopJScode
56%D \stoptyping
57%D
58%D \macros
59%D   {startJSpreamble}
60%D
61%D One can define insert \JAVASCRIPT\ code at the document level by using:
62%D
63%D \starttyping
64%D \startJSpreamble{oeps}
65%D   oeps = 1 ;
66%D \stopJSpreamble
67%D \stoptyping
68%D
69%D which is the same as:
70%D
71%D \starttyping
72%D \startJSpreamble{now} used now
73%D   now = 2 ;
74%D \stopJSpreamble
75%D \stoptyping
76%D
77%D while the next definition is only included when actually used.
78%D
79%D \starttyping
80%D \startJSpreamble{later} used later
81%D   later = 3 ;
82%D \stopJSpreamble
83%D \stoptyping
84%D
85%D This command may be used more that once, but always before the first page is
86%D shipped out.
87%D
88%D \macros
89%D   {setJSpreamble, addtoJSpreamble}
90%D
91%D In addition to the previous preamble definitions, we can set a preamble \quote
92%D {in||line} and add tokens to a preamble.
93%D
94%D \macros
95%D   {useJSpreamblenow}
96%D
97%D This macro can be used to force inclusion of postponed \JAVASCRIPT\ preambles.
98
99\def\m_java_escape_u{\letterbackslash u}
100
101\permanent\protected\def\startJScode
102  {\begingroup
103   \obeyluatokens
104   \enforced\let\u\m_java_escape_u
105   \java_start_code}
106
107\def\java_start_code#1\stopJScode
108  {\normalexpanded{\endgroup\clf_storejavascriptcode{#1}}}
109
110\permanent\protected\lettonothing\stopJScode
111
112\permanent\protected\def\startJSpreamble
113  {\begingroup
114   \obeyluatokens
115   \enforced\let\u\m_java_escape_u
116   \java_start_preamble}
117
118\def\java_start_preamble#1\stopJSpreamble
119  {\normalexpanded{\endgroup\clf_storejavascriptpreamble{#1}}}
120
121\permanent\protected\lettonothing\stopJSpreamble
122
123\permanent\protected\def\setJSpreamble  #1#2{\clf_setjavascriptpreamble  {#1}{#2}}
124\permanent\protected\def\addtoJSpreamble#1#2{\clf_addtojavascriptpreamble{#1}{#2}}
125
126%D \macros
127%D   {useJSscripts}
128%D
129%D In due time, users will build their collections of scripts, which can be used
130%D (loaded) when applicable. Although not all public, we will provide some general
131%D purpose scripts, collected in files with names like \type {java-...}. One can
132%D load these scripts with \type {\useJSscripts}, like:
133%D
134%D \starttyping
135%D \useJSscripts[fld]
136%D \stoptyping
137%D
138%D The not so complicated implementation of this macro is:
139
140\permanent\tolerant\protected\def\useJSscripts[#1]#*[#2]%
141  {\clf_usejavascriptscripts {#1}%  two steps as this one calls tex code
142   \clf_usejavascriptpreamble{#2}}% so this one comes later
143
144\permanent\tolerant\protected\def\useJSpreamble[#1]%
145  {\clf_usejavascriptpreamble{#1}}% so this one comes later
146
147%D Here:
148
149\definefilesynonym[java-imp-fld.mkiv] [java-imp-fields.mkiv]
150\definefilesynonym[java-imp-stp.mkiv] [java-imp-steps.mkiv]
151\definefilesynonym[java-imp-fil.mkiv] [java-imp-print.mkiv]
152\definefilesynonym[java-imp-rhh.mkiv] [java-imp-highlight.mkiv]
153\definefilesynonym[java-imp-exa.mkiv] [java-imp-example.mkiv]
154
155\protect \endinput
156