summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/texk/web2c/cwebdir/ChangeLog4
-rwxr-xr-xBuild/source/texk/web2c/cwebdir/ctproofsort52
2 files changed, 56 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/cwebdir/ChangeLog b/Build/source/texk/web2c/cwebdir/ChangeLog
index 4f602ec35a1..78996467f82 100644
--- a/Build/source/texk/web2c/cwebdir/ChangeLog
+++ b/Build/source/texk/web2c/cwebdir/ChangeLog
@@ -1,3 +1,7 @@
+2023-06-12 Andreas Scherer <https://ascherer.github.io>
+
+ * ctproofsort: Sort mini-indexes in CTWILL output.
+
2023-05-26 Andreas Scherer <https://ascherer.github.io>
* examples/wordtest.w: Fix page number for Aragon and Seidel.
diff --git a/Build/source/texk/web2c/cwebdir/ctproofsort b/Build/source/texk/web2c/cwebdir/ctproofsort
new file mode 100755
index 00000000000..7b8c2332d2d
--- /dev/null
+++ b/Build/source/texk/web2c/cwebdir/ctproofsort
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+# This small Perl script 'proofsort' sorts the mini-indexes for each
+# section in the TeX fiie created by 'ctwill +P', i.e., prior to
+# formatting with the 'proofmac.tex' macros.
+#
+# Example from MMIX:
+# $ tie -c mmotype-twill.ch mmotype.{w,ch} mmotype-mini.ch
+# $ ctwill +P -x mmotype mmotype-twill
+# $ ./proofsort mmotype.tex > mmotype-sorted.tex
+# $ mv mmotype-sorted.tex mmotype.tex
+# $ tex mmotype
+#
+# Public domain. Originally written by Andreas Scherer, 2023.
+
+use strict;
+use warnings;
+
+# We expect a TeX file as the single command-line parameter.
+die "$0 input_file\n" unless scalar @ARGV;
+
+my $tex=$ARGV[0];
+
+open(TEX, $tex) or die "Could not open input file $tex.";
+
+my %mini_index; # storage for index entries of a section
+my $print_index=0; # do we collect and print a mini-index?
+
+foreach my $line (<TEX>) {
+ chomp($line);
+
+ if ('\\mini' eq $line) { # start of mini-index
+ $print_index=1;
+ %mini_index=(); # reset mini-index
+ } elsif ('}\\FI' eq $line) { # end of mini-index
+ foreach my $key (sort keys %mini_index) {
+ print "$mini_index{$key}\n";
+ }
+ $print_index=0;
+ } elsif ($print_index) { # mini-index entry
+ my ($location,$key) = split / /, $line; # 2nd column is the key
+ $key=~s/\\//g; # strip TeX escape(s)
+ $key=~m/\w*\{(\w+)\}/; # extract plain key
+ $mini_index{$1}=$line; # store index entry
+ next; # print later
+ }
+
+ print "$line\n";
+}
+
+close(TEX);
+
+exit 0;