eBook to print book conversion script

2009-11-10 Thread Steve Litt
Hi all,

For the first time I must maintain a book as an eBook AND a pBook. You can't 
really use the same PDF for both...

The pBook must have gutter margins to make up for the binding, so the left and 
right margin will be different and switch places between even and odd pages. 
For best screen reading, the eBook margins should remain constant between even 
and odd pages.

The eBook has an integrated cover page, the pBook does not. The eBook footers 
are maroon background and contain the legend Prepared exclusively for John 
Customer, whereas for minimal toner usage the pBook is all white in that 
area.

I REALLY don't want to maintain two LyX documents, coordinating modifications  
between the two. So I maintain only the eBook LyX doc, and have a script that 
reads the eBook LyX and spits out a pBook PDF.

The perl script is a filter whose stdin is the eBook LyX doc, and whose output 
is the pBook LyX document. The perlscript is a state machine, with state 
defined by a variable called $skip.

Skip=0: Document preamble
Skip=1: Document body, cover page or back of cover page
Skip=2: Found start here marker inside LyX Note inset.
Skip=3: Found the end of that LyX Note inset
Skip=4: Passed the end of the inset, include everything else

Here is the e2b.pl perlscript:

==
#!/usr/bin/perl -w
use strict;

my $skip = 0;
my $line;
while(){
$line = $_;
chomp $line;
if($skip == 0){
if ($line =~ m/\\myfooter/){
$line = '';
}
elsif($line =~ m/\\begin_body/){
print $line . \n\n;
print \\begin_layout Standard\n;
$skip = 1;
}
elsif($line =~ m/\\leftmargin/){
$line = '\\leftmargin 2.3in';
}
elsif($line =~ m/\\rightmargin/){
$line = '\\rightmargin 1.3in';
}

}
elsif(($skip == 1)  ($line =~ m/start_of_print_version_here/)){
$skip = 2;
}
elsif(($skip == 2)  ($line =~ m/^\\end_inset$/)){
$skip = 3;
}
elsif($skip == 3){
$skip = 4;
}
if(($skip == 0) || ($skip == 4)){
print $line . \n;
}
}
==

There's also an e2b.sh that makes the pBook LyX a temporary file and compiles 
down to a PDF.

When $skip==0, I detect left and right margin and change them and I eliminate 
the footer (\myfooter).

All books are different, so your mileage may vary, but if you have a doc that's 
sometimes an eBook and sometimes a pBook, you can do something like this.

StevET

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt




eBook to print book conversion script

2009-11-10 Thread Steve Litt
Hi all,

For the first time I must maintain a book as an eBook AND a pBook. You can't 
really use the same PDF for both...

The pBook must have gutter margins to make up for the binding, so the left and 
right margin will be different and switch places between even and odd pages. 
For best screen reading, the eBook margins should remain constant between even 
and odd pages.

The eBook has an integrated cover page, the pBook does not. The eBook footers 
are maroon background and contain the legend Prepared exclusively for John 
Customer, whereas for minimal toner usage the pBook is all white in that 
area.

I REALLY don't want to maintain two LyX documents, coordinating modifications  
between the two. So I maintain only the eBook LyX doc, and have a script that 
reads the eBook LyX and spits out a pBook PDF.

The perl script is a filter whose stdin is the eBook LyX doc, and whose output 
is the pBook LyX document. The perlscript is a state machine, with state 
defined by a variable called $skip.

Skip=0: Document preamble
Skip=1: Document body, cover page or back of cover page
Skip=2: Found start here marker inside LyX Note inset.
Skip=3: Found the end of that LyX Note inset
Skip=4: Passed the end of the inset, include everything else

Here is the e2b.pl perlscript:

==
#!/usr/bin/perl -w
use strict;

my $skip = 0;
my $line;
while(){
$line = $_;
chomp $line;
if($skip == 0){
if ($line =~ m/\\myfooter/){
$line = '';
}
elsif($line =~ m/\\begin_body/){
print $line . \n\n;
print \\begin_layout Standard\n;
$skip = 1;
}
elsif($line =~ m/\\leftmargin/){
$line = '\\leftmargin 2.3in';
}
elsif($line =~ m/\\rightmargin/){
$line = '\\rightmargin 1.3in';
}

}
elsif(($skip == 1)  ($line =~ m/start_of_print_version_here/)){
$skip = 2;
}
elsif(($skip == 2)  ($line =~ m/^\\end_inset$/)){
$skip = 3;
}
elsif($skip == 3){
$skip = 4;
}
if(($skip == 0) || ($skip == 4)){
print $line . \n;
}
}
==

There's also an e2b.sh that makes the pBook LyX a temporary file and compiles 
down to a PDF.

When $skip==0, I detect left and right margin and change them and I eliminate 
the footer (\myfooter).

All books are different, so your mileage may vary, but if you have a doc that's 
sometimes an eBook and sometimes a pBook, you can do something like this.

StevET

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt




eBook to print book conversion script

2009-11-10 Thread Steve Litt
Hi all,

For the first time I must maintain a book as an eBook AND a pBook. You can't 
really use the same PDF for both...

The pBook must have gutter margins to make up for the binding, so the left and 
right margin will be different and switch places between even and odd pages. 
For best screen reading, the eBook margins should remain constant between even 
and odd pages.

The eBook has an integrated cover page, the pBook does not. The eBook footers 
are maroon background and contain the legend "Prepared exclusively for John 
Customer", whereas for minimal toner usage the pBook is all white in that 
area.

I REALLY don't want to maintain two LyX documents, coordinating modifications  
between the two. So I maintain only the eBook LyX doc, and have a script that 
reads the eBook LyX and spits out a pBook PDF.

The perl script is a filter whose stdin is the eBook LyX doc, and whose output 
is the pBook LyX document. The perlscript is a state machine, with state 
defined by a variable called $skip.

Skip=0: Document preamble
Skip=1: Document body, cover page or back of cover page
Skip=2: Found "start here" marker inside LyX Note inset.
Skip=3: Found the end of that LyX Note inset
Skip=4: Passed the end of the inset, include everything else

Here is the e2b.pl perlscript:

==
#!/usr/bin/perl -w
use strict;

my $skip = 0;
my $line;
while(<>){
$line = $_;
chomp $line;
if($skip == 0){
if ($line =~ m/\\myfooter/){
$line = '';
}
elsif($line =~ m/\\begin_body/){
print $line . "\n\n";
print "\\begin_layout Standard\n";
$skip = 1;
}
elsif($line =~ m/\\leftmargin/){
$line = '\\leftmargin 2.3in';
}
elsif($line =~ m/\\rightmargin/){
$line = '\\rightmargin 1.3in';
}

}
elsif(($skip == 1) && ($line =~ m/start_of_print_version_here/)){
$skip = 2;
}
elsif(($skip == 2) && ($line =~ m/^\\end_inset$/)){
$skip = 3;
}
elsif($skip == 3){
$skip = 4;
}
if(($skip == 0) || ($skip == 4)){
print $line . "\n";
}
}
==

There's also an e2b.sh that makes the pBook LyX a temporary file and compiles 
down to a PDF.

When $skip==0, I detect left and right margin and change them and I eliminate 
the footer (\myfooter).

All books are different, so your mileage may vary, but if you have a doc that's 
sometimes an eBook and sometimes a pBook, you can do something like this.

StevET

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt