Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Latex2wiki

Translate a subset of LaTeX into MoinMoin wiki syntax.


   1  
   2  #!/usr/bin/env python
   3  
   4  #    Copyright (C) 2003, Maxime Biais <maxime@biais.org>
   5  #
   6  #    This program is free software; you can redistribute it and/or modify
   7  #    it under the terms of the GNU General Public License as published by
   8  #    the Free Software Foundation; either version 2 of the License, or
   9  #    (at your option) any later version.
  10  #
  11  #    This program is distributed in the hope that it will be useful,
  12  #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  #    GNU General Public License for more details.
  15  #
  16  #    You should have received a copy of the GNU General Public License
  17  #    along with this program; if not, write to the Free Software
  18  #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19  #
  20  # $Id: latex2wiki.py,v 1.1.1.1 2004/03/14 18:31:50 max Exp $
  21  
  22  import sys, re
  23  
  24  def dummy(d):
  25      pass
  26  
  27  NONE = "__@NONE@__"
  28  
  29  tr_list = [
  30      (r"\\includegraphics.*{(.*)\.eps}", "attachment::%s.png", dummy),
  31      (r"\\caption{.*}", "", dummy),
  32      (r"\\label{.*}", "", dummy),
  33      (r"(.*)\\emph{(.*)}(.*)", """%s'''%s'''%s""", dummy),
  34      (r"\\item (.*)", " * %s", dummy),
  35      (r"\\begin{.*}", "", dummy),
  36      (r"\\end{.*}", "", dummy),
  37      (r"(.*)``(.*)''(.*)", "%s\"%s\"%s", dummy),
  38      (r"\\chapter{(.*)}", NONE, dummy),
  39      (r"\\paragraph{(.*)}", "==== %s ====", dummy),
  40      (r"\\subsubsection{(.*)}", "==== %s ====", dummy),
  41      (r"\\subsection{(.*)}", "=== %s ===", dummy),
  42      (r"\\section{(.*)}", "== %s ==", dummy),
  43      (r"(.*)\\fig{.*}(.*)", "%s suivant %s", dummy)
  44      ]
  45  
  46  in_stream  = open(sys.argv[1], "r")
  47  if len(sys.argv) < 3:
  48      out_stream = sys.stdout
  49  else:
  50      out_stream = open(sys.argv[2], "w")
  51  
  52  
  53  for i in in_stream.readlines():
  54      cur_write = 0
  55      for reg in tr_list:
  56          m = re.search(reg[0], i)
  57          if m:
  58              reg[2](i)
  59              cur_write = 1
  60              if reg[1] == NONE:
  61                  break
  62              print >> out_stream, reg[1] % m.groups()
  63              break
  64      if not cur_write:
  65          out_stream.write(i)
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS