Last active
August 9, 2017 06:26
-
-
Save mjpost/5453894 to your computer and use it in GitHub Desktop.
I used this for turning a sorted list of reviewers for the NAACL 2013 proceedings into 3 columns of sorted reviewers spanning multiple pages. Two arguments control (a) the number of rows on the first page and (b) the number of rows on subsequent pages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Matt Post <[email protected]> | |
# April 2013 | |
# This script turns a single column of sorted text into LaTeX-formatted multiple columns spanning | |
# multiple PDF pages. | |
# Its input is a single column of text on STDIN (each line is a complete entry). Two optional | |
# arguments specify (a) the number of rows on the first page and (b) the number of rows on the | |
# remaining pages, with both defaulting to 45. The last page will be adjusted automatically. | |
use strict; | |
use warnings; | |
use List::Util qw/min/; | |
use POSIX qw/ceil/; | |
my $lines_first_page = shift || 45; | |
my $lines_other_pages = shift || 45; | |
my $num_cols = 3; | |
chomp(my @names = <>); | |
print_formatted_page($num_cols, $lines_first_page, \@names); | |
print_formatted_page($num_cols, $lines_other_pages, \@names) while scalar(@names); | |
sub print_formatted_page { | |
my ($num_cols, $num_rows, $namelistref) = @_; | |
my $names_per_column = ceil(min($num_cols * $num_rows, scalar(@$namelistref)) / $num_cols); | |
print STDERR "Formatting page with maximum $num_rows rows, $names_per_column actual\n"; | |
my $colspec = "l" x $num_cols; | |
# print "\\begin{tabular}{$col_spec}\n"; | |
print "\\begin{tabular*}{0.9\\textwidth}{\@{\\extracolsep{\\fill}} $colspec }\n"; | |
my @cols; | |
foreach my $colno (0..$num_cols-1) { | |
@{$cols[$colno]} = splice(@$namelistref, 0, $names_per_column); | |
} | |
for my $row (0..$names_per_column-1) { | |
print " $cols[0][$row]"; | |
map { print " & $cols[$_][$row]" } (1..$num_cols-1); | |
print " \\\\\n"; | |
} | |
print "\\end{tabular*}\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment