emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Harri Kiiskinen <harri.kiiskinen@utu.fi>
To: davison@stats.ox.ac.uk
Cc: emacs-orgmode@gnu.org
Subject: Re: latex <-> org ?
Date: Mon, 08 Dec 2008 14:39:18 +0200 (EET)	[thread overview]
Message-ID: <20081208.143918.07440426.harri.kiiskinen@utu.fi> (raw)
In-Reply-To: <20081204231231.GE8550@stats.ox.ac.uk>

Very nice! I've been hoping for this kind of functionality for a
while, since I'm really struggling to organize some text-mass produced
by myself over the years, and it seems, that with this I can
re-organize largish LaTeX-documents with relative ease. (For some
reason, the order in which a text is naturally written may not be the
one that is most interesting to read...)  A quick test drive gives ok,
the document is exactly the same (tested with diff) after having gone
through the conversion back and forth.

I think it is a good thing to keep this separate from any of the
org-mode export functions. As far as I can see, the main use for this
is the editing of already existing LaTeX file (as in the case of the
original request), where you have to keep the file as closely
resembling the original as possible.

Also, this does not seem like something you use all the time when
editing LaTeX-files, but more like a tool very handy for reorganizing
and restructuring your work, i.e. not a replacement for
org-export-latex, but a tool to integrate existing material to the
new, exciting org-mode work flow.

Harri K.

From: Dan Davison <davison@stats.ox.ac.uk>
Subject: Re: [Orgmode] latex <-> org ?
Date: Thu, 4 Dec 2008 18:12:31 -0500

> 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

  reply	other threads:[~2008-12-08 12:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-04 16:51 latex <-> org ? Dan Davison
2008-12-04 23:12 ` Dan Davison
2008-12-08 12:39   ` Harri Kiiskinen [this message]
2008-12-18 16:50     ` orgstruct minor mode (WAS: latex <-> org ?) Dan Davison
2008-12-19  8:40       ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081208.143918.07440426.harri.kiiskinen@utu.fi \
    --to=harri.kiiskinen@utu.fi \
    --cc=davison@stats.ox.ac.uk \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).