3 (defconst latex-dir (file-name-directory (nth 2 command-line-args-left)))
8 title pos current-section current-subsection)
10 (find-file (expand-file-name "m17n-lib.toc" latex-dir))
11 (while (re-search-forward "{\\(sub\\)*section}" nil t)
12 (goto-char (1+ (match-beginning 0)))
13 (setq section-type (intern (buffer-substring
14 (1+ (match-beginning 0))
16 (re-search-forward "{[0-9.]+}")
17 (setq title (buffer-substring (1+ (match-beginning 0))
19 (narrow-to-region (point) (line-end-position))
20 (goto-char (point-max))
24 (concat title " " (buffer-substring (point-min) (point))))
27 (while (setq idx (string-match "\\\\discretionary {-}{}{}" title))
28 (setq title (concat (substring title 0 idx)
29 (substring title (match-end 0))))))
30 (re-search-forward "[0-9]+")
31 (setq page (string-to-int (match-string 0)))
32 (cond ((eq section-type 'section)
33 (setq current-section (list title page))
35 (nconc sections (list current-section)))
36 (setq current-subsection nil current-subsubsection nil))
37 ((eq section-type 'subsection)
38 (setq current-subsection (list title page))
40 (nconc current-section (list current-subsection)))
41 (setq current-subsubsection nil))
43 (setq current-subsubsection (list title page))
44 (setq current-subsection
45 (nconc current-subsection (list current-subsubsection)))
49 (defun insert-one-line (elt)
51 (format "[ /Count %d /Page %d/View [/XYZ null null 1.0]/Title ("
52 (length (nthcdr 2 elt)) (+ (nth 1 elt) 4)))
53 (let* ((str (encode-coding-string (car elt) 'utf-16-be-dos))
57 (insert (format "\\%03o" (aref str i)))
59 (insert ") /OUT pdfmark\n"))
61 (defun write-mokuji ()
62 (let ((l (parse-toc)) elt)
63 (with-temp-file (expand-file-name "mokuji.ps" latex-dir)
64 (set-buffer-multibyte nil)
65 (insert "%!PS-Adobe 3.0
67 /bd {bind def} bind def /fsd {findfont exch scalefont def} bd /sms {setfont moveto show} bd /ms {moveto show} bd systemdict /pdfmark known not {userdict /pdfmark systemdict /cleartomark get put } if
72 (setq elt (car l) l (cdr l))
74 (let ((ll (nthcdr 2 elt)) ee)
76 (setq ee (car ll) ll (cdr ll))
78 (let ((lll (nthcdr 2 ee)) eee)
80 (setq eee (car lll) lll (cdr lll))
81 (insert-one-line eee))))))