1 ;;; muse-import-latex.el --- convert a LaTex file into a Muse file
3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of Emacs Muse. It is not part of GNU Emacs.
8 ;; Emacs Muse is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published
10 ;; by the Free Software Foundation; either version 3, or (at your
11 ;; option) any later version.
13 ;; Emacs Muse is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with Emacs Muse; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; Helper commands for converting a LaTeX file into a Muse file.
32 (require 'muse-regexps
)
34 (defun muse-i-l-write-citation (note author citation pages
)
36 (goto-char (point-max))
38 (insert "\nFootnotes:\n\n"))
40 (insert "\n[" (number-to-string note
) "] " author
)
41 (if (and citation pages
)
42 (insert ", " citation
", " pages
))
45 (while (re-search-forward (concat "p.\\\\[" muse-regexp-blank
"\n]+")
49 (while (re-search-forward "--" nil t
)
50 (replace-match "-")))))
52 (defun muse-i-l-write-footnote (note text
)
54 (goto-char (point-max))
56 (insert "\nFootnotes:\n\n"))
57 (insert "\n[" (number-to-string note
) "] " text ?
\n)))
60 (defun muse-import-latex ()
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) (muse-line-end-position)))
73 ((looking-at "^\\\\title{\\(.+\\)}")
74 (delete-region (match-end 1) (muse-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 (set-marker e nil
))))
134 (insert "[" (number-to-string footnote-index
) "]")
135 (if (string= (match-string 2) "footnote")
136 (muse-i-l-write-footnote footnote-index
(match-string 9))
137 (muse-i-l-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-import-latex
)
149 ;;; muse-import-latex.el ends here