File: fill-toc-ends

package info (click to toggle)
derivations 0.56.20180123.1-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 2,388 kB
  • sloc: cpp: 1,633; perl: 692; makefile: 158; sh: 153
file content (31 lines) | stat: -rwxr-xr-x 736 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /bin/bash -e

# The script takes two filenames as arguments: the *.toc and *.llg files
# LaTeX has generated, the latter on special instructions in the book's source.
# From the *.llg, it reads the page numbers of the book's table of contents,
# bibliography and index, writing to stdout an updated *.toc file with these
# entries added.

[[ $# == 2 ]] || false

OLDTOC=$1
PAGE_NO=$2

PROGDIR=$( dirname $0 )
TEXDIR=$PROGDIR/../tex

function page_no {
  sed -ne \
  "s/^[[:space:]]*$1[[:space:]]\\+\\([^[:space:]]\\+\\)[[:space:]]*\$/\\1/p;T;q" \
  $PAGE_NO
}

function toc_line {
  echo "\\contentsline {chapter}{$1}{$( page_no $1 )}"
}

toc_line Contents
sed -re 's/%?[[:space:]]*$//' $OLDTOC
toc_line Bibliography
toc_line Index