"""
1999 Manuel Gutierrez Algaba
You are free to use , modify, distribute and copy this piece of
python code, if you keep this free copyright notice in it.
sectioner.py Version 1.0
relative sectioning of code:
Given a source in LaTeX, it generates the \sections, \subsections,
.., in an automatic way.
It abstracts the idea of absolute sectioning of LaTeX , and supplies
relative positioning. It makes document more independent of their
type. The decission article-report-miarticle can be done in the end
, not when you start to write the document.
Possibly you can use it ( adapting it a bit ) in TeX, or another
sorts of languages of typesseting.
how to use:
python sectioner.py method inputfile outputfile
"""
"""
You use a command in a single line, and in the next line you
put the title of that (sub)section or whatever. And it should
be in the first column of the line.
For example:
\n
Coding Decissions.
<Body of this part>
..
It uses the following commands:
\n : This says the next section is at the same current level.
\+ : This goes a level down
\- : A level up
\+4 ( or any other number ) : 4 levels down
\-4: 4 levels up
\minput{name of file} : This includes another file of sectioner-LaTeX
style.
For more details see the example:
highnest.tex ( a source of sectioner-LaTeX )
"""
import sys
import re
import string
print sys.argv
if not sys.argv[1:] or not sys.argv[2:] or not sys.argv[3:]:
print "usage: python sectioner.py method inputfile outputfile"
print "method can be 'manolo' or it can be article or report"
print "And you should include all the parameters"
sys.exit(2)
def process_lines_in_file(lines_in_file):
next = 0
global level
for i in lines_in_file:
if i[0]=="\\" and i[1] in "+-" and i[2] in "123456789":
signo = i[1]
if signo == '+':
level = level + eval(i[2])
else:
level = level - eval(i[2])
counters[level] = counters[level] + 1
next = 0
continue
if i[0]=="\\" and i[1]=="n":
counters[level] = counters[level] + 1
next = 1
continue
if i[0]=="\\" and i[1]=="+":
level = level + 1
counters[level] = 1
next = 1
continue
if i[0]=="\\" and i[1]=="-":
#counters[level] = 0
level = level - 1
counters[level] = counters[level] + 1
next = 1
continue
mmatch = minputfile.match(i)
if not mmatch is None:
print mmatch.group('file')
process_file(mmatch.group('file'))
continue
if next == 1:
#print counters[level]
#print range(0,1)
t= ""
for k in range(0,level+1):
t = t+ `counters[k]`+"."
#print t,i, # por culpa de tener antes una linea
outputfile.write(dic_sections[level]+"{"+string.strip(i)+"}\n")
next = 0
continue
outputfile.write(i)