Re: [dk-tug] [OT] emacs makro

Lars Madsen <[email protected]>
Newsgroups gmane.comp.tex.danish
Message-ID <[email protected]>
     (setq str (replace-regexp-in-string "\\\\\(q\)+uad" " " str))

skal være

     (setq str (replace-regexp-in-string "\\\\\\(q\\)+uad" " " str))



/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


________________________________________
From: [email protected] [[email protected]] on behalf of Lars Madsen [[email protected]]
Sent: 16 January 2013 11:49
To: [email protected]
Subject: Re: [dk-tug] [OT] emacs makro

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



_______________________________________________
[email protected] mailing list
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.