I can't speak for the OP, but when I do this, I don't really want to use hardcoded page numbers. I want to break up a book into volumes, and \includeonly doesn't do what I want because I want a single table of contents and a single index to be included in both volumes. I also want, e.g., to be able to do a \pageref from vol. 2 back to a page number in vol. 1.
The perl script below is what I use for this purpose. It invokes pdftk to filter the pdf file that was output by pdflatex. Because pdftk is buggy and poorly maintained, I would actually suggest that others do this kind of thing using pdfjam or poppler utils instead.
There is a configuration file that looks like this:
1,2,,3,ch:intro,-1,
1,1,ch:intro,0,splits:startvol2,-3,
2,2,splits:startvol2,-2,splits:index,-1,
1,2,splits:index,0,splits:data,-1,
1,2,splits:data,0,end,,5
The first line, for example, says that both volume 1 and volume 2 should start at page 3 and continue until one page before the first chapter. ch:intro is the latex label for the first chapter.
#!/usr/bin/perl
use strict;
my $input_file = $ARGV[0];
my $vol = $ARGV[1];
my $output_file = $ARGV[2];
# reads save.ref and splits.config
#
# format of splits.config:
# v1,v2,label1,offset1,label2,offset2,mod8
# (v1,v2)=(1,1) means only include these pages in volume 1
# (v1,v2)=(2,2) means only include these pages in volume 2
# (v1,v2)=(1,2) means include these pages in both volumes
# label1=latex label of beginning of range, or null
# offset1=offset from label1; if label1 is null string and offset is +, then take offset1 as page number; if label1 is 'end' and offset is '', take last page
# label2,offset2=similar for end of range
# mod8=if not null, force it to start on a page of the output pdf that equals this, modulo 8
# You typically want the output pdf to have a number of pages that is a multiple of 8. So, e.g., if LM has three pages of data, etc., at the end,
# set mod8 to 5, so that the third page will equal 7 mod 8.
my %refs = ();
open(F,"<save.ref") or die "error opening save.ref for input";
while (my $line = <F>) {
chomp $line;
if ($line =~ /([^,]*),([^,]*),([^,]*)/) {
my ($label,$name,$page) = ($1,$2,$3);
$refs{$label} = $page;
}
}
close(F);
open(F,"<splits.config") or die "error opening splits.config for input";
my @pages = ();
my $n = 0;
while (my $line = <F>) {
chomp $line;
if ($line =~ /([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)/) {
my ($v1,$v2,$l1,$o1,$l2,$o2,$m) = ($1,$2,$3,$4,$5,$6,$7);
#print "$v1,$v2,$l1,$o1,$l2,$o2,$m\n";
my $p1 = find_page($l1,$o1);
my $p2 = find_page($l2,$o2);
#print "pages $p1-$p2\n";
my $chunk = 0;
if ($vol>=$v1 && $vol<=$v2) {
if ($p1%2 != 1) {push @pages,"B1"; ++$chunk}
if ($m ne '') {
while (($n+$chunk)%8!=$m) {push @pages,"B1"; ++$chunk}
}
push @pages,"$p1-$p2";
if ($p2 ne 'end') {
$chunk += (($p2-$p1)+1);
if ($chunk%2!=0) {push @pages,"B1"; ++$chunk}
}
print "input $p1-$p2 -> output ",($n+1),"-",($p2 eq 'end' ? 'end' : $n+$chunk),"\n";
$n += $chunk;
}
}
}
close(F);
my $c = "pdftk $input_file B=../share/misc/blank_page.pdf cat ".join(' ',@pages)." output $output_file";
print "$c\n";
system $c;
sub find_page {
my $l = shift;
my $o = shift;
if ($l eq '') {return $o}
if ($l eq 'end') {return 'end'}
if (!exists $refs{$l}) {die "label $l doesn't exist in save.ref"}
return $refs{$l}+$o;
}
sub barf {
my $message = shift;
print STDERR "splits.pl: $message\n";
print STDERR "You will need to edit splits.config.\n";
exit(-1);
}
\input,\includeonlytype of solutions are not allowed right? I mean like this tex.stackexchange.com/questions/3462/… – percusse Feb 1 at 0:28