Imporve the titlegen script
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 22 Feb 2010 00:40:36 +0100
changeset 426df2bf124af4
parent 41 73fdafd843d9
child 43 7b789434b1af
Imporve the titlegen script
to correctly handle section numbers that are greater than ten
scripts/titlegen.py
     1.1 --- a/scripts/titlegen.py	Sun Feb 21 19:02:08 2010 +0100
     1.2 +++ b/scripts/titlegen.py	Mon Feb 22 00:40:36 2010 +0100
     1.3 @@ -5,6 +5,9 @@
     1.4  import copy
     1.5  import re
     1.6  
     1.7 +max_sec_number=100
     1.8 +max_sec_depth=4
     1.9 +
    1.10  def sec_inc(section, lev):
    1.11      while len(section)<lev:
    1.12          section.append(0)
    1.13 @@ -19,6 +22,21 @@
    1.14      s=s[:-1]
    1.15      return s
    1.16  
    1.17 +def compare_sec(id1, id2):
    1.18 +    id1=id1.split('.')
    1.19 +    c1=0
    1.20 +    for s in id1:
    1.21 +        c1=c1*max_sec_number+int(s)
    1.22 +    for i in range(len(id1), max_sec_depth+1):
    1.23 +        c1*=max_sec_number
    1.24 +    id2=id2.split('.')
    1.25 +    c2=0
    1.26 +    for s in id2:
    1.27 +        c2=c2*max_sec_number+int(s)
    1.28 +    for i in range(len(id2), max_sec_depth+1):
    1.29 +        c2*=max_sec_number
    1.30 +    return c1-c2
    1.31 +
    1.32  section = [];
    1.33  toc={}
    1.34  ind={}
    1.35 @@ -69,8 +87,8 @@
    1.36                  fo.write('%s| \\ref sec_toc "Home" |%s\n'%\
    1.37                               (prev_str,next_str))
    1.38              elif gr[3]:
    1.39 -                secs = [ x for x in toc]
    1.40 -                secs.sort()
    1.41 +                secs = [ x for x in toc ]
    1.42 +                secs.sort(compare_sec)
    1.43                  for num in secs:
    1.44                      fo.write("%s - \\ref %s\n"%('  '*((len(ind[toc[num]][0]))),
    1.45                                                  toc[num]))