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"))
59 (insert "\n[" (number-to-string note
) "] " text ?
\n))))
62 (defun muse-latex-transform ()
64 (goto-char (point-min))
67 ((or (looking-at "^\\\\documentclass")
68 (looking-at "^\\\\input")
69 (looking-at "^\\\\begin{document}")
70 (looking-at "^\\\\end{document}")
71 (looking-at "^\\\\author")
72 (looking-at "^\\\\\\(med\\|big\\|small\\)skip")
73 (looking-at "^\\\\maketitle"))
74 (delete-region (point) (muse-line-end-position)))
75 ((looking-at "^\\\\title{\\(.+\\)}")
76 (delete-region (match-end 1) (muse-line-end-position))
77 (delete-region (point) (match-beginning 1))
80 (goto-char (point-min))
81 (while (re-search-forward "\\\\\\(l\\)?dots{}" nil t
)
82 (replace-match (concat (and (string= (match-string 1) "l") ".")
84 (goto-char (point-min))
85 (while (re-search-forward "\\(``\\|''\\)" nil t
)
87 (goto-char (point-min))
88 (while (re-search-forward "---" nil t
)
89 (replace-match " -- "))
90 (goto-char (point-min))
91 (while (re-search-forward "\\\\tableofcontents" nil t
)
92 (replace-match "<contents>"))
93 (goto-char (point-min))
94 (while (re-search-forward "\\\\\\\\" nil t
)
96 (goto-char (point-min))
97 (while (re-search-forward "\\\\\\(sub\\)?section{\\([^}]+\\)}" nil t
)
98 (replace-match (concat (if (string= (match-string 1) "sub")
100 " " (match-string 2))))
101 (goto-char (point-min))
102 (while (re-search-forward "\\\\\\(begin\\|end\\){verse}" nil t
)
103 (replace-match (concat "<" (if (string= (match-string 1) "end") "/")
105 (goto-char (point-min))
106 (while (re-search-forward "\\\\\\(begin\\|end\\){quote}\n" nil t
)
108 (goto-char (point-min))
109 (while (re-search-forward
110 "\\\\\\(emph\\|textbf\\){\\([^}]+?\\)\\(\\\\/\\)?}" nil t
)
112 (if (string= (match-string 1) "emph") "*\\2*" "**\\2**")))
113 (let ((footnote-index 1))
114 (goto-char (point-min))
115 (while (re-search-forward
116 (concat "\\\\\\(q\\)?\\(footnote\\|excerpt\\)\\(np\\)?"
117 "\\({\\([^}]+\\)}\\)?"
118 "\\({\\([^}]+\\)}{\\([^}]+\\)}\\)?{\\([^}]+\\)}") nil t
)
119 (let ((beg (match-beginning 0))
121 (unless (string= (match-string 2) "footnote")
122 (if (null (match-string 1))
123 (insert " " (match-string 9))
125 (insert "\"" (match-string 9) "\"")
126 (setq e
(point-marker))
131 (if (looking-at "\\s-+")
132 (delete-region (match-beginning 0)
135 (insert "[" (number-to-string footnote-index
) "]")
136 (if (string= (match-string 2) "footnote")
137 (muse-write-footnote footnote-index
(match-string 9))
138 (muse-write-citation footnote-index
(match-string 5)
139 (match-string 7) (match-string 8)))
140 (setq footnote-index
(1+ footnote-index
))
141 (delete-region beg end
))))
142 (goto-char (point-min))
143 (while (looking-at "\n") (delete-char 1))
144 (goto-char (point-min))
145 (while (re-search-forward "\n\n+" nil t
)
146 (replace-match "\n\n")))
148 (provide 'muse-convert
)