summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
authorAndreas Scherer <andreas_tex@freenet.de>2023-06-12 17:20:32 +0000
committerAndreas Scherer <andreas_tex@freenet.de>2023-06-12 17:20:32 +0000
commit9a5f9c80e970ca10e258a66efe58ca3a9cde07a5 (patch)
treedca0c6a596cb49e9d8ef90de1d2bde6de0776aef /Build/source
parent8ba1a4719a2d081268d5445abb7b6c273f1cd39b (diff)
[CWEB] Add Perl script to sort mini-indexes.
I am working on re-using the [ct]proofmac.tex macros in conjunction with HiTeX. My plan is to add HINT-related macros (e.g., from either cwebmac.tex or pdfctwimac.tex) in [ct]proofmac.tex that produce active links when processed with HiTeX. Instead of 'proofing' the mini-indexes, the simple page layout produced by [ct]proofmac.tex should perfectly match the dynamic page layout of the HINT format. Every section in the CWEB output is amended with its local mini-index. As a small step upfront, I hacked the Perl script [ct]proofsort that sorts the mini-index entries alphabetically. git-svn-id: svn://tug.org/texlive/trunk@67340 c570f23f-e606-0410-a88d-b1316a301751
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;