File: manconv.sh

package info (click to toggle)
luatex 0.70.1.20120524-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 242,132 kB
  • sloc: ansic: 890,140; cpp: 469,298; perl: 73,299; sh: 46,668; makefile: 16,604; python: 8,427; lisp: 6,684; xml: 3,926; lex: 3,784; java: 3,569; pascal: 3,569; yacc: 2,461; exp: 2,031; ruby: 1,375; objc: 1,362; tcl: 631; sed: 522; asm: 435; csh: 46; awk: 30
file content (58 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#
###############################################################################
#
# Wrapper for GNU groff to convert man pages to a few formats
#
# Usage: manconv.sh FORMAT [PAPER_SIZE] < in.1 > out.suffix
#
# FORMAT can be ascii, utf8, ps, or pdf. PAPER_SIZE can be anything that
# groff accepts, e.g. a4 or letter. See groff_font(5). PAPER_SIZE defaults
# to a4 and is used only when FORMAT is ps (PostScript) or pdf.
#
# Multiple man pages can be given at once e.g. to create a single PDF file
# with continuous page numbering.
#
###############################################################################
#
# Author: Lasse Collin
#
# This file has been put into the public domain.
# You can do whatever you want with this file.
#
###############################################################################

FORMAT=$1
PAPER=${2-a4}

# Make PostScript and PDF output more readable:
#   - Use 11 pt font instead of the default 10 pt.
#   - Use larger paragraph spacing than the default 0.4v (man(7) only).
FONT=11
PD=0.8

SED_PD="
/^\\.TH /s/\$/\\
.PD $PD/
s/^\\.PD\$/.PD $PD/"

case $FORMAT in
	ascii)
		groff -t -mandoc -Tascii | col -bx
		;;
	utf8)
		groff -t -mandoc -Tutf8 | col -bx
		;;
	ps)
		sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \
				-rC1 -rS$FONT -Tps -P-p$PAPER
		;;
	pdf)
		sed "$SED_PD" | groff -dpaper=$PAPER -t -mandoc \
				-rC1 -rS$FONT -Tps -P-p$PAPER | ps2pdf - -
		;;
	*)
		echo 'Invalid arguments' >&2
		exit 1
		;;
esac