File: NOTES

package info (click to toggle)
openjade 1.4devel1-20.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 6,636 kB
  • sloc: cpp: 90,082; sh: 10,847; ansic: 2,365; lisp: 894; perl: 604; makefile: 443; sed: 93
file content (195 lines) | stat: -rw-r--r-- 6,093 bytes parent folder | download | duplicates (8)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Some temporary notes:

==============================================================================

For reference, here is how some of this can be hacked in jadetex using 
sgml-parse:

cat >>jadetex.cfg <<EOF

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% page-number and category-page-number support
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%
% We need a counter totalpages which truly counts the pages 
% shipped out so far (unlike page, which counts something 
% like the DSSSL category-page-number).  
%
\newcounter{totalpages}
\setcounter{totalpages}{1}

% Wow, changing the LaTeX output routine !
\let\@@outputpage\@outputpage
\def\@outputpage{\@@outputpage\stepcounter{totalpages}}

% Produce an SGML file which can be read by sgml-parse
\newwrite\@dssslindexfile
\immediate\openout\@dssslindexfile=\jobname.index
\begingroup
  \catcode`\#=12
  \immediate\write\@dssslindexfile
  {<!doctype pagelist [^^J %
<!element pagelist - - (node+) >^^J 
<!element node - - (firstarea,node*,lastarea) >^^J 
<!attlist node id ID #IMPLIED >^^J 
<!element (firstarea,lastarea) - - EMPTY >^^J 
<!attlist (firstarea,lastarea)^^J   
page NUMBER #REQUIRED^^J   
category NUMBER #REQUIRED >^^J%
]>^^J%
<pagelist>}
\endgroup
\typeout{Writing DSSSL page number information to \jobname.index.}

\newcounter{elno}
\let\@@Node\Node
\def\Node#1{%
  \@@Node{#1}%
  \DEBUG{Label \Label}%
  \DEBUG{Element \Element}%
  \def\pgid{}%
  \ifx\Label\@empty
    \ifx\Element\@empty\else
     \setcounter{elno}{\Element}%
     \addtocounter{elno}{1}%
     \edef\pgid{ELNO\arabic{elno}}%
    \fi
  \else
    \let\pgid\Label
  \fi
    \immediate\write\@dssslindexfile
    {<node\ifx\pgid\@empty\else\space id="\pgid"\fi>^^J
       <firstarea page="\arabic{totalpages}" 
                  category="\arabic{page}">}}
\let\@@endNode\endNode
\def\endNode#1{%
  \DEBUG{endNode: \Label, \Element}%
    \immediate\write\@dssslindexfile
    { <lastarea page="\arabic{totalpages}"
                category="\arabic{page}">^^J</node>}%
  \@@endNode{#1}}
\let\@@endFOT\endFOT
\def\endFOT{%
 \immediate\write\@dssslindexfile{</pagelist>}%
 \immediate\closeout\@dssslindexfile
 \@@endFOT}

EOF

Explanation for the TeXagnostics: What this does is write an SGML file
xyz.index (assuming you started with xyz.sgml from which jade -ttex produced 
xyz.tex) with the following DTD

<!element pagelist - - (node+) >
<!element node - - (firstarea,node*,lastarea) >
<!attlist node id ID #IMPLIED >
<!element (firstarea,lastarea) - - EMPTY >
<!attlist (firstarea,lastarea)
	page NUMBER #REQUIRED
	category NUMBER #REQUIRED >
 
jadetex emits a node element for each node in the FOT (in reality there
are no nodes in the FOT, but the TeXFOTBuilder emits enough information
for jadetex to know which node was current when a FO was created).

The page and category attributes of the firstarea and lastarea elements 
contain the values we want to get via 

(page-number first-area-of-node: nd)
(page-number last-area-of-node: nd)
(category-page-number first-area-of-node: nd)
(category-page-number last-area-of-node: nd)

if nd is the node in question.

Here is how to define page-number and category-page-number using sgml-parse.
The ugly thing is that the name of the index file is hardcoded. This 
could be improved using the -V extensions of OpenJade.

cat >>page-numbers.dsl <<EOF

(define index-sysid "xyz.index")
(define index-page-grove (sgml-parse index-sysid))

(define (page-number #!key first-area-of-node last-area-of-node) 
  (wrap-generated-object
  (if (and first-area-of-node last-area-of-node)
     (error "page-number accepts at most one key argument")
     (let* ((snl (or first-area-of-node last-area-of-node (current-node))) 
            (area (if last-area-of-node "LASTAREA" "FIRSTAREA"))
	    (tid (or (id snl) (string-append "ELNO" 
					     (format-number
					      (all-element-number snl) "1")))))
       (if tid
	   (string->number 
	    (or (attribute-string 
		 "PAGE" (select-elements 
			 (children (element-with-id tid index-page-grove))
			 area))
		"0"))
	   (error "page-number currently works only on elements 
and nodes with id"))))))
	   
(define (category-page-number #!key first-area-of-node last-area-of-node) 
  (wrap-generated-object
  (if (and first-area-of-node last-area-of-node)
     (error "category-page-number accepts at most one key argument")
     (let* ((snl (or first-area-of-node last-area-of-node (current-node))) 
            (area (if last-area-of-node "LASTAREA" "FIRSTAREA"))
	    (tid (or (id snl) (string-append "ELNO" 
					     (format-number
					      (all-element-number snl) "1")))))
       (if tid
	   (string->number 
	    (or (attribute-string 
		 "CATEGORY" (select-elements 
			 (children (element-with-id tid index-page-grove))
			 area))
		"0"))
	   (error "category-page-number currently works only on elements 
and nodes with id"))))))


;; I used wrap-generated-object to fake a new type for generated objects.

(define (wrap-generated-object x) (cons 'generated-object x))

(define (generated-object? x) 
  (and (pair? x) (equal? (car x) 'generated-object)))

(define (unwrap-generated-object x) 
  (if (generated-object? x) 
      (cdr x)
      (error "generated object required")))


;; Of course we also need some of the DSSSL functions dealing with
;; generated objects.

; This is a *very* partial implementation of general-indirect-sosofo.
(define (general-indirect-sosofo fun #!rest li) 
  (fun (map unwrap-generated-object li)))

(define (number-indirect-sosofo x #!key (format "1") (add 0) (multiple 1))
  (let ((y (unwrap-generated-object x)))
    (if (not (number? y))
	(error "number-indirect-sosofo: kernel of generated object 
not a number")
	(let ((n (+ add y))) 
	  (if (= 0 (remainder n multiple))
	      (literal (format-number n format))
	      (literal ""))))))

(define (asis-indirect-sosofo x)
  (let ((y (unwrap-generated-object x)))
    (if (not (sosofo? y))
	(error "asis-indirect-sosofo: kernel of generated object 
not a sosofo")
	y)))

EOF

==============================================================================