Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to compile all of the books in a series at the same time. This would:

  • Guarantee that everything compiled with consistency.
  • Easily allow for cross-references between books.
  • Allow counters from one book to be conveniently carried to the next.

With the book document class, one can assign parts, chapters, and sections. Is there a way to assign volumes? E.g.:

\book{This is the book's title}
    \part{This is the part's title}
        \chapter{This is the chapter's title}
\book{This is the second book's title}
share|improve this question
    
Which LaTeX document class are you using? Is it book? Would you be willing to consider using the memoir document class? –  Mico Jan 18 '12 at 14:04
add comment

5 Answers

up vote 17 down vote accepted

Using the memoir document class you have a new "sectional unit" \book that serves your purposes. Refer to Chapter 6 of the documentation, particularly, Sections 6.2 SECTIONAL DIVISIONS, 6.3 NUMBERING, and 6.4 BOOK AND PART HEADINGS.

share|improve this answer
2  
Is there any package which allows this behavior when not using the memoir document class? Or is there a way to load only this feature from this class, but no other components? –  Village Dec 17 '11 at 1:34
    
@Village: other than anon's suggestion, there's not such a package, as far as I know. –  Gonzalo Medina Dec 17 '11 at 1:44
add comment

Guarantee that everything compiles with consistency

You will have consistent documents when you avoid redundancy. Check your files carefully if you define the same properties or styles twice (e.g. colours, lengths, abbreviations, …).

Move all mutual elements to dedicated environment files and include those in your books. You can find more information about this on the ConTeXt wiki - Project Structure and the ConTeXt magazine #1101. Content files not containing any style information and the style information that is shared between the individual volumes leads to consistency.

Easily allow for cross-references between books

Cross-references are supported by default. You either prepend the reference with filename:: or you can use the more generic command \useexternaldocument. Example:

% file: crossref.tex
\useexternaldocument [introduction] [intro.tex]
\starttext
    Here comes a reference to the intro:
    \in{chapter}[intro::sec:intro] on \at{page}[intro::sec:intro]

    Or, more generic, using useexternaldocument:
    \in{chapter}[introduction::sec:intro] on \at{page}[introduction::sec:intro]
\stoptext

% file: intro.tex
\starttext
    \null\page
    \startchapter [title=Intro, reference=sec:intro]
    \stopchapter
\stoptext

Here's a screenshot from the file crossref.tex:

crossref

Remember to use a double colon for cross-referencing, in contrast to the more common variant of using a single one for in-document references.

Allow counters from one book to be conveniently carried to the next

I don't think this is natively supported. But you can misuse the referencing mechanism, since it supports counting and cross-document access. Of course, you are again free to use the \useexternaldocument feature. Example:

% file: savecounter.tex
\starttext
    Here I store a number that can be obtained in the
        other file:
    \reference [mycount] {42}
\stoptext

% file: crosscounter.tex
\useexternaldocument [cross] [savecounter.tex]
\starttext
    And here is the number from the savecounter file:
    \getreference [text] [savecounter::mycount]

    Using the useexternaldocument mechanism:
    \getreference [text] [cross::mycount]
\stoptext

Here's a screenshot from the file crosscounter.tex:

crosscounter

Since the reference mechanism saves more information than we need, we provide an argument in brackets containing text, which retrieves the value that was saved before as the second argument of the \reference command.

And again: Remember to use a double colon for the cross-document reference.

You can create an interface to define, change and retrieve the counters if you like. The low-level ommands look quite ugly in the document and are even semantically wrong.

share|improve this answer
add comment

As others have said you can use xr to manage cross references between documents. If you want counters to be preserved, I'm not sure if there is a ready made package on ctan but it is easy to save the state of the counters at the end of one document and reset them at the start of the next.

for example if you latex b1 and then b2 using the following the equations and tables in b2 will carry on from where they left off in b1.

%savecounters.sty


\def\savecounters#1{%
\newwrite\SC@counters
\immediate\openout\SC@counters=\jobname-counters.tex
\AtEndDocument{
\@for\c:=#1\do{
\immediate\write\SC@counters{\noexpand\setcounter{\c}{\arabic{\c}}}
}
}
}

b1.tex

\documentclass{book}

\usepackage{savecounters}

\savecounters{equation,table}

\begin{document}

\begin{table}
Table
\caption{a table}
\end{table}

\begin{equation}
1=1
\end{equation}


\begin{equation}
1=2
\end{equation}

\end{document}

b2.tex

\documentclass{book}
\input{b1-counters}
\begin{document}

\begin{table}
Table
\caption{a table}
\end{table}

\begin{equation}
1=1
\end{equation}


\begin{equation}
1=2
\end{equation}

\end{document

}

share|improve this answer
add comment

I do this using pdftk and the perl script shown below. One advantage of this approach is that you can have certain content reproduced in each volume. For example, I have pages numbered sequentially across volumes, and a single index and table of contents which are reproduced in all volumes. That way, if you have volume 2, you can look up something in the index and find out that it's on p. 37 of volume 1.

If you have material (e.g., a quick reference page) that you want to end up on the final page of a printed book, there is a mechanism for that as well. Typically the number of pages in a printed book is a multiple of 8, so you need to add blank pages to get the material to end up on the very last interior page.

It reads your .ref file (here assumed to be save.ref) to find the labels used to mark the beginning or end of a section. That way you don't have to keep updating the page numbers of the split-points by hand.

#!/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);
    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);
}
share|improve this answer
add comment

There is no need to compile the books all at once: the xr package easily allows for cross-references between books, and it allows counters from one book to be conveniently carried to the next. With hyperref, links will work between different books.

share|improve this answer
    
I looked at the documentation for xr, but it seems to only allow a reference to one other document. How can I specify references to many different documents? –  Village Dec 16 '11 at 13:18
    
xr allows external reference to any number of documents. –  egreg Jan 18 '12 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.