summaryrefslogtreecommitdiff
path: root/docs/users_guide_2_src/latex2rst.py
diff options
context:
space:
mode:
authorR. Tyler Ballance <tyler@monkeypox.org>2009-11-16 21:09:13 -0800
committerR. Tyler Ballance <tyler@monkeypox.org>2009-11-16 21:09:13 -0800
commitd9ce7916e309e2393d824e249f512d2629e5e181 (patch)
tree6b7ad5cd6292f6e017e048fbeb4551facbabd174 /docs/users_guide_2_src/latex2rst.py
parente43765a679b84c52df875e9629d303e304af50a1 (diff)
downloadpython-cheetah-docs.tar.gz
Revert "Delete the "old" docs directory to make way for fancy smancy sphinx"docs
This reverts commit 5dc95cfcd015628665d3672e56d0551943b5db6b.
Diffstat (limited to 'docs/users_guide_2_src/latex2rst.py')
-rwxr-xr-xdocs/users_guide_2_src/latex2rst.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/users_guide_2_src/latex2rst.py b/docs/users_guide_2_src/latex2rst.py
new file mode 100755
index 0000000..80f9a1d
--- /dev/null
+++ b/docs/users_guide_2_src/latex2rst.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+"""Convert files from LaTeX format to ReStructured Text.
+
+ This converter is meant only for saving keystrokes. It won't catch
+ everything and it may misformat stuff, so proofread the file after
+ processing.
+
+ "Verbatim" blocks are not converted due to the difficulty in placing the
+ preceding colon(s) and indenting every line.
+"""
+import os, re, shutil, sys
+
+def convert(filename):
+ print "Processing file", filename
+ backup = filename + ".bak"
+ shutil.copy2(filename, backup)
+ f = open(filename, 'r+')
+ text = f.read()
+ text = re.sub( R"%%%+", R"", text)
+ text = re.sub( R"\\section\{(.*?)\}", R"\1\n" + ("=" * 40), text)
+ text = re.sub( R"\\subsection\{(.*?)\}", R"\1\n" + ("-" * 40), text)
+ text = re.sub( R"\\label\{(.*?)\}", R"\n..\n :label: \1", text)
+ text = re.sub( R"``|''", R'"', text)
+ text = re.sub( R"(?s)\{\\em (.*?)\}", R"*\1*", text)
+ text = re.sub( R"(?s)\{\\bf (.*?)\}", R"**\1**", text)
+ text = re.sub( R"(?s)\\code\{(.*?)\}", R"``\1``", text)
+ text = re.sub( R"\\(begin|end)\{(itemize|enumerate)\}\n", R"", text)
+ text = re.sub( R"\\item ", R"* ", text)
+ #text = re.sub(
+ # R"(?sm)(\w):\n\s*^\\begin\{verbatim\}\s*(.*?)\\end\{verbatim\}",
+ # R"\1::\n\n\2", text)
+ f.seek(0)
+ f.write(text)
+ f.truncate()
+ f.close()
+
+
+def main():
+ if len(sys.argv) < 2:
+ prog = os.path.basename(sys.argv[0])
+ raise SystemExit("usage: %s FILENAMES ..." % prog)
+ for filename in sys.argv[1:]:
+ convert(filename)
+
+if __name__ == "__main__": main()