The R Project SVN R

Rev

Rev 34808 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34808 Rev 34818
1
#! /bin/sh
1
#! /bin/sh
2
 
2
 
3
## Rd2dvi -- Convert man pages (*.Rd help files) via LaTeX to DVI/PDF.
3
## Rd2dvi -- Convert man pages (*.Rd help files) via LaTeX to DVI/PDF.
4
##
4
##
5
## Examples:
5
## Examples:
6
##  R CMD Rd2dvi /path/to/Rsrc/src/library/base/man/Normal.Rd
6
##  R CMD Rd2dvi /path/to/Rsrc/src/library/base/man/Normal.Rd
7
##  R CMD Rd2dvi `grep -l "\\keyword{distr" \
7
##  R CMD Rd2dvi `grep -l "\\keyword{distr" \
8
##                  /path/to/Rsrc/src/library/base/man/*.Rd | sort | uniq`
8
##                  /path/to/Rsrc/src/library/stats/man/*.Rd | sort | uniq`
9
 
9
 
10
revision='$Revision: 1.40 $'
10
revision='$Revision: 1.41 $'
11
version=`set - ${revision}; echo ${2}`
11
version=`set - ${revision}; echo ${2}`
12
version="Rd2dvi ${version}
12
version="Rd2dvi ${version}
13
 
13
 
14
Copyright (C) 2000-2001 The R Core Development Team.
14
Copyright (C) 2000-2005 The R Core Development Team.
15
This is free software; see the GNU General Public Licence version 2
15
This is free software; see the GNU General Public Licence version 2
16
or later for copying conditions.  There is NO warranty." 
16
or later for copying conditions.  There is NO warranty." 
17
 
17
 
18
usage="Usage: R CMD Rd2dvi [options] files
18
usage="Usage: R CMD Rd2dvi [options] files
19
 
19
 
20
Generate DVI (or PDF) output from the Rd sources specified by files, by
20
Generate DVI (or PDF) output from the Rd sources specified by files, by
21
either giving the paths to the files, or the path to a directory with
21
either giving the paths to the files, or the path to a directory with
22
the sources of a package.
22
the sources of a package.
23
 
23
 
24
Unless specified via option '--output', the basename of the output file
24
Unless specified via option '--output', the basename of the output file
25
equals the basename of argument 'files' if this specifies a package
25
equals the basename of argument 'files' if this specifies a package
26
(bundle) or a single file, and 'Rd2' otherwise.
26
(bundle) or a single file, and 'Rd2' otherwise.
27
 
27
 
28
Options:
28
Options:
29
  -h, --help		print short help message and exit
29
  -h, --help		print short help message and exit
30
  -v, --version		print Rd2dvi version info and exit
30
  -v, --version		print Rd2dvi version info and exit
31
      --batch		no interaction
31
      --batch		no interaction
32
      --debug		turn on shell debugging (set -x)
32
      --debug		turn on shell debugging (set -x)
33
      --no-clean	do not remove created temporary files
33
      --no-clean	do not remove created temporary files
34
      --no-preview	do not preview generated output file
34
      --no-preview	do not preview generated output file
35
      --os=NAME		use OS subdir 'NAME' (unix or windows)
35
      --os=NAME		use OS subdir 'NAME' (unix or windows)
36
      --OS=NAME		the same as '--os'
36
      --OS=NAME		the same as '--os'
37
  -o, --output=FILE	write output to FILE
37
  -o, --output=FILE	write output to FILE
38
      --pdf		generate PDF output
38
      --pdf		generate PDF output
39
      --title=NAME	use NAME as the title of the document
39
      --title=NAME	use NAME as the title of the document
40
  -V, --verbose		report on what is done
40
  -V, --verbose		report on what is done
41
 
41
 
42
Report bugs to <r-bugs@r-project.org>."
42
Report bugs to <r-bugs@r-project.org>."
43
 
43
 
44
start_dir=`pwd`
44
start_dir=`pwd`
45
 
45
 
46
batch=false
46
batch=false
47
clean=true
47
clean=true
48
debug=false
48
debug=false
49
out_ext="dvi"
49
out_ext="dvi"
50
output=""
50
output=""
51
preview=xdvi
51
preview=xdvi
52
verbose=false
52
verbose=false
53
OSdir=${R_OSTYPE-"unix"}
53
OSdir=${R_OSTYPE-"unix"}
54
 
54
 
55
: ${R_SHARE_DIR}=${R_HOME}/share
55
: ${R_SHARE_DIR}=${R_HOME}/share
56
## Need a `safe' echo which does not interpret backslash-escaped
56
## Need a `safe' echo which does not interpret backslash-escaped
57
## characters in SysV style.
57
## characters in SysV style.
58
echo="sh ${R_SHARE_DIR}/sh/echo.sh"
58
echo="sh ${R_SHARE_DIR}/sh/echo.sh"
59
 
59
 
60
while test -n "${1}"; do
60
while test -n "${1}"; do
61
  case ${1} in
61
  case ${1} in
62
    -h|--help)
62
    -h|--help)
63
      ${echo} "${usage}"; exit 0 ;;
63
      ${echo} "${usage}"; exit 0 ;;
64
    -v|--version)
64
    -v|--version)
65
      ${echo} "${version}"; exit 0 ;;
65
      ${echo} "${version}"; exit 0 ;;
66
    --batch)
66
    --batch)
67
      batch=true ;;
67
      batch=true ;;
68
    --debug)
68
    --debug)
69
      debug=true ;;
69
      debug=true ;;
70
    --no-clean)
70
    --no-clean)
71
      clean=false ;;
71
      clean=false ;;
72
    --no-preview)
72
    --no-preview)
73
      preview=false ;;
73
      preview=false ;;
74
    --pdf)
74
    --pdf)
75
      out_ext="pdf";
75
      out_ext="pdf";
76
      preview=false;
76
      preview=false;
77
      R_RD4DVI=${R_RD4PDF-"times,hyper"};
77
      R_RD4DVI=${R_RD4PDF-"times,hyper"};
78
      R_LATEXCMD=${PDFLATEX-pdflatex} ;;
78
      R_LATEXCMD=${PDFLATEX-pdflatex} ;;
79
    --title=*)
79
    --title=*)
80
      title=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
80
      title=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
81
    -o)
81
    -o)
82
      if test -n "`echo ${2} | sed 's/^-.*//'`"; then      
82
      if test -n "`echo ${2} | sed 's/^-.*//'`"; then      
83
	output="${2}"; shift
83
	output="${2}"; shift
84
      else
84
      else
85
	${echo} "ERROR: option '${1}' requires an argument"
85
	${echo} "ERROR: option '${1}' requires an argument"
86
	exit 1
86
	exit 1
87
      fi
87
      fi
88
      ;;
88
      ;;
89
    --output=*)
89
    --output=*)
90
      output=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
90
      output=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
91
    --OS=*|--os=*)
91
    --OS=*|--os=*)
92
      OSdir=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
92
      OSdir=`echo "${1}" | sed -e 's/[^=]*=//'` ;;
93
    -V|--verbose)
93
    -V|--verbose)
94
      verbose=${echo} ;;
94
      verbose=${echo} ;;
95
    --|*)
95
    --|*)
96
      break ;;
96
      break ;;
97
  esac
97
  esac
98
  shift
98
  shift
99
done
99
done
100
 
100
 
101
if ${debug}; then set -x; fi
101
if ${debug}; then set -x; fi
102
 
102
 
103
. ${R_SHARE_DIR}/sh/dcf.sh	# get_dcf_field()
103
. ${R_SHARE_DIR}/sh/dcf.sh	# get_dcf_field()
104
 
104
 
105
Rdconv_dir_or_files_to_LaTeX () {
105
Rdconv_dir_or_files_to_LaTeX () {
106
  ## Convert Rd files in a dir or a list of Rd files to LaTeX, appending
106
  ## Convert Rd files in a dir or a list of Rd files to LaTeX, appending
107
  ## the result to OUTFILE.
107
  ## the result to OUTFILE.
108
  ## Usage:
108
  ## Usage:
109
  ##   Rdconv_dir_or_files_to_LaTeX OUTFILE DIR
109
  ##   Rdconv_dir_or_files_to_LaTeX OUTFILE DIR
110
  ##   Rdconv_dir_or_files_to_LaTeX OUTFILE FILES
110
  ##   Rdconv_dir_or_files_to_LaTeX OUTFILE FILES
111
 
111
 
112
  ${verbose} $@
112
  ${verbose} $@
113
 
113
 
114
  out="${1}"
114
  out="${1}"
115
  shift
115
  shift
116
 
116
 
117
  if test -d ${1}; then
117
  if test -d ${1}; then
118
    files=`ls ${1}/*.[Rr]d`
118
    files=`ls ${1}/*.[Rr]d`
119
    if test -d ${1}/${OSdir}; then
119
    if test -d ${1}/${OSdir}; then
120
      files="${files} `ls ${1}/${OSdir}/*.[Rr]d`"
120
      files="${files} `ls ${1}/${OSdir}/*.[Rr]d`"
121
    fi
121
    fi
122
    files=`LC_ALL=C ${echo} ${files} | sort`
122
    files=`LC_ALL=C ${echo} ${files} | sort`
123
  else
123
  else
124
    files="${@}"
124
    files="${@}"
125
  fi
125
  fi
126
 
126
 
127
  echo "Converting Rd files to LaTeX ..."
127
  echo "Converting Rd files to LaTeX ..."
128
 
128
 
129
  for f in ${files}; do
129
  for f in ${files}; do
130
    ${echo} ${f}
130
    ${echo} ${f}
131
    ${R_CMD} Rdconv -t latex ${f} >> ${out}
131
    ${R_CMD} Rdconv -t latex ${f} >> ${out}
132
  done
132
  done
133
 
133
 
134
}
134
}
135
 
135
 
136
Rd_DESCRIPTION_to_LaTeX () {
136
Rd_DESCRIPTION_to_LaTeX () {
137
  ## Typeset the contents of a DESCRIPTION file in a LaTeX description
137
  ## Typeset the contents of a DESCRIPTION file in a LaTeX description
138
  ## list.
138
  ## list.
139
  ## Usage:
139
  ## Usage:
140
  ##   Rd_DESCRIPTION_to_LaTeX FILE
140
  ##   Rd_DESCRIPTION_to_LaTeX FILE
141
  
141
  
142
  fields=`sed '/^[ 	]/d; s/^\([^:]*\):.*$/\1/' $1`
142
  fields=`sed '/^[ 	]/d; s/^\([^:]*\):.*$/\1/' $1`
143
  ${echo} "\\begin{description}"
143
  ${echo} "\\begin{description}"
144
  ${echo} "\\raggedright{}"
144
  ${echo} "\\raggedright{}"
145
  for f in `${echo} "${fields}" | sed '/Package/d; /Bundle/d;'`; do
145
  for f in `${echo} "${fields}" | sed '/Package/d; /Bundle/d;'`; do
146
    text=`get_dcf_field ${f} ${1} | \
146
    text=`get_dcf_field ${f} ${1} | \
147
      tr '\n' ' ' | \
147
      tr '\n' ' ' | \
148
      sed "s/\"\([^\"]*\)\"/\\\`\\\`\\1''/g"`
148
      sed "s/\"\([^\"]*\)\"/\\\`\\\`\\1''/g"`
149
    ${echo} "\\item[${f}] \\AsIs{${text}}"
149
    ${echo} "\\item[${f}] \\AsIs{${text}}"
150
  done
150
  done
151
  ${echo} "\\end{description}"
151
  ${echo} "\\end{description}"
152
}
152
}
153
 
153
 
154
is_bundle=no
154
is_bundle=no
155
is_base_package=no
155
is_base_package=no
156
file_sed='s/[_$]/\\&/g'
156
file_sed='s/[_$]/\\&/g'
157
 
157
 
158
toc="\\Rdcontents{\\R{} topics documented:}"
158
toc="\\Rdcontents{\\R{} topics documented:}"
159
if test -d "${1}"; then
159
if test -d "${1}"; then
160
  if test -f ${1}/DESCRIPTION; then
160
  if test -f ${1}/DESCRIPTION; then
161
    if test -n "`grep '^Bundle:' ${1}/DESCRIPTION`"; then
161
    if test -n "`grep '^Bundle:' ${1}/DESCRIPTION`"; then
162
      echo "Hmm ... looks like a package bundle"
162
      echo "Hmm ... looks like a package bundle"
163
      is_bundle=yes
163
      is_bundle=yes
164
      bundle_name=`get_dcf_field Bundle "${1}/DESCRIPTION"`
164
      bundle_name=`get_dcf_field Bundle "${1}/DESCRIPTION"`
165
      bundle_pkgs=`get_dcf_field Contains "${1}/DESCRIPTION"`
165
      bundle_pkgs=`get_dcf_field Contains "${1}/DESCRIPTION"`
166
      title=${title-"Bundle \`${bundle_name}'"}
166
      title=${title-"Bundle \`${bundle_name}'"}
167
    else
167
    else
168
      echo "Hmm ... looks like a package"
168
      echo "Hmm ... looks like a package"
169
      package_name=`get_dcf_field Package "${1}/DESCRIPTION"`
169
      package_name=`get_dcf_field Package "${1}/DESCRIPTION"`
170
      title=${title-"Package \`${package_name}'"}
170
      title=${title-"Package \`${package_name}'"}
171
      dir=${1}/man
171
      dir=${1}/man
172
    fi
172
    fi
173
    test -z "${output}" && output="`basename ${1}`.${out_ext}"
173
    test -z "${output}" && output="`basename ${1}`.${out_ext}"
174
  elif test -f ${1}/DESCRIPTION.in && \
174
  elif test -f ${1}/DESCRIPTION.in && \
175
       test -n "`grep '^Priority: *base' ${1}/DESCRIPTION.in`"; then
175
       test -n "`grep '^Priority: *base' ${1}/DESCRIPTION.in`"; then
176
    is_base_package=yes
176
    is_base_package=yes
177
    echo "Hmm ... looks like a package from the R distribution"
177
    echo "Hmm ... looks like a package from the R distribution"
178
    package_name=`get_dcf_field Package "${1}/DESCRIPTION.in"`
178
    package_name=`get_dcf_field Package "${1}/DESCRIPTION.in"`
179
    title=${title-"Package \`${package_name}'"}
179
    title=${title-"Package \`${package_name}'"}
180
    dir=${1}/man
180
    dir=${1}/man
181
    test -z "${output}" && output="`basename ${1}`.${out_ext}"    
181
    test -z "${output}" && output="`basename ${1}`.${out_ext}"    
182
  else
182
  else
183
    if test -d ${1}/man; then
183
    if test -d ${1}/man; then
184
      dir=${1}/man
184
      dir=${1}/man
185
    else
185
    else
186
      dir=${1}
186
      dir=${1}
187
    fi
187
    fi
188
    subj0=`${echo} ${dir} | sed -e ${file_sed}`
188
    subj0=`${echo} ${dir} | sed -e ${file_sed}`
189
    subj="all in \\file{${subj0}}"
189
    subj="all in \\file{${subj0}}"
190
  fi
190
  fi
191
else
191
else
192
  if test ${#} -gt 1 ; then
192
  if test ${#} -gt 1 ; then
193
    subj=" etc.";
193
    subj=" etc.";
194
  else
194
  else
195
    subj=
195
    subj=
196
    toc=
196
    toc=
197
    if test -z "${output}"; then
197
    if test -z "${output}"; then
198
      output=`basename "${1}"`
198
      output=`basename "${1}"`
199
      output="`echo ${output} | sed 's/[Rr]d$//'`${out_ext}"
199
      output="`echo ${output} | sed 's/[Rr]d$//'`${out_ext}"
200
    fi
200
    fi
201
  fi
201
  fi
202
  subj0=`${echo} ${1} | sed -e ${file_sed}`
202
  subj0=`${echo} ${1} | sed -e ${file_sed}`
203
  subj="\\file{${subj0}}${subj}"
203
  subj="\\file{${subj0}}${subj}"
204
fi
204
fi
205
title=${title-"\\R{} documentation}} \\par\\bigskip{{\\Large of ${subj}"}
205
title=${title-"\\R{} documentation}} \\par\\bigskip{{\\Large of ${subj}"}
206
 
206
 
207
## Prepare for building the documentation.
207
## Prepare for building the documentation.
208
if test -z "${output}"; then
208
if test -z "${output}"; then
209
  output="Rd2.${out_ext}"
209
  output="Rd2.${out_ext}"
210
fi
210
fi
211
if test -f ${output}; then
211
if test -f ${output}; then
212
  ${echo} "file '${output}' exists; please remove first"
212
  ${echo} "file '${output}' exists; please remove first"
213
  exit 1
213
  exit 1
214
fi
214
fi
215
build_dir=.Rd2dvi${$}
215
build_dir=.Rd2dvi${$}
216
if test -d ${build_dir}; then
216
if test -d ${build_dir}; then
217
  rm -rf ${build_dir} || echo "cannot write to build dir" && exit 2
217
  rm -rf ${build_dir} || echo "cannot write to build dir" && exit 2
218
fi
218
fi
219
mkdir ${build_dir}
219
mkdir ${build_dir}
220
 
220
 
221
## Rd2.tex part 1: header
221
## Rd2.tex part 1: header
222
if test ${batch}; then
222
if test ${batch}; then
223
  cat > ${build_dir}/Rd2.tex <<EOF
223
  cat > ${build_dir}/Rd2.tex <<EOF
224
\\nonstopmode{}
224
\\nonstopmode{}
225
EOF
225
EOF
226
else
226
else
227
  cat > ${build_dir}/Rd2.tex <<EOF
227
  cat > ${build_dir}/Rd2.tex <<EOF
228
EOF
228
EOF
229
fi
229
fi
230
cat >> ${build_dir}/Rd2.tex <<EOF
230
cat >> ${build_dir}/Rd2.tex <<EOF
231
\\documentclass[${R_PAPERSIZE}paper]{book}
231
\\documentclass[${R_PAPERSIZE}paper]{book}
232
\\usepackage[${R_RD4DVI-ae}]{Rd}
232
\\usepackage[${R_RD4DVI-ae}]{Rd}
233
\\usepackage{makeidx}
233
\\usepackage{makeidx}
234
\\usepackage[latin1,latin2,latin9,utf8]{inputenc}
234
\\usepackage[@ENC@]{inputenc}
235
\\makeindex{}
235
\\makeindex{}
236
\\begin{document}
236
\\begin{document}
237
EOF
237
EOF
238
if test "${is_bundle}" = no; then
238
if test "${is_bundle}" = no; then
239
  cat >> ${build_dir}/Rd2.tex <<EOF
239
  cat >> ${build_dir}/Rd2.tex <<EOF
240
\\chapter*{}
240
\\chapter*{}
241
\\begin{center}
241
\\begin{center}
242
{\\textbf{\\huge ${title}}}
242
{\\textbf{\\huge ${title}}}
243
\\par\\bigskip{\\large \\today}
243
\\par\\bigskip{\\large \\today}
244
\\end{center}
244
\\end{center}
245
EOF
245
EOF
246
  if test -f ${1}/DESCRIPTION; then
246
  if test -f ${1}/DESCRIPTION; then
247
    Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.tex
247
    Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.tex
248
  fi
248
  fi
249
  if test "${is_base_package}" = yes; then
249
  if test "${is_base_package}" = yes; then
250
    R_version=unknown
250
    R_version=unknown
251
    if test -f ${1}/../../../VERSION; then
251
    if test -f ${1}/../../../VERSION; then
252
      R_version=`cat ${1}/../../../VERSION`
252
      R_version=`cat ${1}/../../../VERSION`
253
    fi
253
    fi
254
    Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION.in | \
254
    Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION.in | \
255
      sed "s/@VERSION@/${R_version}/" >> ${build_dir}/Rd2.tex
255
      sed "s/@VERSION@/${R_version}/" >> ${build_dir}/Rd2.tex
256
  fi
256
  fi
257
else
257
else
258
  cat >> ${build_dir}/Rd2.tex <<EOF
258
  cat >> ${build_dir}/Rd2.tex <<EOF
259
\\pagenumbering{Roman}
259
\\pagenumbering{Roman}
260
\\begin{titlepage}
260
\\begin{titlepage}
261
\\strut\\vfill
261
\\strut\\vfill
262
\\begin{center}
262
\\begin{center}
263
{\\textbf{\\Huge ${title}}}
263
{\\textbf{\\Huge ${title}}}
264
\\par\\bigskip{\\large \\today}
264
\\par\\bigskip{\\large \\today}
265
\\end{center}
265
\\end{center}
266
\\par\\bigskip
266
\\par\\bigskip
267
EOF
267
EOF
268
  Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.tex
268
  Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.tex
269
  cat >> ${build_dir}/Rd2.tex <<EOF
269
  cat >> ${build_dir}/Rd2.tex <<EOF
270
\\vfill\\vfill
270
\\vfill\\vfill
271
\\end{titlepage}
271
\\end{titlepage}
272
EOF
272
EOF
273
fi
273
fi
274
  
274
  
275
## Rd2.tex part 2: body
275
## Rd2.tex part 2: body
276
if test "${is_bundle}" = no; then
276
if test "${is_bundle}" = no; then
277
  ${echo} ${toc} >> ${build_dir}/Rd2.tex
277
  ${echo} ${toc} >> ${build_dir}/Rd2.tex
278
  Rdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${dir-${@}}
278
  Rdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${dir-${@}}
279
else
279
else
280
  cat >> ${build_dir}/Rd2.tex <<EOF
280
  cat >> ${build_dir}/Rd2.tex <<EOF
281
\\setcounter{secnumdepth}{-1}
281
\\setcounter{secnumdepth}{-1}
282
\\pagenumbering{roman}
282
\\pagenumbering{roman}
283
\\tableofcontents{}
283
\\tableofcontents{}
284
\\cleardoublepage{}
284
\\cleardoublepage{}
285
\\pagenumbering{arabic}
285
\\pagenumbering{arabic}
286
EOF
286
EOF
287
  for p in ${bundle_pkgs}; do
287
  for p in ${bundle_pkgs}; do
288
    ${echo} "Bundle package: '${p}'"
288
    ${echo} "Bundle package: '${p}'"
289
    ${echo} "\\chapter{Package \`${p}'}" >> ${build_dir}/Rd2.tex
289
    ${echo} "\\chapter{Package \`${p}'}" >> ${build_dir}/Rd2.tex
290
    if test -f ${1}/${p}/DESCRIPTION.in; then
290
    if test -f ${1}/${p}/DESCRIPTION.in; then
291
      Rd_DESCRIPTION_to_LaTeX ${1}/${p}/DESCRIPTION.in \
291
      Rd_DESCRIPTION_to_LaTeX ${1}/${p}/DESCRIPTION.in \
292
        >> ${build_dir}/Rd2.tex
292
        >> ${build_dir}/Rd2.tex
293
    fi
293
    fi
294
    Rdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${1}/${p}/man
294
    Rdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${1}/${p}/man
295
    ${echo} "\\clearpage{}" >> ${build_dir}/Rd2.tex
295
    ${echo} "\\clearpage{}" >> ${build_dir}/Rd2.tex
296
  done
296
  done
297
  ${echo} "\\cleardoublepage{}" >> ${build_dir}/Rd2.tex
297
  ${echo} "\\cleardoublepage{}" >> ${build_dir}/Rd2.tex
298
fi
298
fi
299
 
299
 
300
## Rd2.tex part 3: footer
300
## Rd2.tex part 3: footer
301
cat >> ${build_dir}/Rd2.tex <<EOF
301
cat >> ${build_dir}/Rd2.tex <<EOF
302
\\printindex{}
302
\\printindex{}
303
\\end{document}
303
\\end{document}
304
EOF
304
EOF
305
 
305
 
-
 
306
## Look for encodings
-
 
307
ENCS=`grep '^\\\\inputencoding' ${build_dir}/Rd2.tex | uniq |\
-
 
308
  sed -e 's/^\\\\inputencoding{\(.*\)}/\1/'`
-
 
309
ENCS=`grep '^\\\\\inputencoding' ${build_dir}/Rd2.tex |  uniq | \
-
 
310
  sed -e 's/^\\\\inputencoding{\(.*\)}/\1/' | \
-
 
311
  tr '\na-z0-9' ',a-z0-9' | sed -e s/,$//`
-
 
312
echo "ENCS is ${ENCS}"
-
 
313
 
-
 
314
## substitute for the encodings used
-
 
315
mv ${build_dir}/Rd2.tex ${build_dir}/Rd2.tex.pre
-
 
316
if test -z "${ENCS}"; then
-
 
317
  sed -e '/^\\usepackage\[@ENC@\]{inputenc}$/d' \
-
 
318
    ${build_dir}/Rd2.tex.pre > ${build_dir}/Rd2.tex
-
 
319
else
-
 
320
  sed -e s/^\\\\usepackage\\[@ENC@\\]/\\\\usepackage[${ENCS}]/ \
-
 
321
    ${build_dir}/Rd2.tex.pre > ${build_dir}/Rd2.tex
-
 
322
fi
-
 
323
 
306
## <FIXME>
324
## <FIXME>
307
## Need to do something smarter about the exit status in batch mode.
325
## Need to do something smarter about the exit status in batch mode.
308
status=0
326
status=0
309
## <FIXME>
327
## <FIXME>
310
 
328
 
311
echo "Creating ${out_ext} output from LaTeX ..."
329
echo "Creating ${out_ext} output from LaTeX ..."
312
cd ${build_dir}
330
cd ${build_dir}
313
${R_LATEXCMD-latex} Rd2 || status=1
331
${R_LATEXCMD-latex} Rd2 || status=1
314
${R_MAKEINDEXCMD-makeindex} Rd2
332
${R_MAKEINDEXCMD-makeindex} Rd2
315
${R_LATEXCMD-latex} Rd2
333
${R_LATEXCMD-latex} Rd2
316
if test "${out_ext}" = pdf; then
334
if test "${out_ext}" = pdf; then
317
  ${R_LATEXCMD-latex} Rd2
335
  ${R_LATEXCMD-latex} Rd2
318
fi
336
fi
319
cd ${start_dir}
337
cd ${start_dir}
320
${echo} "Saving output to '${output}' ..."
338
${echo} "Saving output to '${output}' ..."
321
cp ${build_dir}/Rd2.${out_ext} ${output}
339
cp ${build_dir}/Rd2.${out_ext} ${output}
322
echo "Done"
340
echo "Done"
323
 
341
 
324
if ${clean}; then
342
if ${clean}; then
325
  rm -rf ${build_dir}
343
  rm -rf ${build_dir}
326
else
344
else
327
  ${echo} "You may want to clean up by 'rm -rf ${build_dir}'"
345
  ${echo} "You may want to clean up by 'rm -rf ${build_dir}'"
328
fi
346
fi
329
${preview} ${output}
347
${preview} ${output}
330
exit ${status}
348
exit ${status}
331
 
349
 
332
### Local Variables: ***
350
### Local Variables: ***
333
### mode: sh ***
351
### mode: sh ***
334
### sh-indentation: 2 ***
352
### sh-indentation: 2 ***
335
### End: ***
353
### End: ***