1 #!/bin/sh
2
3 # usage: fix_index.sh <file>.idx
4
5 # This script works around a hyperref bug: hyperref does not handle
6 # quotes in \index arguments properly.
7 #
8 # Symptom:
9 # When \index{-pipe-pipe@\verb`("|"|)`} appears in your .tex, the hyperref
10 # package mangles it and produces this line in your .idx:
11 # \indexentry{(-pipe-pipe)@\verb`("|hyperindexformat{\"}}{292}
12 # instead of the expected:
13 # \indexentry{(-pipe-pipe)@\verb`("|"|)`|hyperpage}{292}
14 #
15 # This is because it fails to handle quoted characters correctly.
16 #
17 # The workaround:
18 # Look for the buggy line in the given .idx file and change it.
19
20 # Note: this bug will happen every time you have a | (pipe) character
21 # in an index entry (properly quoted with a " (double-quote) before it).
22 # We fix only the one case that appears in the OCaml documentation.
23 # We do not attempt a general solution because hyperref erases part
24 # of the argument, so we cannot recover the correct string from its
25 # output.
26
27 # Note 2013-06-19:
28 # The above was for the || operator in the stdlib's Pervasives module.
29 # Now we have the same problem with the |> operator that was added
30 # to the same module in commit 13739, hence the second special case.
31
32 usage(){
33 echo "usage: fix_index.sh <file>.idx" >&2
34 exit 2
35 }
36
37 case $# in
38 1) ;;
39 *) usage;;
40 esac
41
42 sed < "$1" > "$1.new" \
43 -e 's/verb`("|hyperindexformat{\\"}/verb`("|"|)`|hyperpage/' \
44 -e 's/verb`("|hyperindexformat{\\>)`}/verb`("|>)`|hyperpage/'
45
46 case $? in
47 0) echo "fix_index.sh: fixed $1 successfully.";;
48 *) echo "fix_index.sh: some error occurred."; exit 1;;
49 esac
50
51 mv "$1.new" "$1"
52