Skip to content

Commit

Permalink
[svn r3571] r4028@delle: sbehnel | 2008-04-22 23:30:05 +0200
Browse files Browse the repository at this point in the history
 PDF layout fixes

--HG--
branch : trunk
  • Loading branch information
scoder committed Apr 23, 2008
1 parent 45ab7f4 commit 21dfe8d
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions doc/mklatex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@

replace_invalid = re.compile(r'[-_/.\s\\]').sub

# LaTeX snippets

DOCUMENT_CLASS = r"""
\documentclass[10pt,english]{report}
\usepackage[a4paper]{geometry}
\parindent0pt
\parskip1ex
"""

PYGMENTS_IMPORT = r"""
\usepackage{fancyvrb}
\input{_part_pygments.tex}
"""

def write_chapter(master, title, outname):
master.write(r"""
\chapter{%s}
\label{_part_%s}
\input{_part_%s}
""".replace(' ', '') % (title, outname, outname))


# the program ----

def rest2latex(script, source_path, dest_path):
command = ('%s %s %s %s > %s' %
(sys.executable, script, RST2LATEX_OPTIONS,
Expand Down Expand Up @@ -182,24 +206,18 @@ def fix_changelog(line):
print "Building %s\n" % TARGET_FILE
master = file( os.path.join(dirname, TARGET_FILE), "w")
for hln in header:
if hln.startswith("\\documentclass"):
if hln.startswith(r"\documentclass"):
#hln = hln.replace('article', 'book')
hln = "\\documentclass[10pt,english]{book}\n\\usepackage[a4paper]{geometry}\n"
elif hln.startswith("\\begin{document}"):
hln = DOCUMENT_CLASS
elif hln.startswith(r"\begin{document}"):
# pygments support
master.write("\\usepackage{fancyvrb}\n")
master.write("\\input{_part_pygments.tex}\n")
elif hln.startswith("\\title{"):
master.write(PYGMENTS_IMPORT)
elif hln.startswith(r"\title{"):
hln = re.sub("\{[^\}]*\}", '{%s}' % book_title, hln)
master.write(hln)

master.write("\\tableofcontents\n\n")

def write_chapter(title, outname):
master.write(
"\\chapter{%s}\n\\label{_part_%s}\n\n\\input{_part_%s}\n\n" % (
title, outname, outname))

for section, text_files in SITE_STRUCTURE:
master.write("\\part{%s}\n\n" % section)
for filename in text_files:
Expand All @@ -213,11 +231,11 @@ def write_chapter(title, outname):
basename = os.path.splitext(os.path.basename(filename))[0]
basename = BASENAME_MAP.get(basename, basename)
outname = basename + '.tex'
write_chapter(titles[outname], outname)
write_chapter(master, titles[outname], outname)

write_chapter("Changes", chgname)
write_chapter(master, "Changes", chgname)

master.write("\end{document}\n")
master.write("\\end{document}\n")

if __name__ == '__main__':
publish(sys.argv[1], sys.argv[2], sys.argv[3])

0 comments on commit 21dfe8d

Please sign in to comment.