]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/mathml_editor/doc/spec.tex
* added introduction + structure for next sections
[helm.git] / helm / DEVEL / mathml_editor / doc / spec.tex
1 \documentclass[10pt]{article}
2
3 \usepackage{a4wide}
4 \usepackage{palatino}
5 \usepackage{euler}
6 \usepackage{amssymb}
7 \usepackage{stmaryrd}
8
9 \title{\EdiTeX: a MathML Editor Based on \TeX{} Syntax\\\small Description and Formal Specification}
10 \author{Paolo Marinelli\\Luca Padovani\\\small\{{\tt pmarinel},{\tt lpadovan}\}{\tt @cs.unibo.it}\\\small Department of Computer Science\\\small University of Bologna}
11 \date{}
12
13 \newcommand{\EdiTeX}{Edi\TeX}
14
15 \newcommand{\tmap}[1]{\llbracket#1\rrbracket}
16 \newcommand{\tadvance}{\vartriangle}
17 \newcommand{\tnext}{\rhd}
18 \newcommand{\G}{\texttt{g}}
19 \newcommand{\PNODE}{\texttt{p}}
20 \newcommand{\SNODE}{\texttt{s}}
21 \newcommand{\INODE}{\texttt{i}}
22 \newcommand{\NNODE}{\texttt{n}}
23 \newcommand{\ONODE}{\texttt{o}}
24 \newcommand{\CNODE}{\texttt{c}}
25 \newcommand{\TABLE}{\texttt{table}}
26 \newcommand{\SP}{\texttt{sp}}
27 \newcommand{\SB}{\texttt{sb}}
28 \newcommand{\CELL}{\texttt{cell}}
29 \newcommand{\ROW}{\texttt{row}}
30 \newcommand{\SLDROP}{\blacktriangleleft}
31 \newcommand{\SLDSCRIPT}{\blacktriangleleft_{s}}
32 \newcommand{\NLDROP}{\vartriangleleft}
33 \newcommand{\RGROUP}{\vartriangleleft_{rg}}
34 \newcommand{\NLDGP}{\vartriangleleft_{g}}
35 \newcommand{\NLDSCRIPT}{\vartriangleleft_{s}}
36 \newcommand{\NLDMACRO}{\vartriangleleft_{c}}
37 \newcommand{\NLDTABLE}{\vartriangleleft_{t}}
38
39 \begin{document}
40
41 \maketitle
42
43 \section{Introduction}
44
45 MathML~\cite{MathML1,MathML2,MathML2E} is an XML application for the
46 representation of mathematical expressions. As most XML applications,
47 MathML is unsuitable to be hand-written, except for the simplest
48 cases, because of its verbosity. In fact, the MathML specification
49 explicitly states that
50 \begin{quote}
51 ``While MathML is human-readable, it is anticipated that, in all but
52 the simplest cases, authors will use equation editors, conversion
53 programs, and other specialized software tools to generate MathML''
54 \end{quote}
55
56 The statement about human readability of MathML is already too strong,
57 as the large number of mathematical symbols, operators, and
58 diacritical marks that are used in mathematical notation cause MathML
59 documents to make extensive use of Unicode characters that typically
60 are not in the ``visible'' range of common text editors. Such
61 characters may appear as entity references, whose name indicates
62 somehow the kind of symbol used, or character references or they are
63 directly encoded in the document encoding scheme (for instance,
64 UTF-8).
65
66 It is thus obvious that authoring MathML documents assumes the
67 assistance of dedicated tools. As of today, such tools can be
68 classified into two main categories:
69 \begin{enumerate}
70   \item WYSIWYG (What You See Is What You Get) editors that allow the
71     author to see the formatted document on the screen as it is
72     composed;
73   \item conversion tools that generate MathML markup from different
74     sources, typically other markup languages for scientific
75     documents, such as \TeX.
76 \end{enumerate}
77
78 While the former tools are certainly more appealing, especially to the
79 unexperienced user, as they give a direct visual feedback, the
80 existance of tools in the second category takes into account the large
81 availability of existing documents in \TeX{} format, and also the fact
82 that experienced or ``lazy'' users may continue to prefer the use of a
83 markup language other than MathML for editing, and generate MathML
84 only as a final step of the authoring process. The ``laziness'' is not
85 really intended as a way of being reluctant towards a new technology,
86 but rather as a justified convincement that WYSIWYG editors are ``nice
87 to look at'' but after all they may slow down the authoring process.
88 WYSIWYG editors often involve the use of menus, palettes of symbols,
89 and, in general, an extensive use of the pointing device (the mouse)
90 for completing most operations. The use of shortcuts is of little
91 help, as it implies very soon a challenging exercise for the fingers
92 and the mind. Moreover, authors \emph{cannot improve} their authoring
93 speed with time.  On the other side, the gap between the syntax of any
94 markup language for mathematics and mathematical notation may be
95 relevant, especially for large, non-trivial formulas and authoring is
96 a re-iterated process in which the author repeadtedly types the markup
97 in the editor, compiles, and looks at the result inside a pre-viewer.
98
99 \EdiTeX{} tries to synthesize the ``best of both worlds'' in a single
100 tool. The basic idea is that of creating a WYSIWYG editor in which
101 editing is achieved by typing \TeX{} markup as the author would do in
102 a text editor. The \TeX{} markup is tokenized and parsed on-the-fly
103 and a corresponding MathML representation is created and
104 displayed. This way, the author can see the rendered document as it
105 changes. The advantages of this approach can be summarized as follows:
106 \begin{itemize}
107   \item the document is rendered concurrently with the editing, the
108     user has an immediate feedback hence it is easier to spot errors;
109   \item the author types in a concrete (and likely familiar) syntax
110     improving the editing speed;
111   \item the usual WYSIWYG mechanisms are still available. In
112     particular, it is possible to select \emph{visually} a fragment of
113     the document that needs re-editing, or that was left behind for
114     subsequent editing.
115 \end{itemize}
116
117 \paragraph{The Name of the Game:} there is no reference to MathML in
118 the name ``\EdiTeX.'' In fact, the architecture of the editor is not
119 tied to MathML markup. Although we focus on MathML editing, by
120 changing a completely modularized component of the editor it is
121 virtually possible to generate any other markup language.
122
123 \paragraph{Acknowledgments.} Stephen M. Watt and Igor Rodionov for
124 their work on the \TeX{} to MathML conversion tool; Stan Devitt for an
125 illuminating discussion about the architecture of \TeX{} to XML
126 conversion tools; Claudio Sacerdoti Coen for the valuable feedback and
127 uncountable bug reports.
128
129 \section{Architecture}
130
131 \section{Customization}
132
133 \subsection{Short and Long Identifiers}
134
135 \subsection{The Dictionary}
136
137 \subsection{Stylesheets and Trasformations}
138
139 \subsection{Rendering}
140
141 \section{XML Representation of \TeX{} Markup}
142
143 \section{Tokens}
144
145 The following tokens are defined:
146
147 \begin{tabular}{lllp{0.5\textwidth}}
148   \textbf{\TeX{}} & \textbf{Notation} & \textbf{Node} & \textbf{Description} \\
149 \hline
150   \verb+{+ & $\mathrm{begin}$ & \texttt{g} & Beginning of a group \\
151   \verb+}+ & $\mathrm{end}$ & & End of a group \\
152   \verb+$+ & $\$$ & \texttt{math} & Math shift \\ %$ \\
153   & &  & End-of-line \\
154   \verb+#+$i$ & $p(i)$ & \texttt{p} & Parameter \\
155   \verb+^+ & $\uparrow$ & \texttt{sp} & Superscript \\
156   \verb+_+ & $\downarrow$ & \texttt{sb} & Subscript \\
157   & $\square$ & & Space-like character that can be ignored \\
158   & $s$ & \texttt{s} & Space-like character that may be significant \\
159   letter & $i(v)$ & \texttt{i} & Identifier $v$ \\
160   digit & $n(v)$ & \texttt{n} & Number $v$ \\
161   other & $o(v)$ & \texttt{o} & Other character or operator $v$ \\
162   \verb+~+ & $\sim$ & & Active character \\
163   \verb+%+ & $\%$ & & Comment \\
164   control & $c(v)\langle\alpha_1,\dots,\alpha_n\rangle$ & \texttt{c} & 
165     Control sequence $v$ that expects the $\alpha_1,\dots,\alpha_n$ sequence of tokens. \\
166   backspace & $\vartriangleleft$ & & \\
167   backspace & $\blacktriangleleft$ & & \\
168 \end{tabular}
169
170 %% Some tokens are mapped directly into nodes of the TML tree. The following functions shows
171 %% the mapping:
172
173 \begin{tabular}{r@{\quad$=$\quad}l}
174   $\tmap{\{}$ & \verb+g+ \\
175   $\tmap{p(i)}$ & \verb+p[@index=+$i$\verb+]+ \\
176   $\tmap{p_l(i)}$ & \verb+p[@index=+$i$\verb+][@left-open='1']+ \\
177   $\tmap{p_r(i)}$ & \verb+p[@index=+$i$\verb+][@right-open='1']+ \\
178   $\tmap{s}$ & \verb+s+ \\
179   $\tmap{\uparrow}$ & \verb+sp+ \\
180   $\tmap{\downarrow}$ & \verb+sb+ \\
181   $\tmap{i(v)}$ & \verb+i[@value=+$v$\verb+]+ \\
182   $\tmap{n(v)}$ & \verb+n[@value=+$v$\verb+]+ \\
183   $\tmap{o(v)}$ & \verb+o[@value=+$v$\verb+]+ \\
184   $\tmap{c(v)\langle\alpha_1,\dots,\alpha_n\rangle}$ & \verb+c[@name=+$v$\verb+][^+$\tmap{\alpha_1}\cdots\tmap{\alpha_n}$\verb+$]+\\
185 \end{tabular}
186 %$
187
188 %% \section{Description and Semantics of the Pattern Language}
189
190 %% \begin{eqnarray*}
191 %%   \mathit{NodeTest} & ::= & \mathtt{*} \\
192 %%   & | & \mathit{ElementType} \\
193 %%   & | & \mathtt{<}~\mathit{ElementTypePattern}~\mathtt{>} \\[1ex]
194 %%   \mathit{ElementTypePattern} & ::= & \mathtt{*} \\
195 %%   & | & \mathit{ElementType}~(\mathtt{|}~\mathit{ElementType})^* \\
196 %%   & | & \mathtt{!}\mathit{ElementType}~(\mathtt{|}~\mathit{ElementType})^*\\[1ex]
197 %%   \mathit{NodePattern} & ::= & \mathit{NodeTest}~\mathit{AttributeQualifier}^*\\[1ex]
198 %%   \mathit{AttributeQualifier} & ::= & \mathtt{[@}\mathit{AttributeTest}\mathtt{]}\\
199 %%   & | & \mathtt{[!@}\mathit{AttributeTest}\mathtt{]}\\[1ex]
200 %%   \mathit{AttributeTest} & ::= & \mathit{AttributeName} \\
201 %%   & | & \mathit{AttributeName}\mathtt{='}\mathit{Text}\mathtt{'}
202 %% \end{eqnarray*}
203
204 \section{Insert Rules}
205
206 \paragraph{Begin Group:} $\{$
207
208 \begin{description}
209   \item{\verb+table/cursor+}\\
210    create a \texttt{row} node, create a \texttt{cell} node, create a \texttt{g} node,
211     append the cursor to the \texttt{g} node, append the \texttt{g} node to the \texttt{cell} node,
212     append the \texttt{cell} node to the \texttt{row} node, append the \texttt{row} node to the
213     \texttt{c} node 
214   \item{\verb+cursor+} \\ create a \texttt{g} node, replace the cursor with the new \texttt{g} node,
215     append the cursor to the new \texttt{g} node
216 \end{description}
217
218 % CASE: c/g[!@id]/cursor
219
220 % CASE: c/cursor
221
222 % ELSE:
223
224 % do_begin:
225 % CASE: c[@table='1']/cursor
226 % ELSE:
227 %   create a g node with id, replace the cursor with the fresh g and append
228 %   the cursor as only child of it
229
230 \paragraph{End Group:} $\}$
231
232 \begin{description}
233   \item{\verb+g[@id]/cursor+}\\
234   remove the cursor, put $\tadvance$ after the \texttt{g} node
235   \item{\verb+row/cell/g/cursor+}\\
236   remove the cursor, put $\tadvance$ after the \texttt{row} node
237   \item{\verb+math/g[!@id]/cursor+}\\
238   ?
239   \item{\verb+cursor+}\\
240   error ?
241 \end{description}
242
243 \paragraph{Math Shift:} $\$$
244
245 \begin{description}
246   \item{\verb+tex/cursor+}\\
247   create a \texttt{math} node, create a \texttt{g} node, append the \texttt{g} node
248     as child of the \texttt{math} node, append the cursor as child of the \texttt{g} node
249   \item{\verb+math[@display='1']/g[!@id][*#]/cursor+}\\
250   append the cursor as last child of the \texttt{math} node
251   \item{\verb+math/g[!@id][*#]/cursor+}\\
252   remove the cursor
253   \item{\verb+math[!display='1']/g[!@id]/cursor+}\\
254   set \verb+display='1'+ in the \texttt{math} node
255   \item{\verb+math/g[!@id]+}\\
256   append the cursor after the \texttt{math} node
257   \item{\verb+math/cursor+}\\
258   remove the cursor
259   \item{\verb+cursor+} \\
260   error ?
261 \end{description}
262
263 % do_shift:
264 % CASE: tex/cursor
265 %   create a math node. create a g node. append g as child of math.
266 %   append the cursor as child of g
267 % CASE: math[@display='1']/g[!@id][*#]/cursor
268 %   append the cursor as last child of math
269 % CASE: math/g[!@id][*#]/cursor
270 %   remove the cursor. Editing is done
271 % CASE: math[!display='1']/g[!@id]/cursor
272 %   set the display attribute to '1'
273 % CASE: math/g[!@id]
274 %   append the cursor after math (?)
275 % CASE: math/cursor
276 %   remove the cursor. Editing is done
277 % ELSE:
278 %   error
279
280 \paragraph{Align:} $\&$
281
282 \begin{description}
283   \item{\verb+g[@id]/cursor+}\\
284   create a \texttt{row} node, create a \texttt{cell} node, create a \texttt{g} node,
285     append the cursor to the new \texttt{g} node, append the \texttt{cell} node to the
286     the \texttt{row} node ?
287   \item{\verb+row/cell/g/cursor+}\\
288   create the \texttt{g} node, create the \texttt{cell} node, append the cursor
289     as child of the new \texttt{g} node, append the new \texttt{g} node to the new
290     \texttt{cell} node after the old \texttt{cell} node
291   \item{\verb+cursor+}\\
292   error
293 \end{description}
294
295 % do_align:
296 % CASE: g[@id]/cursor
297 %   create a row node. create a cell node. create a g node. append the
298 %   cursor to g, append the g to cell, append the cell to row, ???
299 % CASE: row/cell/g/cursor
300 %   create a g node. create a cell node. appent the cursor to g,
301 %   append the g to cell, insert the new cell after the existing cell
302 % ELSE:
303 %   error
304
305 \paragraph{End-of-line:}
306
307 % do_eol:
308 %   ignored
309
310 \paragraph{Parameter:} $p(i)$
311 % do_parameter:
312 %   ignored
313
314 \paragraph{Superscript:} $\uparrow$
315
316 \begin{description}
317   \item{\verb+<g|p>[^#]/cursor+}\\
318   create a \SP{} node, create a \G{} node, replace the cursor with the \SP{} node,
319     append the \G{} node as first child of the \SP{} node, append the cursor as last
320     child of the \SP{} node
321   \item{\verb+<g|p>[*#]/cursor+}\\
322   create a \SP{} node, replace \texttt{*} with the \SP{} node, append \texttt{*} to
323     the \SP{} node, append cursor to the \SP{} node
324   \item{\verb+sp[^*#$][!@over='1']/cursor+}\\ %$
325   set \verb+over='1'+ in the \SP{} node
326   \item{\verb+sp[^*#$][@over='1']/cursor+}\\ %$
327   error
328   \item{\verb+cursor+}\\
329   error ?
330 \end{description}
331 % do_superscript:
332 % CASE: g[^#]/cursor
333 %   create sp node. create g node, replace cursor with sp, append g to sp, append cursor to sp
334 % CASE: g[*#]/cursor
335 %   create sp node, replace * with sp, append * to sp, append cursor to sp
336 % CASE: sp[^*#$][!@over='1']/cursor
337 %   set over='1' in sp node
338 % CASE: sp[^*#$][@over='1']/cursor
339 %   error
340 % ELSE:
341 %   error ?
342
343 \paragraph{Subscript:} $\downarrow$
344
345 \begin{description}
346   \item{\verb+<g|p>[^#]/cursor+}\\
347   create a \SB{} node, create a \G{} node, replace the cursor with the \SB{} node,
348     append the \G{} node as first child of the \SB{} node, append the cursor as last
349     child of the \SB{} node
350   \item{\verb+<g|p>[*#]/cursor+}\\
351   create a \SB{} node, replace \texttt{*} with the \SB{} node, append \texttt{*} to
352     the \SB{} node, append cursor to the \SB{} node
353   \item{\verb+sb[^*#$][!@under='1']/cursor+}\\ %$
354   set \verb+under='1'+ in the \SB{} node
355   \item{\verb+sb[^*#$][@under='1']/cursor+}\\ %$
356   error
357   \item{\verb+cursor+}\\
358   error ?
359 \end{description}
360 % do_subscript:
361 % CASE: g[^#]/cursor
362 %   create sb node. create g node, replace cursor with sb, append g to sb, append cursor to sb
363 % CASE: g[*#]/cursor
364 %   create sb node, replace * with sb, append * to sb, append cursor to sb
365 % CASE: sb[^*#$][!@under='1']/cursor
366 %   set over='1' in sb node
367 % CASE: sb[^*#$][@under='1']/cursor
368 %   error
369 % ELSE:
370 %   error ?
371
372 \paragraph{Ignorable space:} $\square$
373
374 % do_ignorable_space:
375 %   do nothing?
376
377 \paragraph{Space:} $s$
378
379 \begin{description}
380   \item{\verb+cursor+}\\
381   create \SNODE{} node, replace cursor with the \SNODE{} node, append
382   $\tadvance$ after \SNODE{} node
383 \end{description}
384
385 % do_space
386 %   create s node, replace cursor with s, append \advance after s
387
388 \paragraph{Identifier:} $i(v)$
389
390 \begin{description}
391   \item{\verb+cursor+}\\
392   create an \INODE{}, set \verb+value=+$v$ in the \INODE{}, replace
393   cursor with \INODE{}, append $\tadvance$ after the \INODE{} node
394 \end{description}
395
396 % do_identifier
397 %   create i node, replace cursor with i, append \advance after i
398
399 \paragraph{Number:} $n(v)$
400
401 \begin{description}
402   \item{\verb+cursor+}\\
403   create an \NNODE{}, set \verb+value=+$v$ in the \NNODE{}, replace
404   cursor with \NNODE{}, append $\tadvance$ after the \NNODE{} node
405 \end{description}
406
407 % do_number
408 %   create n node, replace cursor with n, append \advance after n
409
410 \paragraph{Apostrophe:} $o({}')$
411
412 \begin{description}
413   \item{\verb+<g/p>[(sp[*#$]/g[o[@name='prime']$])#]/cursor+}\\
414   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
415     append the \ONODE{} to the innermost \G{} node
416   \item{\verb+<g|p>[(sb[^sp[^*#$]/g[o[@name='prime']]$])#]/cursor+}\\
417   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
418     append the \ONODE{} to the innermost \G{} node
419   \item{\verb+<g|p>[*#]/cursor+}\\
420   create a \ONODE{} node, set \verb+name='prime'+ in the \ONODE{},
421     create a \SP{} node, create a \G{} node, replace \texttt{*} with \SP{} node,
422     append the new \G{} node to the \SP{} node, append the \ONODE{}
423     node to the new \G{} node
424   \item{\verb+<g|p>[^#]/cursor+}\\
425   error?
426   \item{\verb+cursor+}\\
427   cursor is not in a group, error?
428 \end{description}
429
430 % do_apostrophe
431 % CASE: g[(sp[^*#$]/g[o[@name='prime']$])#]/cursor
432 %   append a new o[@name='prime'] node to the inner g node
433 % CASE: g[(sb[^sp[^*#$]/g[o[@name='prime']]$])#]/cursor
434 %   append a new o[@name='prime'] node to the inner g node
435 % CASE: g[*#]/cursor
436 %   create sp node, create g node, replace * with sp, append * to sp, append g to sp,
437 %   append a new o[@name='prime'[ node to the new g node
438 % CASE: g[^#]/cursor
439 %   error?
440 % ELSE:
441 %   cursor is not in a group, error?
442
443 \paragraph{Other:} $o(v)$
444
445 create an \ONODE{}, set \verb+value=+$v$ in the \ONODE{}, replace
446 cursor with \ONODE{}, append $\tadvance$ after the \ONODE{} node
447
448 % do_other
449 %   create o node, replace cursor with o, append \advance after o
450
451 \paragraph{Active:} $\sim$
452
453 % do_active:
454 %   ignored ???
455
456 \paragraph{Comment:} $\%$
457
458 % do_comment:
459 %   ignored ???
460
461 \paragraph{Begin Environment:} $c(\mathtt{begin})\langle\alpha_1,\dots,\alpha_n\rangle$
462
463 \paragraph{End Environment:} $c(\mathtt{end})\langle\rangle$
464
465 \paragraph{Left Delimiter:} $c(\mathtt{left})\langle\alpha\rangle$
466
467 \paragraph{Right Delimiter:} $c(\mathtt{right})\langle\alpha\rangle$
468
469 \paragraph{Carriage-Return:} $c(\mathtt{cr})\langle\rangle$
470
471 \begin{description}
472   \item{\verb+row/cell/g/cursor+}\\
473   create a \ROW{} node, create a \CELL{} node, create a \G{}
474     node, append the cursor to the new \G{} node, append the new \G{}
475     node to the new \CELL{} node, append the new \CELL{} node to the
476     new \ROW{} node, insert the new \ROW{} node after the old \ROW{} node
477   \item{\verb+cursor+}\\
478   ignored?
479 \end{description}
480
481 % do_cr:
482 % CASE: row/cell/g/cursor
483 %   create row node, create cell node, create g node,
484 %   append cursor to g, append g to cell, append cell to row,
485 %   insert new row after old row
486 % ELSE:
487 %   ignored ???
488
489 \paragraph{Macro:} $c(v)\langle\alpha_1,\dots,\alpha_n\rangle$
490
491 \begin{description}
492   \item{\verb+<p|g>/cursor+}\\
493   create a \CNODE{} node with the children corresponding to the pattern
494   $\tmap{\alpha_1}$,\dots,$\tmap{\alpha_n}$, replace the cursor with
495   the new \CNODE{} node. put $\tnext$ as the first child of the new
496   \CNODE{} node
497
498   \item{\verb+*/cursor+}\\
499   create a \CNODE{} node with the children corresponding to the pattern
500   $\tmap{\alpha_1}$,\dots,$\tmap{\alpha_n}$, replace the cursor with
501   the new \CNODE{} node, put $\tnext$ as the first child of the new
502   \CNODE{} node. If $n\ne0$ emit a warning (the macro has arguments but
503   but the context wouldn't normally allow them to be entered)
504 \end{description}
505
506 % do_macro:
507 % CASE: g/cursor
508 %   create a c node with children corresponding to the pattern of the macro
509 %   append \nextparam as first child of the macro
510
511 \section{Left Drop Rules}
512
513 \paragraph{Normal Left Drop:} $\NLDROP$
514
515 \begin{description}
516
517   \item{\verb+cursor+}\\
518   replace the cursor with the $\NLDROP$.
519
520 \end{description}
521
522 \paragraph{Special Left Drop:} $\SLDROP$
523
524 \begin{description}
525
526   %*******************************************************************************************************
527   %************** rules handling the case in which the cursor has a preceding node ***********************
528   %*******************************************************************************************************
529
530   %************** cursor's parent is a group or a parameter (a p node)
531
532   \item{\verb+<g|p>[(i|n|o|s|c[!*])#]/cursor+}\\
533   remove the token.
534
535   \item{\verb+<g|p>[g#]/cursor+}\\
536   remove the cursor and append it to the \G{} node.
537
538   \item{\verb+<g|p>[<sp|sb>#]cursor+}\\
539   remove the cursor and append the $\SLDSCRIPT$
540
541   \item{\verb+<g|p>[c[p[@right-open="1"]$]#]/cursor+}\\
542   remove the cursor and append the it to the \PNODE{} node.
543
544   % remember to add the rules handling the primes
545
546   %*************************************************************************************************
547   %*********** rules handling the case in which the cursor has no preceding nodes ******************
548   %*************************************************************************************************
549
550   \item{\verb+g[@id][^#$]/cursor+}\\
551   replace the \G{} node with the cursor.
552
553 \end{description}
554
555 \section{Right Drop Rules}
556
557 \section{$\varepsilon$-rules}
558
559 \paragraph{Nromal Left Drop}
560
561 \begin{description}
562
563   %**************************************************************************************
564   %****************************** epsilon-rules with \NLDROP ****************************
565   %**************************************************************************************
566
567   %***************************** \NLDROP has no preceding nodes *************************
568
569   \item{\verb+math[^#$]/+$\NLDROP$}\\
570   replace the $\NLDROP$ with the cursor.
571
572   \item{\verb+g[^#$]/+$\NLDROP$}\\
573   replace the \G{} node with the $\NLDROP$.
574
575   % this rule overrides the rule above
576   \item{\verb+math/g[^#$]/+$\NLDROP$}\\
577   replace the $\NLDROP$ with the cursor.
578
579   \item{\verb+c/p[^#$]/+$\NLDROP$}\\
580   remove the $\NLDROP$ and insert it before the \PNODE{} node.
581
582   \item{\verb+cell[^#$]/+$\NLDROP$}\\
583   replace the cell with the $\NLDROP_n$.
584
585   \item{\verb+table[^#$]/+$\NLDROP$}\\
586   replace the \TABLE{} node with the $\NLDROP$.
587
588   \item{\verb+c[p[@left-open='1'][*]#$]/p[@right-open='1'][^#$]/+$\NLDROP$}\\
589   replace the \CNODE{} node with the content of the first \PNODE{} node and insert the $\NLDROP$ after this content
590
591   \item{\verb+c[p[@left-open='1'][!*]#$]/p[@right-open='1'][^#$]/+$\NLDROP$}\\
592   replace the \CNODE{} node with the $\NLDROP$.
593
594   \item{\verb+c[^#][!p(*)]/+$\NLDROP$}\\
595   replace the \CNODE{} node with the $\NLDROP$.
596
597   %************************* \NLDROP has at least one preceding node *********************
598
599   % general rules
600
601   % this rule should also handles the case where the \NLDROP is the third (and last) child of a script.
602   \item{\verb+*[*#]/+$\NLDROP$}\\
603   remove the $\NLDROP$ and append it as the last child of its ex preceding brother.
604
605   % this rule overrides the one above
606   \item{\verb+*[<i|n|o|s>#]/+$\NLDROP$}\\
607   remove the $\NLDROP$ and replace the token with the $\NLDROP_n$.
608
609   % special rules
610
611   \item{\verb+<sp|sb>[^*#$]+/$\NLDROP$}\\
612   replace the script node with its first child and insert the $\NLDROP$ after it.
613
614   % this rule overrides the one above.
615   \item{\verb+<sp|sb>[^g[!@id][!*]#$]/+$\NLDROP$}\\
616   replace the script with the cursor.
617
618   % this rule overrides the one above
619   \item{\verb+*[sp[!@id][^*g[!@id][^o[@name='prime']++\verb+o[@name='prime']$]]#]/+$\NLDROP$}\\
620   remove the last \ONODE{} node and replace the $\NLDROP$ with the cursor.%$\NLDROP_n$.
621
622   \item{\verb+*[sp[!@id][^*g[!@id][^o[@name='prime']$]]#]/+$\NLDROP$}\\
623   replace the script with its first child and replace the $\NLDROP$ with the cursor.%$\NLDROP_n$.
624
625   \item{\verb+c[(i|n|o|s|c[!*])#]/+$\NLDROP$}\\
626   move the $\NLDROP$ before the delimiter.
627
628   % this rule is true for both right-open and parameterized macros.
629   \item{\verb+c[p#]/+$\NLDROP$}\\
630   move the $\NLDROP$ into the \PNODE{} node.
631
632   %**************** \NLDROP has no preceding nodes, but has following nodes **************
633
634   % general rule
635   \item{\verb+*[^#*]/+$\NLDROP$}\\
636   remove the $\NLDROP$ and insert it before its parent.
637
638   % special rules
639
640   \item{\verb+math/g[^#*]/+$\NLDROP$}\\
641   replace the $\NLDROP$ with the cursor.
642
643   % this rule is applicable to all macros.
644   \item{\verb+c[^#][p[*]]/+$\NLDROP$}\\
645   remove the $\NLDROP$ and insert it before the \CNODE{} node.
646
647   %****************************************************************************************
648   %***************************** epsilon-rules with \NLDROP_n *****************************
649   %****************************************************************************************
650
651   \item{\verb+*[*#]/+$\NLDROP_n$}\\
652   replace the $\NLDROP_n$ with the cursor.
653
654   \item{\verb+row[cell#]/+$\NLDROP_n$}\\
655   remove the $\NLDROP_n$ and append the cursor as the last child of the \CELL{} node.
656
657   \item{\verb+row[^#$]/+$\NLDROP_n$}\\
658   replace the \ROW{} node with the $\NLDROP_n$
659
660   \item{\verb+table[row#]/+$\NLDROP_n$}\\
661   remove the $\NLDROP_n$ and append it as last child of the \ROW{} node.
662
663   \item{\verb+table[^#$]/+$\NLDROP_n$}\\
664   replace the \texttt{table} with the cursor.%$\NLDROP_n$.
665
666   \item{\verb+g[@id][^#$]/+$\NLDROP_n$}\\
667   replace the \G{} node with the $\NLDROP_n$.
668
669 \end{description}
670
671 \paragraph{Special Left Drop}
672
673 %\begin{description}
674
675 %\end{description}
676
677 \paragraph{Advance}
678
679 \begin{description}
680   \item{\verb+g/+$\tadvance$}\\
681   replace $\tadvance$ with the cursor
682
683   \item{\verb+p[#$]/+$\tadvance$}\\ %$
684   put $\tadvance$ after the \PNODE{} node
685
686   \item{\verb+c[#p]/+$\tadvance$} \\
687   remove $\tadvance$, put the cursor as first child of the \PNODE{} node
688
689   \item{\verb+c[#*]/+$\tadvance$} \\ %$
690   replace $\tadvance$ with the cursor 
691
692   \item{\verb+c[#$]/+$\tadvance$} \\ %$
693   move $\tadvance$ after the \CNODE{} node
694 \end{description}
695
696 \paragraph{Next Parameter}
697
698 \paragraph{Next Token}
699
700 %% \begin{description}
701 %%   \item{\verb+c[#p]/+$\tnext$} \\
702 %% \end{description}
703
704 % g[@id]/(c[#$][@right-open]/g[!@id][#$]/)+cursor  }   let p = cursor.parent() in remove; advance(p)
705
706 % c/g[!@id]/cursor
707 % c/cursor 
708 % */cursor  {   let g = new group in replace
709
710 % g[@id][^#$]/cursor  <=   cursor.parent().replace(cursor)
711 % g[@id][^#$]/cursor  <-   cursor
712 % (!g[@id][^#$])[A#B]/(g[@id][^#$]/)+cursor  <-  (!g[@id][^#$])[A#B]/cursor  
713
714 \end{document}