这是一个AWK脚本,它包装长行并重新包装其余部分和短行:
awk -v WIDTH=72 '
{
gsub("\t"," ")
$0 = line $0
while (length <= WIDTH) {
line = $0
more = getline
gsub("\t"," ")
if (more)
$0 = line " " $0
else
$0 = line
break
}
while (length >= WIDTH) {
print substr($0,1,WIDTH)
$0 = substr($0,WIDTH+1)
}
line = $0 " "
}
END {
print
}
'
CPAN上有一个Perl脚本,可以很好地重新格式化文本。它称为paradj(单个文件)。为了进行断字,您还需要TeX::Hyphen
。
SWITCHES
--------
The available switches are:
--width=n (or -w=n or -w n)
Line width is n chars long
--left (or -l)
Output is left-justified (default)
--right (or -r)
Output is right-justified
--centered (or -c)
Output is centered
--both (or -b)
Output is both left- and right-justified
--indent=n (or -i=n or -i n)
Leave n spaces for initial indention (defaults to 0)
--newline (or -n)
Insert blank lines between paragraphs
--hyphenate (or -h)
Hyphenate word that doesn't fit on a line
这是我为支持左边距选项所做的一些更改的区别:
12c12
< my ($indent, $newline);
---
> my ($indent, $margin, $newline);
15a16
> "margin:i" => \$margin,
21a23
> $margin = 0 if (!$margin);
149a152
> print " " x $margin;
187a191,193
> print "--margin=n (or -m=n or -m n) Add a left margin of n ";
> print "spaces\n";
> print " (defaults to 0)\n";