1 | (in-package :cl-user) |
---|
2 | (defun grovel-docstrings-as-tex (&optional (package (find-package :java))) |
---|
3 | (let ((output-file (format nil "~A.tex" (string-downcase (package-name package))))) |
---|
4 | (with-open-file (stream output-file :direction :output) |
---|
5 | (format t "Writing output to ~A.~%" output-file) |
---|
6 | (loop :for symbol :being :each :external-symbol :of package |
---|
7 | :doing (format stream "~&~A~%~%" (symbol-as-tex symbol)))))) |
---|
8 | |
---|
9 | (require :asdf) |
---|
10 | |
---|
11 | (asdf:load-system 'swank) ;; XXX Does this load the SWANK-BACKEND package as well |
---|
12 | |
---|
13 | (defun texify-string (string &optional remove) |
---|
14 | (with-output-to-string (s) |
---|
15 | (loop for char across string |
---|
16 | ;; when (string= char #\_) ;; XXX FIXME |
---|
17 | ;; do (progn |
---|
18 | ;; (write-char #\_ s) |
---|
19 | ;; (write-char #\_ s)) |
---|
20 | do (if (find char '(#\& #\% #\#)) |
---|
21 | (unless remove |
---|
22 | (write-char #\\ s) |
---|
23 | (write-char char s)) |
---|
24 | (write-char char s))))) |
---|
25 | |
---|
26 | (defun texify (thing) |
---|
27 | "Return STRING with LaTeX-sensitive characters escaped. |
---|
28 | Downcase symbol names but leave strings alone." |
---|
29 | (cond ((listp thing) |
---|
30 | (format nil "~A" (mapcar #'texify thing))) |
---|
31 | ((stringp thing) (texify-string thing)) |
---|
32 | ((symbolp thing) (texify-string (string-downcase (symbol-name thing)))))) |
---|
33 | |
---|
34 | (defun arglist-as-tex (symbol) |
---|
35 | (handler-case |
---|
36 | (loop :for arg :in (arglist symbol) |
---|
37 | :collecting (texify arg)) |
---|
38 | (t (e) |
---|
39 | (progn (warn "Failed to form arglist for ~A: ~A" symbol e) |
---|
40 | (list ""))))) |
---|
41 | |
---|
42 | |
---|
43 | (defvar *type-alist* |
---|
44 | '((:function |
---|
45 | . "Function") |
---|
46 | (:macro |
---|
47 | . "Macro") |
---|
48 | (:variable |
---|
49 | . "Variable") |
---|
50 | (:class |
---|
51 | . "Class") |
---|
52 | (:special-operator |
---|
53 | . "Special Operator") |
---|
54 | (:generic-function |
---|
55 | . "Generic Function"))) |
---|
56 | |
---|
57 | (defun symbol-as-tex (symbol) |
---|
58 | "Return the TeX representation of a SYMBOL as Tex." |
---|
59 | (let (type documentation arglist doc symbol-name package-name) |
---|
60 | (when (setf doc (swank-backend:describe-symbol-for-emacs symbol)) |
---|
61 | (cond |
---|
62 | ((find :function doc) |
---|
63 | (setf type :function |
---|
64 | documentation (second doc) |
---|
65 | arglist (format nil "~{~A~^ ~}" (arglist-as-tex symbol)))) |
---|
66 | ((find :variable doc) |
---|
67 | (setf type :variable |
---|
68 | documentation (second doc))) |
---|
69 | ((find :macro doc) |
---|
70 | (setf type :macro |
---|
71 | documentation (second doc))) |
---|
72 | ((find :generic-function doc) |
---|
73 | (setf type :generic-function |
---|
74 | documentation (second doc))) |
---|
75 | ((find :class doc) |
---|
76 | (setf type :class |
---|
77 | documentation (second doc))) |
---|
78 | ((find :special-operator doc) |
---|
79 | (setf type :special-operator |
---|
80 | documentation (second doc))) |
---|
81 | (t |
---|
82 | (warn "Unknown type of documentation for symbol ~A: ~A" |
---|
83 | symbol doc))) |
---|
84 | (setf symbol-name (string-downcase |
---|
85 | symbol) |
---|
86 | package-name (string-downcase |
---|
87 | (package-name (find-package (symbol-package symbol))))) |
---|
88 | (format nil "~&\\paragraph{} |
---|
89 | \\label{~A:~A} |
---|
90 | \\index{~A} |
---|
91 | --- ~A: \\textbf{~A} [\\textbf{~A}] \\textit{~A} |
---|
92 | |
---|
93 | \\begin{adjustwidth}{5em}{5em} |
---|
94 | ~A |
---|
95 | \\end{adjustwidth}" |
---|
96 | (texify-string (package-name (find-package (symbol-package symbol))) t) |
---|
97 | (texify-string (symbol-name symbol) t) |
---|
98 | (texify-string (symbol-name symbol) t) |
---|
99 | (cdr (assoc type *type-alist*)) |
---|
100 | (texify symbol-name) |
---|
101 | (texify package-name) |
---|
102 | (if arglist arglist "") |
---|
103 | (if documentation (texify documentation) ""))))) |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|