texlive[67340] Build/source/texk/web2c/cwebdir: [CWEB] Add Perl

commits+ascherer at tug.org commits+ascherer at tug.org
Mon Jun 12 19:20:33 CEST 2023


Revision: 67340
          http://tug.org/svn/texlive?view=revision&revision=67340
Author:   ascherer
Date:     2023-06-12 19:20:32 +0200 (Mon, 12 Jun 2023)
Log Message:
-----------
[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.

Modified Paths:
--------------
    trunk/Build/source/texk/web2c/cwebdir/ChangeLog

Added Paths:
-----------
    trunk/Build/source/texk/web2c/cwebdir/ctproofsort

Modified: trunk/Build/source/texk/web2c/cwebdir/ChangeLog
===================================================================
--- trunk/Build/source/texk/web2c/cwebdir/ChangeLog	2023-06-11 23:42:53 UTC (rev 67339)
+++ trunk/Build/source/texk/web2c/cwebdir/ChangeLog	2023-06-12 17:20:32 UTC (rev 67340)
@@ -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.

Added: trunk/Build/source/texk/web2c/cwebdir/ctproofsort
===================================================================
--- trunk/Build/source/texk/web2c/cwebdir/ctproofsort	                        (rev 0)
+++ trunk/Build/source/texk/web2c/cwebdir/ctproofsort	2023-06-12 17:20:32 UTC (rev 67340)
@@ -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;


Property changes on: trunk/Build/source/texk/web2c/cwebdir/ctproofsort
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property


More information about the tex-live-commits mailing list.