[PATCH -perfbook 1/4] cleverefcheck.pl: Add test of listing next to heading

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



There is a side effect of fancyvrb, or the Verbatim{L|N|U}
environments derived from Verbatim, in that floating "listing"
environments placed just next to chapter/section headings are
treated as page/column-break candidates, and results in a widowed
heading.

Other floating objects such as "figure" and "table" do not
have this issue as long as they are free of fancyvrb.

Add tests to detect "listing" environments who come next to
\chapter/\section/\subsection/... commands.

Signed-off-by: Akira Yokosawa <akiyks@xxxxxxxxx>
---
 utilities/cleverefcheck.pl | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/utilities/cleverefcheck.pl b/utilities/cleverefcheck.pl
index 0085fdb5..f46cd89f 100755
--- a/utilities/cleverefcheck.pl
+++ b/utilities/cleverefcheck.pl
@@ -25,8 +25,11 @@ my $IX_ptn = qr/(^|\s+)IX[^\s\{]*{/ ;
 my $api_ptn = qr/(^|\s+)api[^\s\{]*{/ ;
 my $ppl_ptn = qr/(^|\s+)ppl[^\s\{]*{/ ;
 my $acr_ptn = qr/(^|\s+)[aA]cr[^\s\{]*{/ ;
+my $heading_ptn = qr/(\\chapter|\\section|\\subsection|\\subsubsection)/ ;
+my $listing_ptn = qr/\\begin\{(listing|Verbatim)/ ;
 my $in_footnote = 0 ;
 my $footnote_save = 0;
+my $after_heading = 0;
 
 sub check_line {
     my $raw_line = $line;
@@ -102,6 +105,18 @@ sub check_line {
 	    print $ARGV[0], ':', $line_num, ':', $raw_line;
 	}
     }
+    if ($after_heading) {
+	if ($line =~ /^\s*$/) {
+	    # ignore empty/blank line
+	}
+	if ($line =~ /^\s*\{*[A-Za-z0-9]/) {
+	    $after_heading = 0 ;  # normal line, OK
+	}
+	if ($line =~ /$listing_ptn/) {
+	    print $ARGV[0], ':', $line_num, ':', $raw_line, "^^^ listing next to heading ^^^\n";
+	    $after_heading = 0 ;
+	}
+    }
     if ($line =~ /$Verbatim_end/) {
 	$skip = 0;
     } else {
@@ -135,6 +150,9 @@ sub check_line {
 	    }
 	}
     }
+    if ($line =~ /$heading_ptn/) {
+	$after_heading = 1 ;
+    }
 }
 
 open(my $fh, '<:encoding(UTF-8)', $ARGV[0])
-- 
2.17.1





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux