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., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
24 ;; Helper commands for converting a LaTeX file into a Muse file.
31 (require 'muse-regexps
)
33 (defun muse-write-citation (note author citation pages
)
35 (goto-char (point-max))
37 (insert "\nFootnotes:\n\n"))
39 (insert "\n[" (number-to-string note
) "] " author
)
40 (if (and citation pages
)
41 (insert ", " citation
", " pages
))
44 (while (re-search-forward (concat "p.\\\\["
50 (while (re-search-forward "--" nil t
)
51 (replace-match "-")))))
53 (defun muse-write-footnote (note text
)
55 (goto-char (point-max))
57 (insert "\nFootnotes:\n\n"))
58 (insert "\n[" (number-to-string note
) "] " text ?
\n)))
61 (defun muse-latex-transform ()
63 (goto-char (point-min))
66 ((or (looking-at "^\\\\documentclass")
67 (looking-at "^\\\\input")
68 (looking-at "^\\\\begin{document}")
69 (looking-at "^\\\\end{document}")
70 (looking-at "^\\\\author")
71 (looking-at "^\\\\\\(med\\|big\\|small\\)skip")
72 (looking-at "^\\\\maketitle"))
73 (delete-region (point) (muse-line-end-position)))
74 ((looking-at "^\\\\title{\\(.+\\)}")
75 (delete-region (match-end 1) (muse-line-end-position))
76 (delete-region (point) (match-beginning 1))
79 (goto-char (point-min))
80 (while (re-search-forward "\\\\\\(l\\)?dots{}" nil t
)
81 (replace-match (concat (and (string= (match-string 1) "l") ".")
83 (goto-char (point-min))
84 (while (re-search-forward "\\(``\\|''\\)" nil t
)
86 (goto-char (point-min))
87 (while (re-search-forward "---" nil t
)
88 (replace-match " -- "))
89 (goto-char (point-min))
90 (while (re-search-forward "\\\\tableofcontents" nil t
)
91 (replace-match "<contents>"))
92 (goto-char (point-min))
93 (while (re-search-forward "\\\\\\\\" nil t
)
95 (goto-char (point-min))
96 (while (re-search-forward "\\\\\\(sub\\)?section{\\([^}]+\\)}" nil t
)
97 (replace-match (concat (if (string= (match-string 1) "sub")
99 " " (match-string 2))))
100 (goto-char (point-min))
101 (while (re-search-forward "\\\\\\(begin\\|end\\){verse}" nil t
)
102 (replace-match (concat "<" (if (string= (match-string 1) "end") "/")
104 (goto-char (point-min))
105 (while (re-search-forward "\\\\\\(begin\\|end\\){quote}\n" nil t
)
107 (goto-char (point-min))
108 (while (re-search-forward
109 "\\\\\\(emph\\|textbf\\){\\([^}]+?\\)\\(\\\\/\\)?}" nil t
)
111 (if (string= (match-string 1) "emph") "*\\2*" "**\\2**")))
112 (let ((footnote-index 1))
113 (goto-char (point-min))
114 (while (re-search-forward
115 (concat "\\\\\\(q\\)?\\(footnote\\|excerpt\\)\\(np\\)?"
116 "\\({\\([^}]+\\)}\\)?"
117 "\\({\\([^}]+\\)}{\\([^}]+\\)}\\)?{\\([^}]+\\)}") nil t
)
118 (let ((beg (match-beginning 0))
120 (unless (string= (match-string 2) "footnote")
121 (if (null (match-string 1))
122 (insert " " (match-string 9))
124 (insert "\"" (match-string 9) "\"")
125 (setq e
(point-marker))
130 (if (looking-at "\\s-+")
131 (delete-region (match-beginning 0)
134 (insert "[" (number-to-string footnote-index
) "]")
135 (if (string= (match-string 2) "footnote")
136 (muse-write-footnote footnote-index
(match-string 9))
137 (muse-write-citation footnote-index
(match-string 5)
138 (match-string 7) (match-string 8)))
139 (setq footnote-index
(1+ footnote-index
))
140 (delete-region beg end
))))
141 (goto-char (point-min))
142 (while (looking-at "\n") (delete-char 1))
143 (goto-char (point-min))
144 (while (re-search-forward "\n\n+" nil t
)
145 (replace-match "\n\n")))
147 (provide 'muse-convert
)