[doconce] push by h...@simula.no - Implemented automatic upgrading and downgrading of all sections. on 2013-08-07 21:55 GMT

1 view
Skip to first unread message

doc...@googlecode.com

unread,
Aug 7, 2013, 5:55:59 PM8/7/13
to docon...@googlegroups.com
Revision: 15b12716504a
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Sun Aug 4 11:57:04 2013
Log: Implemented automatic upgrading and downgrading of all sections.
http://code.google.com/p/doconce/source/detail?r=15b12716504a

Modified:
/lib/doconce/doconce.py
/lib/doconce/misc.py
/test/make.sh

=======================================
--- /lib/doconce/doconce.py Thu Jul 18 20:58:04 2013
+++ /lib/doconce/doconce.py Sun Aug 4 11:57:04 2013
@@ -2095,6 +2095,29 @@
debugpr('%s\n**** The tex blocks:\n\n%s\n\n' % \
('*'*80, pprint.pformat(tex_blocks)))

+ # Lift sections up or down?
+ sections_up = option('sections_up')
+ sections_down = option('sections_down')
+ if sections_up or sections_down:
+ s2name = {9: 'chapter', 7: 'section',
+ 5: 'subsection', 3: 'subsubsection'}
+ for s in 9, 7, 5, 3:
+ if sections_up:
+ if s == 9:
+ continue
+ header_old = '='*s
+ header_new = '='*(s+2)
+ print 'transforming %s to %s...' % (s2name[s], s2name[s+2])
+ else:
+ if s == 3:
+ continue
+ header_new = '='*(s-2)
+ header_old = '='*s
+ print 'transforming %s to %s...' % (s2name[s], s2name[s-2])
+ pattern = r'=%s(.+?)=%s' % (header_old, header_old)
+ replacement = r'=%s\g<1>%s' % (header_new, header_new)
+ filestr = re.sub(pattern, replacement, filestr)
+
# Remove linebreaks within paragraphs
if option('oneline_paragraphs'): # (does not yet work well)
filestr = make_one_line_paragraphs(filestr, format)
=======================================
--- /lib/doconce/misc.py Sun Jul 21 01:24:05 2013
+++ /lib/doconce/misc.py Sun Aug 4 11:57:04 2013
@@ -88,6 +88,10 @@
'Write each table to a CSV file table_X.csv, where X is the table
number.'),
('--github_md',
'Turn on github-flavored-markdown dialect of the pandoc translator'),
+ ('--sections_up',
+ 'Upgrade all sections: sections to chapters, subsections to sections,
etc.'),
+ ('--sections_down',
+ 'Downgrade all sections: chapters to sections, sections to
subsections, etc.'),
]

_legal_command_line_options = \
=======================================
--- /test/make.sh Sun Jul 21 01:24:05 2013
+++ /test/make.sh Sun Aug 4 11:57:04 2013
@@ -44,7 +44,7 @@
system doconce format html testdoc --without_answers --without_solutions
$ex -DSOMEVAR --html_exercise_icon=default
cp testdoc.html testdoc_no_solutions.html

-system doconce format latex testdoc --without_answers --without_solutions
$ex -DSOMEVAR
+system doconce format latex testdoc --without_answers --without_solutions
$ex -DSOMEVAR --sections_down
cp testdoc.p.tex testdoc_no_solutions.p.tex

cp -r ../bundled/html_styles/style_vagrant .
Reply all
Reply to author
Forward
0 new messages