Debian Codegraph @

texk/texlive/linked_scripts/aomart/aom-fullref.pl

raw
1 #!/usr/bin/perl
2 #
3 # Convert the refences to \fullref. Usage:
4 # perl fullref.pl original.tex > converted.tex
5 #
6 #
7 #
8 # Author: Boris Veytsman
9 #
10 # Version: 1.0, 2025/01/08
11
12 =pod
13
14 =head1 NAME
15
16 aom-fullref.pl - confert references to aomart fullref commands
17
18 =head1 SYNOPSIS
19
20 aom-fullref.pl INPUT > OUTPUT
21
22
23 =head1 DESCRIPTION
24
25 Aomart class L<https://ctan.org/pkg/aomart> uses commands like
26 C<\fullref{Theorem}{ref}> to generate clickable reference to constructions
27 like ``Theorem 7'' or ``Equation 4''. This script changes all C<\ref> and
28 C<\pageref> commands into C<\fullref> and C<\pfullref> commands suitable
29 for use with aomart.
30
31
32 =head1 AUTHOR
33
34 Boris Veytsman
35
36 =head1 COPYRIGHT AND LICENSE
37
38 This work is in public domain and licensed under CC0 1.0
39
40 =cut
41
42
43 use strict;
44
45 # List of patterns for 'equation' words
46 my @eqsynonyms = ('\S*equa\S*', 'relat\S*', 'item\S*',
47 'condition\S*',
48 '\S*propert\S*');
49
50 # First we skip preamble
51 while(<>) {
52 print;
53 last if (/\\begin\{document\}/);
54 }
55
56 # This is a trick to catch \ref being the first word on the line
57 my $prevline = "";
58
59 # Processing document
60 while (<>) {
61 if ((/^[\s~]*\(?\\ref/) || (/^[\s~]*\\eqref/)) {
62 chomp $prevline;
63 $_ = "$prevline $_";
64 } else {
65 print $prevline;
66 }
67
68 # Now the meat of the substitutions
69 # We add initial space, so all words have space before them.
70 $_ = " $_";
71 foreach my $synonym (@eqsynonyms) {
72 s/(\s)($synonym)[\s~]*\(\\ref\{([^\}]+)\}\)/$1\\pfullref{$2}{$3}/gi;
73 s/(\s)($synonym)[\s~]*\\eqref\{([^\}]+)\}/$1\\eqfullref{$2}{$3}/gi;
74 }
75 s/(\s)([^\s\\]\S*[^~\s\(\)\[\]])[\s~]*\[\\ref\{([^\}]+)\}\]/$1\\bfullref{$2}{$3}/g;
76 s/(\s)([^\s\\]\S*[^~\s\(\)\[\]])[\s~]*\\ref\{([^\}]+)\}/$1\\fullref{$2}{$3}/g;
77 s/(\s)([^\s\\]\S*[^~\s\(\)\[\]])[\s~]*\\pageref\{([^\}]+)\}/$1\\fullpageref[$2]{$3}/g;
78 # Now delete the extra space
79 s/^ //;
80 $prevline=$_;
81 if (/\\end\{document\}/) {
82 print;
83 last;
84 }
85 }
86
87 # And processing whatever is left
88 while (<>) {
89 print;
90 }
91
92 exit 0;