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 part of Emacs Muse. It is not part of GNU Emacs.
7
;; Emacs Muse is free software; you can redistribute it and/or modify
8
;; it under the terms of the GNU General Public License as published
9
;; by the Free Software Foundation; either version 2, or (at your
10
;; option) any later version.
12
;; Emacs Muse is distributed in the hope that it will be useful, but
13
;; WITHOUT ANY WARRANTY; without even the implied warranty of
14
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
;; General Public License for more details.
17
;; You should have received a copy of the GNU General Public License
18
;; along with Emacs Muse; 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.\\\\[" muse-regexp-blank "\n]+")
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"))
56
(insert "\n[" (number-to-string note) "] " text ?\n)))
59
(defun muse-latex-transform ()
61
(goto-char (point-min))
64
((or (looking-at "^\\\\documentclass")
65
(looking-at "^\\\\input")
66
(looking-at "^\\\\begin{document}")
67
(looking-at "^\\\\end{document}")
68
(looking-at "^\\\\author")
69
(looking-at "^\\\\\\(med\\|big\\|small\\)skip")
70
(looking-at "^\\\\maketitle"))
71
(delete-region (point) (muse-line-end-position)))
72
((looking-at "^\\\\title{\\(.+\\)}")
73
(delete-region (match-end 1) (muse-line-end-position))
74
(delete-region (point) (match-beginning 1))
77
(goto-char (point-min))
78
(while (re-search-forward "\\\\\\(l\\)?dots{}" nil t)
79
(replace-match (concat (and (string= (match-string 1) "l") ".")
81
(goto-char (point-min))
82
(while (re-search-forward "\\(``\\|''\\)" nil t)
84
(goto-char (point-min))
85
(while (re-search-forward "---" nil t)
86
(replace-match " -- "))
87
(goto-char (point-min))
88
(while (re-search-forward "\\\\tableofcontents" nil t)
89
(replace-match "<contents>"))
90
(goto-char (point-min))
91
(while (re-search-forward "\\\\\\\\" nil t)
93
(goto-char (point-min))
94
(while (re-search-forward "\\\\\\(sub\\)?section{\\([^}]+\\)}" nil t)
95
(replace-match (concat (if (string= (match-string 1) "sub")
97
" " (match-string 2))))
98
(goto-char (point-min))
99
(while (re-search-forward "\\\\\\(begin\\|end\\){verse}" nil t)
100
(replace-match (concat "<" (if (string= (match-string 1) "end") "/")
102
(goto-char (point-min))
103
(while (re-search-forward "\\\\\\(begin\\|end\\){quote}\n" nil t)
105
(goto-char (point-min))
106
(while (re-search-forward
107
"\\\\\\(emph\\|textbf\\){\\([^}]+?\\)\\(\\\\/\\)?}" nil t)
109
(if (string= (match-string 1) "emph") "*\\2*" "**\\2**")))
110
(let ((footnote-index 1))
111
(goto-char (point-min))
112
(while (re-search-forward
113
(concat "\\\\\\(q\\)?\\(footnote\\|excerpt\\)\\(np\\)?"
114
"\\({\\([^}]+\\)}\\)?"
115
"\\({\\([^}]+\\)}{\\([^}]+\\)}\\)?{\\([^}]+\\)}") nil t)
116
(let ((beg (match-beginning 0))
118
(unless (string= (match-string 2) "footnote")
119
(if (null (match-string 1))
120
(insert " " (match-string 9))
122
(insert "\"" (match-string 9) "\"")
123
(setq e (point-marker))
128
(if (looking-at "\\s-+")
129
(delete-region (match-beginning 0)
132
(insert "[" (number-to-string footnote-index) "]")
133
(if (string= (match-string 2) "footnote")
134
(muse-write-footnote footnote-index (match-string 9))
135
(muse-write-citation footnote-index (match-string 5)
136
(match-string 7) (match-string 8)))
137
(setq footnote-index (1+ footnote-index))
138
(delete-region beg end))))
139
(goto-char (point-min))
140
(while (looking-at "\n") (delete-char 1))
141
(goto-char (point-min))
142
(while (re-search-forward "\n\n+" nil t)
143
(replace-match "\n\n")))
145
(provide 'muse-convert)