Teach utilities/punctcheck.sh of the pattern for the percent sign by
adding utilities/percentcheck.pl and letting it invoked along with
utilities/punctcheck.pl.

It could be added in punctcheck.pl, but doing so would further complicate
the script.  Therefore, a dedicated script.

Signed-off-by: Akira Yokosawa <[email protected]>
---
 utilities/percentcheck.pl | 39 +++++++++++++++++++++++++++++++++++++++
 utilities/punctcheck.sh   |  1 +
 2 files changed, 40 insertions(+)
 create mode 100755 utilities/percentcheck.pl

diff --git a/utilities/percentcheck.pl b/utilities/percentcheck.pl
new file mode 100755
index 00000000..0fe83276
--- /dev/null
+++ b/utilities/percentcheck.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Check LaTeX source of percent sign
+#
+# Copyright (C) Akira Yokosawa, 2025
+#
+# Authors: Akira Yokosawa <[email protected]>
+
+use strict;
+use warnings;
+
+my $line;
+my $line_num = 0;
+my $next_line;
+
+sub check_percent {
+    my $line_raw = $line;
+    if ($line =~ /[0-9]+(\\,)?\\%/) {
+       print $ARGV[0], ':', $line_num, ': ', $line_raw;
+       print "Hint: Use \\pct for percent sign as unit, say \\pct\\ if no 
punct follows.\n";
+    }
+    if ($line =~ /[0-9]+\\pct[ \s]/) {
+       print $ARGV[0], ':', $line_num, ': ', $line_raw;
+       print "Hint: Say \\pct\\ in mid-sentence.\n";
+    }
+}
+
+open(my $fh, '<:encoding(UTF-8)', $ARGV[0])
+    or die "Could not open file '$ARGV[0]' $!";
+
+$line = <$fh>;
+$line_num = 1;
+while($next_line = <$fh>) {
+    check_percent();
+    $line = $next_line;
+    $line_num++ ;
+}
+check_percent();
diff --git a/utilities/punctcheck.sh b/utilities/punctcheck.sh
index d0ade754..cf264243 100755
--- a/utilities/punctcheck.sh
+++ b/utilities/punctcheck.sh
@@ -21,4 +21,5 @@ done
 for g in $tex_sources
 do
        utilities/punctcheck.pl $g
+       utilities/percentcheck.pl $g
 done
-- 
2.43.0



Reply via email to