From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: latex <-> org ? Date: Thu, 4 Dec 2008 18:12:31 -0500 Message-ID: <20081204231231.GE8550@stats.ox.ac.uk> References: <20081204165144.GA8550@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L8NN9-0004yv-Ew for emacs-orgmode@gnu.org; Thu, 04 Dec 2008 18:12:39 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L8NN7-0004xW-HL for emacs-orgmode@gnu.org; Thu, 04 Dec 2008 18:12:38 -0500 Received: from [199.232.76.173] (port=50852 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L8NN7-0004xQ-9a for emacs-orgmode@gnu.org; Thu, 04 Dec 2008 18:12:37 -0500 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:48952) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L8NN6-00065F-R0 for emacs-orgmode@gnu.org; Thu, 04 Dec 2008 18:12:37 -0500 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id mB4NCX7q012441 for ; Thu, 4 Dec 2008 23:12:33 GMT Content-Disposition: inline In-Reply-To: <20081204165144.GA8550@stats.ox.ac.uk> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs org-mode mailing list For what it's worth, here's my attempt at a simple version of this. These flip a latex document into org mode so that you can see the document structure, and then flip it back, hopefully to the same latex document. #+begin_src ... #+end_src are inserted in the org version so that text in unfolded sections can be edited in latex-mode via C-c '. The only latex tags operated on are \section, \subsection and \subsubsection. But maybe a proper version of this already exists somewhere? Dan (defun org-latex-to-org () "Convert latex buffer to org." (interactive) (beginning-of-buffer) (if (save-excursion (re-search-forward "^\\\\title{\\([^}]*\\)}" nil t)) (insert (concat "#+title: " (match-string 1) "\n")) (insert "#+title: [No title found]\n")) (insert "* Preamble\n") (let (level dummy) (dotimes (level 3) (let (string) (dotimes (dummy level) (setq string (concat "sub" string))) ;; how do you make e.g. 'subsub'? (save-excursion (while (re-search-forward (concat "^\\\\" string "section\\(\\*?{.*\\)$") nil t) (replace-match (concat (make-string (1+ level) (string-to-char "*")) " " (replace-regexp-in-string "\\\\" "\\\\\\\\" (match-string 1))) ;; further '\'s might occur e.g. \label{} nil nil) (beginning-of-line) (insert "#+end_src\n") (end-of-line) (insert "\n#+begin_src latex")))))) (org-mode)) (defun org-latex-to-org-inverse () "Convert org buffer to latex. Intended to be the inverse of org-latex-to-org." (interactive) (latex-mode) (beginning-of-buffer) (kill-line 2) (save-excursion (while (re-search-forward "^#\\+begin_src latex" nil t) (kill-line 0) (kill-line))) (save-excursion (while (re-search-forward "^#\\+end_src" nil t) (kill-line 0) (kill-line))) (save-excursion (while (re-search-forward "^\\* \\(.*\\)$" nil t) (replace-match (concat "\\\\section" (replace-regexp-in-string "\\\\" "\\\\\\\\" (match-string 1))) nil nil))) (save-excursion (while (re-search-forward "^\\*\\* \\(.*\\)$" nil t) (replace-match (concat "\\\\subsection" (replace-regexp-in-string "\\\\" "\\\\\\\\" (match-string 1))) nil nil))) (save-excursion (while (re-search-forward "^\\*\\*\\* \\(.*\\)$" nil t) (replace-match (concat "\\\\subsubsection" (replace-regexp-in-string "\\\\" "\\\\\\\\" (match-string 1))) nil nil)))) On Thu, Dec 04, 2008 at 11:51:44AM -0500, Dan Davison wrote: > Has anyone worked on reversible transformation between org and latex? > I'm collaborating on a latex document with some non-org > users. Basically what I'd like to do is transform a latex document > into an org document, fold/unfold sections and edit the document under > org-mode, and then reconvert to latex. The end result would be as if > the transformation to org had never happened. > > At its simplest those functions would convert between '\section' <-> > '* section', '\subsection' <-> '** subsection' etc, but obviously > there's a lot more that could be done such as all the conversions that > org-export-to-latex does; I imagine that function couldn't be used > directly, but ideally the inverse of the latex->org function would > share conversion code with org-export-to-latex. Does this idea make > sense, and has anyone already worked on this? > > Dan > > -- > http://www.stats.ox.ac.uk/~davison > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode -- http://www.stats.ox.ac.uk/~davison