The R Project SVN R

Rev

Rev 52398 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 52398 Rev 52403
Line 1... Line 1...
1
## Rd2dvi -- Convert man pages (*.Rd help files) via LaTeX to DVI/PDF.
1
## Rd2dvi -*- sh -*-  Convert man pages (*.Rd help files) via LaTeX to DVI/PDF.
2
##
-
 
3
## Examples:
-
 
4
##  R CMD Rd2dvi /path/to/Rsrc/src/library/base/man/Normal.Rd
-
 
5
##  R CMD Rd2dvi `grep -l "\\keyword{distr" \
-
 
6
##                  /path/to/Rsrc/src/library/stats/man/*.Rd | sort | uniq`
-
 
7
 
-
 
8
revision='$Rev: 52398 $'
-
 
9
version=`set - ${revision}; echo ${2}`
-
 
10
version="Rd2dvi: ${R_VERSION} (r${version})
-
 
11
 
-
 
12
Copyright (C) 2000-2010 The R Core Development Team.
-
 
13
This is free software; see the GNU General Public License version 2
-
 
14
or later for copying conditions.  There is NO warranty."
-
 
15
 
-
 
16
usage="Usage: R CMD Rd2dvi [options] files
-
 
17
 
-
 
18
Generate DVI (or PDF) output from the Rd sources specified by files, by
-
 
19
either giving the paths to the files, or the path to a directory with
-
 
20
the sources of a package, or an installed package.
-
 
21
 
-
 
22
Unless specified via option '--output', the basename of the output file
-
 
23
equals the basename of argument 'files' if this specifies a package
-
 
24
or a single file, and 'Rd2' otherwise.
-
 
25
 
-
 
26
The Rd sources are assumed to be ASCII unless they contain \encoding
-
 
27
declarations (which take priority) or --encoding is supplied or if using
-
 
28
package sources, if the package DESCRIPTION file has an Encoding field.
-
 
29
The output encoding defaults to the package encoding then to 'UTF-8'.
-
 
30
 
-
 
31
Options:
-
 
32
  -h, --help		print short help message and exit
-
 
33
  -v, --version		print version info and exit
-
 
34
      --batch		no interaction
-
 
35
      --debug		turn on shell debugging (set -x)
-
 
36
      --no-clean	do not remove created temporary files
-
 
37
      --no-preview	do not preview generated DVI/PDF file
-
 
38
      --encoding=enc    use 'enc' as the default input encoding
-
 
39
      --outputEncoding=outenc use 'outenc' as the default output encoding
-
 
40
      --os=NAME		use OS subdir 'NAME' (unix or windows)
-
 
41
      --OS=NAME		the same as '--os'
-
 
42
  -o, --output=FILE	write output to FILE
-
 
43
      --pdf		generate PDF output
-
 
44
      --title=NAME	use NAME as the title of the document
-
 
45
      --no-index	don't index output
-
 
46
      --no-description	don't typeset the description of a package
-
 
47
      --internals	typeset 'internal' documentation (usually skipped)
-
 
48
 
-
 
49
The output papersize is set by the environment variable R_PAPERSIZE.
-
 
50
The DVI previewer is set by the environment variable xdvi.
-
 
51
The PDF previewer is set by the environment variable R_PDFVIEWER.
-
 
52
 
-
 
53
Report bugs to <r-bugs@r-project.org>."
-
 
54
 
-
 
55
## workaround the export of CDPATH, which may cause 'cd ${build_dir}' to echo
-
 
56
unset CDPATH
-
 
57
 
-
 
58
start_dir=`pwd`
-
 
59
build_dir=".Rd2dvi${$}"
-
 
60
 
-
 
61
title=""
-
 
62
batch=false
-
 
63
clean=true
-
 
64
debug=false
-
 
65
only_meta=false
-
 
66
out_ext="dvi"
-
 
67
output=""
-
 
68
enc=unknown
-
 
69
outenc=latin1
-
 
70
index=true
-
 
71
description=true
-
 
72
internals=no
-
 
73
 
-
 
74
if test "${R_OSTYPE}" = "windows"; then
-
 
75
  echo=echo
-
 
76
  preview=${xdvi-open}
-
 
77
  OSdir=windows
-
 
78
else
-
 
79
  ## Need a `safe' echo which does not interpret backslash-escaped
-
 
80
  ## characters in SysV style.
-
 
81
  ## FIXME: R_SHARE_DIR might contain a space.
-
 
82
  echo="sh ${R_SHARE_DIR}/sh/echo.sh"
-
 
83
  preview=${xdvi-xdvi}
-
 
84
  OSdir=unix
-
 
85
fi
-
 
86
 
2
 
-
 
3
args=
87
while test -n "${1}"; do
4
while test -n "${1}"; do
88
  case ${1} in
-
 
89
    -h|--help)
-
 
90
      ${echo} "${usage}"; exit 0 ;;
-
 
91
    -v|--version)
-
 
92
      ${echo} "${version}"; exit 0 ;;
5
  ## quote each argument here, unquote in R code.
93
    --batch)
-
 
94
      batch=true ;;
-
 
95
    --debug)
-
 
96
      debug=true ;;
-
 
97
    --no-clean)
-
 
98
      clean=false ;;
-
 
99
    --no-preview)
-
 
100
      preview=false ;;
-
 
101
    --pdf)
-
 
102
      out_ext="pdf";
-
 
103
      ## allow for --no-preview --pdf
-
 
104
      if test "${preview}" != "false"; then
-
 
105
	if test -n "${R_PDFVIEWER}"; then
-
 
106
	    preview=${R_PDFVIEWER}
-
 
107
	elif test "${R_OSTYPE}" = "windows"; then
-
 
108
	    preview=open
-
 
109
	else
-
 
110
	    preview=false
-
 
111
	fi
-
 
112
      fi
-
 
113
      export R_RD4DVI=${R_RD4PDF-"times,hyper"}
-
 
114
      ;;
-
 
115
    --title=*)
-
 
116
      title=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
117
    -o)
-
 
118
      if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
-
 
119
	output="${2}"; shift
-
 
120
      else
-
 
121
	echo "ERROR: option '${1}' requires an argument"
-
 
122
	exit 1
-
 
123
      fi
-
 
124
      ;;
-
 
125
    --only-meta)
-
 
126
      only_meta=true ;;
-
 
127
    --output=*)
-
 
128
      output=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
129
    --OS=*|--os=*)
-
 
130
      OSdir=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
131
    --encoding=*)
-
 
132
      enc=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
133
    --outputEncoding=*)
-
 
134
      outenc=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
135
    --build-dir=*)
-
 
136
      build_dir=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-
 
137
    --no-index)
-
 
138
      index=false ;;
-
 
139
    --no-description)
-
 
140
      description=false ;;
6
  args="${args}nextArg${1}"
141
    --internals)
-
 
142
      internals="yes" ;;
-
 
143
    --|*)
-
 
144
      break ;;
-
 
145
  esac
-
 
146
  shift
7
  shift
147
done
8
done
148
 
9
 
149
if ${debug}; then set -x; fi
-
 
150
 
-
 
151
do_cleanup () {
-
 
152
  if ${clean}; then
-
 
153
    cd "${start_dir}"
-
 
154
    rm -rf "${build_dir}"
-
 
155
  else
-
 
156
    echo "You may want to clean up by 'rm -rf ${build_dir}'"
-
 
157
  fi
-
 
158
}
-
 
159
 
-
 
160
if test -d "${1}"; then
-
 
161
  if test -f ${1}/DESCRIPTION; then
-
 
162
    echo "Hmm ... looks like a package"
-
 
163
    dir=${1}
-
 
164
    test -z "${output}" && output="`basename ${1}`.${out_ext}"
-
 
165
  elif test -f ${1}/DESCRIPTION.in && \
-
 
166
       test -n "`grep '^Priority: *base' ${1}/DESCRIPTION.in`"; then
-
 
167
    echo "Hmm ... looks like a package from the R distribution"
-
 
168
    dir=${1}
-
 
169
    test -z "${output}" && output="`basename ${1}`.${out_ext}"
-
 
170
    if ${index}; then
-
 
171
      this=`basename ${1}`
-
 
172
      if test ${this} = "base"; then
-
 
173
        index=false
-
 
174
        echo "_not_ indexing 'base' package"
-
 
175
      fi
-
 
176
    fi
-
 
177
  else
-
 
178
    if test -d ${1}/man; then
-
 
179
      dir=${1}/man
-
 
180
    else
-
 
181
      dir=${1}
-
 
182
    fi
-
 
183
  fi
-
 
184
else
-
 
185
  if test ${#} -eq 1 ; then
-
 
186
    if test -z "${output}"; then
-
 
187
      output=`basename "${1}"`
-
 
188
      output="`echo ${output} | ${SED} 's/[Rr]d$//'`${out_ext}"
-
 
189
    fi
-
 
190
  fi
-
 
191
fi
-
 
192
 
-
 
193
## Prepare for building the documentation.
-
 
194
if test -z "${output}"; then
-
 
195
  output="Rd2.${out_ext}"
-
 
196
fi
-
 
197
if test -f ${output}; then
-
 
198
  echo "file '${output}' exists; please remove first"
-
 
199
  exit 1
-
 
200
fi
-
 
201
if test -d "${build_dir}"; then
-
 
202
  rm -rf "${build_dir}" || echo "cannot write to build dir" && exit 2
-
 
203
fi
-
 
204
mkdir "${build_dir}"
-
 
205
 
-
 
206
echo "tools:::.Rd2dvi(\"${1}\",  \"${build_dir}/Rd2.tex\", \
10
echo 'tools:::..Rd2dvi()' \
207
\"$title\", \"$batch\", \"$description\", \"$only_meta\",\
-
 
208
\"$enc\", \"$outenc\", \"${dir-$@}\", \"$OSdir\", \"$internals\", \"$index\")" \
-
 
209
  | LC_ALL=C ${R_HOME}/bin/R --slave --vanilla || exit 11
11
| R_DEFAULT_PACKAGES= LC_ALL=C "${R_HOME}/bin/R" \
210
 
-
 
211
echo "Creating ${out_ext} output from LaTeX ..."
-
 
212
cd "${build_dir}"
-
 
213
 
-
 
214
status=0
-
 
215
echo "tools::texi2dvi('Rd2.tex', pdf=(\"${out_ext}\" == \"pdf\"), \
-
 
216
    quiet=FALSE, index=(\"${index}\" != \"false\"))" | \
-
 
217
   LC_ALL=C ${R_HOME}/bin/R --slave --vanilla || status=1
-
 
218
if test $status -gt 0; then
12
--vanilla --slave --args ${args}
219
  echo "Error in running tools::texi2dvi"
-
 
220
  do_cleanup
-
 
221
  exit 1
-
 
222
fi
-
 
223
 
-
 
224
cd "${start_dir}"
-
 
225
echo "Saving output to '${output}' ..."
-
 
226
cp "${build_dir}/Rd2.${out_ext}" ${output}
-
 
227
echo "Done"
-
 
228
 
-
 
229
do_cleanup
-
 
230
${preview} ${output}
-
 
231
exit 0
-
 
232
 
-
 
233
### Local Variables: ***
-
 
234
### mode: sh ***
-
 
235
### sh-indentation: 2 ***
-
 
236
### End: ***
-