1 ;;; muse-convert.el --- Convert a LaTex file into a Muse file.
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 ;; This file is not part of GNU Emacs.
7 ;; This is free software; you can redistribute it and/or modify it under
8 ;; the terms of the GNU General Public License as published by the Free
9 ;; Software Foundation; either version 2, or (at your option) any later
12 ;; This is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 ;; MA 02111-1307, USA.
28 ;; Helper commands for converting a LaTeX file into a Muse file
29 (require 'muse-regexps
)
31 (defun muse-write-citation (note author citation pages
)
33 (goto-char (point-max))
35 (insert "\nFootnotes:\n\n"))
37 (insert "\n[" (number-to-string note
) "] " author
)
38 (if (and citation pages
)
39 (insert ", " citation
", " pages
))
42 (while (re-search-forward (concat "p.\\\\["
48 (while (re-search-forward "--" nil t
)
49 (replace-match "-")))))
51 (defun muse-write-footnote (note text
)
53 (goto-char (point-max))
55 (insert "\nFootnotes:\n\n"))
57 (insert "\n[" (number-to-string note
) "] " text ?
\n))))
60 (defun muse-latex-transform ()
62 (goto-char (point-min))
65 ((or (looking-at "^\\\\documentclass")
66 (looking-at "^\\\\input")
67 (looking-at "^\\\\begin{document}")
68 (looking-at "^\\\\end{document}")
69 (looking-at "^\\\\author")
70 (looking-at "^\\\\\\(med\\|big\\|small\\)skip")
71 (looking-at "^\\\\maketitle"))
72 (delete-region (point) (line-end-position)))
73 ((looking-at "^\\\\title{\\(.+\\)}")
74 (delete-region (match-end 1) (line-end-position))
75 (delete-region (point) (match-beginning 1))
78 (goto-char (point-min))
79 (while (re-search-forward "\\\\\\(l\\)?dots{}" nil t
)
80 (replace-match (concat (and (string= (match-string 1) "l") ".")
82 (goto-char (point-min))
83 (while (re-search-forward "\\(``\\|''\\)" nil t
)
85 (goto-char (point-min))
86 (while (re-search-forward "---" nil t
)
87 (replace-match " -- "))
88 (goto-char (point-min))
89 (while (re-search-forward "\\\\tableofcontents" nil t
)
90 (replace-match "<contents>"))
91 (goto-char (point-min))
92 (while (re-search-forward "\\\\\\\\" nil t
)
94 (goto-char (point-min))
95 (while (re-search-forward "\\\\\\(sub\\)?section{\\([^}]+\\)}" nil t
)
96 (replace-match (concat (if (string= (match-string 1) "sub")
98 " " (match-string 2))))
99 (goto-char (point-min))
100 (while (re-search-forward "\\\\\\(begin\\|end\\){verse}" nil t
)
101 (replace-match (concat "<" (if (string= (match-string 1) "end") "/")
103 (goto-char (point-min))
104 (while (re-search-forward "\\\\\\(begin\\|end\\){quote}\n" nil t
)
106 (goto-char (point-min))
107 (while (re-search-forward
108 "\\\\\\(emph\\|textbf\\){\\([^}]+?\\)\\(\\\\/\\)?}" nil t
)
110 (if (string= (match-string 1) "emph") "*\\2*" "**\\2**")))
111 (let ((footnote-index 1))
112 (goto-char (point-min))
113 (while (re-search-forward
114 (concat "\\\\\\(q\\)?\\(footnote\\|excerpt\\)\\(np\\)?"
115 "\\({\\([^}]+\\)}\\)?"
116 "\\({\\([^}]+\\)}{\\([^}]+\\)}\\)?{\\([^}]+\\)}") nil t
)
117 (let ((beg (match-beginning 0))
119 (unless (string= (match-string 2) "footnote")
120 (if (null (match-string 1))
121 (insert " " (match-string 9))
123 (insert "\"" (match-string 9) "\"")
124 (setq e
(point-marker))
129 (if (looking-at "\\s-+")
130 (delete-region (match-beginning 0)
133 (insert "[" (number-to-string footnote-index
) "]")
134 (if (string= (match-string 2) "footnote")
135 (muse-write-footnote footnote-index
(match-string 9))
136 (muse-write-citation footnote-index
(match-string 5)
137 (match-string 7) (match-string 8)))
138 (setq footnote-index
(1+ footnote-index
))
139 (delete-region beg end
))))
140 (goto-char (point-min))
141 (while (looking-at "\n") (delete-char 1))
142 (goto-char (point-min))
143 (while (re-search-forward "\n\n+" nil t
)
144 (replace-match "\n\n")))
146 (provide 'muse-convert
)