Skip to content

Commit

Permalink
(python) Initiate the work for publishing.
Browse files Browse the repository at this point in the history
- add some docstrings
- coherence of the variable names
  • Loading branch information
LaurentClaessens committed Sep 2, 2018
1 parent 6e035cc commit da50aa9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 27 deletions.
12 changes: 4 additions & 8 deletions lst_book.py
@@ -1,21 +1,17 @@
#! /usr/bin/python
# -*- coding: utf8 -*-

from __future__ import unicode_literals

import latexparser
import latexparser.PytexTools
from pytex.src import PytexTools
import commons
import plugins_agreg

myRequest = latexparser.PytexTools.Request("mesure")
myRequest = PytexTools.Request("mesure")
myRequest.ok_hash=commons.ok_hash
myRequest.original_filename="mazhe.tex"

# L'ordre dans les plugin est important parce que set_isFrido retourne un code latex sans les commentaires
# alors que keep_script_marks compte dessus pour faire sa sélection.
myRequest.add_plugin(latexparser.PytexTools.accept_all_input,"medicament")
myRequest.add_plugin(latexparser.PytexTools.keep_script_marks(plugins_agreg.frido_mark_list),"before_pytex")
myRequest.add_plugin(PytexTools.accept_all_input,"medicament")
myRequest.add_plugin(PytexTools.keep_script_marks(plugins_agreg.frido_mark_list),"before_pytex")


# the plugin "split_doc" should better be of type "medicament"
Expand Down
13 changes: 13 additions & 0 deletions python/debug_tools.py
@@ -0,0 +1,13 @@
# -*- coding: utf8 -*-

"""
This file contains some utilities for debugging.
"""

def dprint(*args):
"""
Same as "print", but easier to search/remove when I do not
need anymore.
"""
print(" ".join(args))

62 changes: 45 additions & 17 deletions python/split_book.py
Expand Up @@ -5,6 +5,32 @@
from pdfrw import PdfReader,PdfWriter
from splittoc import Book

"""
This script generates the pdf's for printing/commercialization
by thebookedition.com and lulu.com
Usage
-----
- compile with
```
pytex lst_book.py
```
this generates 0-book.pdf which will be used here to extract the
TOC/matters.
- launch this script
Number of volumes
-----------------
The variable `tot_volumes` is the number of volumes we want.
It has to be the same
- here
- in `lst_frido.py`
- in `lst_book.py`
"""

pdf_filename = "../0-book.pdf"
toc_filename = "../Inter_book-mazhe_pytex.toc"

Expand Down Expand Up @@ -82,33 +108,33 @@ def latex_code(title,year,v,imprimeur):
return text


def make_5_pages(n):
def make_5_pages(tot_volumes, title, year):
"""
This script creates the pdf of the firsts page for the commercialized Frido.
- two withe pages
- one with the title on the top (small)
- one speaking about the numerous versions of the book
- one with the copyright on the bottom
@param n (integer) the number of volumes
@param {int} `tot_volumes`
the number of volumes
"""
title = "Le Frido"
year = 2017

for imprimeur in ["lulu","thebookedition"]:
for v in range(1,n+1):
for imprimeur in ["lulu", "thebookedition"]:
for v in range(1, tot_volumes + 1):
code = latex_code(title,year,v,imprimeur)
filename = first_filename(v,imprimeur)+".tex"
with open(filename,'w') as f:
f.write(code)
os.system("pdflatex "+filename)

def split_book(book,n):
def split_book(book, tot_volumes):
"""
Split the book in 'v' volumes
@param book (type Book)
@param n (integer) the number of volumes
@param book (type Book)
@param {int} tot_volumes
the number of volumes
The 'book' parameter has to contain the pdf filename.
"""
Expand All @@ -117,10 +143,12 @@ def split_book(book,n):
print(book.get_chapter(n=1).title())
print(book.tot_pages())
print("Creating front matter")
book.sub_pdf(2,book.volume_first_page(1,n)-1,"front.pdf")
for v in range(1,n+1):
pI = book.volume_first_page(v,n)
pF = book.volume_last_page(v,n)
book.sub_pdf(2,
book.volume_first_page(1, tot_volumes) - 1,
"front.pdf")
for v in range(1, tot_volumes + 1):
pI = book.volume_first_page(v, tot_volumes)
pF = book.volume_last_page(v, tot_volumes)
filename = matter_filename(v)
print("Creating matter of volume {} : {} -> {}".format( v, pI, pF ))
book.sub_pdf(pI,pF,filename)
Expand All @@ -141,14 +169,14 @@ def concatenate(n):

outpdf.write(out_filename)

n = 4
tot_volumes = 4

# Creating the 5 first pages
make_5_pages(n)
make_5_pages(tot_volumes, title="Le Frido", year=2017)

# Creating the front and matter of the 4 books.
book = Book(toc_filename,pdf_filename)
split_book(book,n)
book = Book(toc_filename, pdf_filename)
split_book(book, tot_volumes)

# Concatenating the files
concatenate(n)
7 changes: 5 additions & 2 deletions python/splittoc.py
Expand Up @@ -12,6 +12,9 @@
"""

import os
from pdfrw import PdfReader

from debug_tools import dprint

class UnicodeCouple(object):
def __init__(self,iec,utf):
Expand Down Expand Up @@ -88,12 +91,12 @@ class Book(object):
This is a wrapper around a list of chapters.
"""
def __init__(self,toc_filename,pdf_filename=None):
def __init__(self, toc_filename, pdf_filename=None):
self.toc_filename = toc_filename
self.pdf_filename = pdf_filename
self.pdf_reader = None
if self.pdf_filename is not None :
from pdfrw import PdfReader
dprint('pdf_filename :', pdf_filename)
self.pdf_reader = PdfReader(self.pdf_filename)
def splitlines(self):
"""
Expand Down

0 comments on commit da50aa9

Please sign in to comment.