\n";}
if (defined $title) {formatprint($title."\n",'h2');}
if ($outputtemplate) {
_print_count_template($count,$outputtemplate);
} elsif ($briefsum && @sumweights) {
_print_sum_count($count);
} elsif ($briefsum) {
if ($htmlstyle) {print "
";}
_print_count_brief($count);
if ($htmlstyle) {print "
\n";}
} else {
_print_count_details($count);
}
if ($htmlstyle) {print "
\n";}
}
# Return count,header,... list filling in header if missing
sub __count_and_header {
my $count=shift @_;
my $header=__count_header($count);
return $count,$header,@_;
}
# Return count title or '' if missing
sub __count_header {
my $count=shift @_;
return $count->{'title'}||'';
}
# Print total count (sum) for a given count object
sub _print_sum_count {
my ($count,$header)=__count_and_header(@_);
if ($htmlstyle) {print "".text_to_print($header).": ";}
print get_sum_count($count);
if ($htmlstyle) {print "
\n";}
else {print ": ".text_to_print($header);}
print "\n";
}
# Print brief summary of count object
sub _print_count_brief {
my ($count,$header,$tag1,$tag2)=__count_and_header(@_);
my @cnt=@{$count->{'counts'}};
if ($htmlstyle && $tag1) {print '<',$tag1,'>';}
print $cnt[$CNT_WORDS_TEXT],'+',$cnt[$CNT_WORDS_HEADER],'+',$cnt[$CNT_WORDS_OTHER];
for (my $i=$SIZE_CNT_DEFAULT;$i<$SIZE_CNT;$i++) {
if ($cnt[$i]) {print '+',$cnt[$i],$countkey[$i];}
}
print ' (',$cnt[$CNT_COUNT_HEADER],'/',$cnt[$CNT_COUNT_FLOAT],
'/',$cnt[$CNT_COUNT_INLINEMATH],'/',$cnt[$CNT_COUNT_DISPLAYMATH],')';
if ($htmlstyle && $tag2) {
print '',$tag1,'><',$tag2,'>';
$tag1=$tag2;
} else {print ' ';}
print text_to_print($header);
if ($htmlstyle && $tag1) {print '',$tag1,'>';}
if ($finalLineBreak) {print "\n";}
}
# Print detailed summary of count object
sub _print_count_details {
my ($count,$header)=__count_and_header(@_);
if ($htmlstyle) {print "';}
formatprint('Format/colour codes of verbose output:','h2');
print "\n\n";
foreach my $style (@STYLE_LIST) {
my $desc=$STYLE_DESC{$style};
if ($desc=~/^(.*):\s+(.*)$/) {
_help_style_line($1,$style,$2); # $1~${^PREMATCH}, $2~${^POSTMATCH}
} else {
_help_style_line($desc,$style);
}
}
if ($htmlstyle) {print '
';}
print "\n\n";
}
# Print one line of help
sub _help_style_line {
my ($text,$style,$comment)=@_;
if (!defined $comment) {$comment='';}
if ($htmlstyle) {$comment=' .... '.text_to_print($comment);}
else {$comment=' .... '.$comment;}
if (print_style($text,$style)) {
print $comment;
linebreak();
}
}
###### Help routines
# Print TeXcount version
sub print_version {
wprintstringdata('Version');
}
# Print TeXcount licence text
sub print_license {
wprintstringdata('License');
}
# Print short TeXcount help
sub print_help {
wprintstringdata('ShortHelp');
}
# Print main TeXcount help
sub print_help_man {
wprintstringdata('HelpTitle');
wprintstringdata('HelpText');
wprintstringdata('Reference');
}
# Print help on TC instructions
sub print_help_tcinst {
wprintstringdata('TCinstructions');
}
# Print TeXcount options list
sub print_help_options {
wprintstringdata('OptionsHead');
wprintstringdata('Options',StringDatum('OptionsFormat'));
}
# Print TeXcount options containing substring
sub print_help_options_subset {
my $pattern=shift @_;
my $data=StringData('Options');
if (!defined $data) {
error($Main,'No StringData Options.','BUG');
return;
}
my @options;
foreach (@$data) {
if (/^\s*([^\s]+\s)*[^\s]*\Q$pattern\E/) {push @options,$_;}
}
if (scalar(@options)==0) {print "No options contained $pattern.\n";}
else {
print "Options containing \"$pattern\":\n\n";
wprintlines(StringDatum('OptionsFormat'),@options);
}
}
# Print help on specific macro or environment
sub print_help_on_rule {
my $arg=shift @_;
my $def;
my %rules=(
'\documentclass' => 'Initiates LaTeX document preamble.',
'\begin' => 'Treatmend depends on environment handling rules.',
'\def' => 'Excluded from count.',
'\verb' => 'Strong exclude for enclosed region.',
'$' => 'Opens or closes inlined equation',
'$$' => 'Opens or closes displayed equation.',
'\(' => 'Opens inlined equation.',
'\)' => 'Closes inlined equation initiated by \(.',
'\[' => 'Opens displayed equation.',
'\]' => 'Closes displayed equation initiated by \[.');
if (!defined $arg || $arg=~/^\s*$/) {
print "\nSpecify macro or environment name after the -h= option.\n";
return;
}
if ($arg=~/^[\w\-\%]+:/) {
remove_all_rules();
%rules=();
while ($arg=~s/^([\w\-\%]+)://) {include_package($1);}
}
if ($def=$rules{$arg}) {
print "\nSpecial rule (hard coded) for $arg\n";
print $def."\n";
} elsif ($arg=~/^\\/) {
my $hasrule=0;
print "\nRule(s) for macro $arg\n";
if ($def=$TeXmacrocount{$arg}) {
$hasrule=1;
}
if ($def=$TeXfileinclude{$arg}) {
$hasrule=1;
print "Takes file name as parameter which is included in document.\n";
}
if ($def=$TeXmacro{$arg}) {
$hasrule=1;
_print_rule_macro($arg,$def);
}
if ($def=$TeXfloatinc{$arg}) {
$hasrule=1;
print "\nIncluded inside floats:\n";
_print_rule_macro($arg,$def);
}
if (!$hasrule) {
print "\nNo macro rule defined for $arg.\nParameters treated as surrounding text.\n";
}
} else {
if ($def=$TeXenvir{$arg}) {
print "\nRule for environment $arg\n";
_print_rule_macrocount($PREFIX_ENVIR.$arg);
_print_rule_envir($arg,$def);
} else {
print "\nNo default environment rule defined for $arg.\nContent handled as surrounding text.\n";
}
}
}
# Print macro handling rule
sub _print_rule_macro {
my ($arg,$def)=@_;
if (!defined $def) {
print "Takes no parameter(s).\n";
} elsif (ref($def) eq 'ARRAY') {
my $optionflag=0;
print "Takes has the following parameters and parameter rules:\n";
foreach my $state (@{$def}) {
if ($state==$_STATE_OPTION) {$optionflag=1;}
elsif ($state==$_STATE_NOOPTION) {print " - no [] options permitted here\n";}
elsif ($state==$_STATE_AUTOOPTION) {}
elsif ($optionflag) {
$optionflag=0;
print " + optional [] containing $state2desc{$state}\n";
} else {
print " + $state2desc{$state}\n";
}
}
} else {
print "Takes $def parameter(s): content ignored, i.e. not included in counts.\n";
}
}
# Print environment handling rule
sub _print_rule_envir {
my ($arg,$def)=@_;
print "Contents parsed as $state2desc{$def}\n";
if ($def=$TeXmacro{$PREFIX_ENVIR.$arg}) {
_print_rule_macro($arg,$def);
} else {
print "Takes no parameter(s).\n";
}
}
# Print macrocount rule, return rule
sub _print_rule_macrocount {
my $arg=shift @_;
my $def=$TeXmacrocount{$arg};
if (!defined $def) {return undef;}
if (ref($def) eq 'ARRAY') {
my @wd=@$def;
foreach (@wd) {$_=$countdesc[$_];}
print 'Increments the following counters: ',join('; ',@wd),".\n";
} else {
print "Counted as $def word(s).\n";
}
}
# Print style or style category summary
sub print_help_on_styles {
my $style=shift @_;
if (defined $style) {
if (my $def=$STYLES{$style}) {
_print_help_on_style_category($style);
print wrap('',' ',"$style = ".join(', ',grep(/^\w+$/,sort keys %$def))),".\n";
} elsif ($def=$STYLE_DESC{$style}) {
print $style,' = ',$def,"\n";
} else {
print "Unknown style or style category: $style.\n";
}
} else {
print wrap('',' ','Styles: '.join(', ',@STYLE_LIST)),".\n\n";
print wrap('',' ','Style categories: '.join(', ',sort grep(/^\w+$/,keys %STYLES))),".\n\n";
print "Use -help-style={style} to get help on particular style or style category.\n";
}
}
# Print help on a particular style category (optional prefix and indentation)
sub _print_help_on_style_category {
my ($cat,$prefix,$indent)=@_;
if (!defined $prefix) {$prefix='';}
if (!defined $indent) {$indent=' ';}
}
###### HTML routines
# Print HTML header
sub html_head {
if (defined $HTMLfile) {
if (open(FH,$HTMLfile)) {
my $text=join('',