Re: [dk-tug] [OT] emacs makro
Lars Madsen <[email protected]>
| Newsgroups | gmane.comp.tex.danish |
|---|---|
| Message-ID | <[email protected]> |
Efter et par skønhedsfejl
(defun qqtext(beg end)
(interactive "r")
(let (str o pre txt left)
(setq str (buffer-substring beg end))
(setq o "")
;; (message (concat "Starting with: " "'" str "'"))
;; start by doing some clean up
(setq str (replace-regexp-in-string "\\\\\(q\)+uad" " " str))
(setq str (replace-regexp-in-string "[\t\n ]+" " " str))
(setq str (replace-regexp-in-string "\\\\ +" " " str))
(setq str (replace-regexp-in-string " \\{2,\\}" " " str))
(setq str (replace-regexp-in-string "\\` +" "" str))
;; (message (concat "After cleaning: " "'" str "'"))
(catch 'break
(while (not (string= str ""))
(catch 'continue
;; handle embedded \text{...}
(when (string-match "\\(.*?\\) *\\\\text{ *\\(.*?\\) *} *\\(.*\\)" str)
(setq pre (match-string 1 str))
(setq txt (match-string 2 str))
(setq left (match-string 3 str))
;; (message (concat "Pre: '" pre "'"))
;; (message (concat "Text: '" txt "'"))
;; if pre is non-empty, regard it as math, and make it in-line
(when (not (string= pre ""))
(setq o (concat o "$" pre "$"))
)
;; if o is non-empty, we will need a space
(when (not (string= o ""))
(setq o (concat o " "))
)
;; add the text and a space
(setq o (concat o txt " "))
(setq str left)
(throw 'continue nil)
)
;; there is no \text left
(setq o (concat o "$" str "$"))
(setq str "")
)
)
)
(delete-region beg end)
(insert (concat "\\qqtext{" o "}"))
)
)
/Lars Madsen
Institut for Matematik / Department of Mathematics
Aarhus Universitet / Aarhus University
Mere info: http://au.dk/daleif@imf / More information: http://au.dk/en/daleif@imf