Rev 48164 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
## Rd2dvi -- Convert man pages (*.Rd help files) via LaTeX to DVI/PDF.#### Examples:## R CMD Rd2dvi /path/to/Rsrc/src/library/base/man/Normal.Rd## R CMD Rd2dvi `grep -l "\\keyword{distr" \## /path/to/Rsrc/src/library/stats/man/*.Rd | sort | uniq`revision='$Rev: 49329 $'version=`set - ${revision}; echo ${2}`version="Rd2dvi: ${R_VERSION} (r${version})Copyright (C) 2000-2009 The R Core Development Team.This is free software; see the GNU General Public License version 2or later for copying conditions. There is NO warranty."usage="Usage: R CMD Rd2dvi [options] filesGenerate DVI (or PDF) output from the Rd sources specified by files, byeither giving the paths to the files, or the path to a directory withthe sources of a package/bundle, or an installed package.Unless specified via option '--output', the basename of the output fileequals the basename of argument 'files' if this specifies a package(bundle) or a single file, and 'Rd2' otherwise.The Rd sources are assumed to be ASCII unless they contain \encodingdeclarations (which take priority) or --encoding is supplied or if usingpackage sources, if the package DESCRIPTION file has an Encoding field.Options:-h, --help print short help message and exit-v, --version print version info and exit--batch no interaction--debug turn on shell debugging (set -x)--no-clean do not remove created temporary files--no-preview do not preview generated DVI file--encoding=enc use 'enc' as the default encoding--os=NAME use OS subdir 'NAME' (unix or windows)--OS=NAME the same as '--os'-o, --output=FILE write output to FILE--pdf generate PDF output--title=NAME use NAME as the title of the document-V, --verbose report on what is done--no-index don't index PDF output--no-description don't typeset the description of a package--internals typeset 'internal' documentation (usually skipped)The output papersize is set by the environment variable R_PAPERSIZE.The DVI previewer is set by the environment variable xdvi.The PDF previewer is set by the environment variable R_PDFVIEWER.Report bugs to <r-bugs@r-project.org>."## workaround the export of CDPATH, which may cause 'cd ${build_dir}' to echounset CDPATHstart_dir=`pwd`build_dir=".Rd2dvi${$}"title=""batch=falseclean=truedebug=falseonly_meta=falseout_ext="dvi"output=""verbose=falseenc=unknownindex=truedescription=trueinternals=noif test "${R_OSTYPE}" = "windows"; thenecho=echopreview=${xdvi-open}OSdir=windowselse## Need a `safe' echo which does not interpret backslash-escaped## characters in SysV style.## FIXME: R_SHARE_DIR might contain a space.echo="sh ${R_SHARE_DIR}/sh/echo.sh"preview=${xdvi-xdvi}OSdir=unixfiwhile test -n "${1}"; docase ${1} in-h|--help)${echo} "${usage}"; exit 0 ;;-v|--version)${echo} "${version}"; exit 0 ;;--batch)batch=true ;;--debug)debug=true ;;--no-clean)clean=false ;;--no-preview)preview=false ;;--pdf)out_ext="pdf";## allow for --no-preview --pdfif test "${preview}" != "false"; thenif test -n "${R_PDFVIEWER}"; thenpreview=${R_PDFVIEWER}elif test "${R_OSTYPE}" = "windows"; thenpreview=openelsepreview=falsefifiR_RD4DVI=${R_RD4PDF-"times,hyper"}R_LATEXCMD="${R_PDFLATEXCMD}";;--title=*)title=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;-o)if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; thenoutput="${2}"; shiftelseecho "ERROR: option '${1}' requires an argument"exit 1fi;;--only-meta)only_meta=true ;;--output=*)output=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;--OS=*|--os=*)OSdir=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;--encoding=*)enc=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;--build-dir=*)build_dir=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;-V|--verbose)verbose=${echo} ;;--no-index)index=false ;;--no-description)description=false ;;--internals)internals="yes" ;;--|*)break ;;esacshiftdoneif ${debug}; then set -x; fido_cleanup () {if ${clean}; thencd ${start_dir}rm -rf ${build_dir}elseecho "You may want to clean up by 'rm -rf ${build_dir}'"fi}is_bundle=noif test -d "${1}"; thenif test -f ${1}/DESCRIPTION; thenif test -n "`grep '^Bundle:' ${1}/DESCRIPTION`"; thenecho "Hmm ... looks like a package bundle"is_bundle=yeselseecho "Hmm ... looks like a package"dir=${1}fitest -z "${output}" && output="`basename ${1}`.${out_ext}"elif test -f ${1}/DESCRIPTION.in && \test -n "`grep '^Priority: *base' ${1}/DESCRIPTION.in`"; thenecho "Hmm ... looks like a package from the R distribution"dir=${1}test -z "${output}" && output="`basename ${1}`.${out_ext}"elseif test -d ${1}/man; thendir=${1}/manelsedir=${1}fifielseif test ${#} -eq 1 ; thenif test -z "${output}"; thenoutput=`basename "${1}"`output="`echo ${output} | ${SED} 's/[Rr]d$//'`${out_ext}"fififi## Prepare for building the documentation.if test -z "${output}"; thenoutput="Rd2.${out_ext}"fiif test -f ${output}; thenecho "file '${output}' exists; please remove first"exit 1fiif test -d ${build_dir}; thenrm -rf ${build_dir} || echo "cannot write to build dir" && exit 2fimkdir ${build_dir}echo "tools:::.Rd2dvi(\"${1}\", \"${build_dir}/Rd2.tex\", \"$is_bundle\", \\"$title\", \"$batch\", \"$description\", \"$only_meta\",\\"$enc\", \"${dir-$@}\", \"OSdir\", \"$internals\", \"$index\")" \| LC_ALL=C ${R_HOME}/bin/R --slave --vanilla || exit 1## <FIXME>## Need to do something smarter about the exit status in batch mode.status=0## <FIXME>R_TEXOPTS=if test "${R_OSTYPE}" = "windows"; thenmiktex=`latex --version | grep ^MiKTeX | wc -l`if test "${miktex}" = "1"; thenR_TEXOPTS=--include-directory=${R_HOME}/share/texmffifiecho "Creating ${out_ext} output from LaTeX ..."cd ${build_dir}if test "${out_ext}" = pdf; then${R_PDFLATEXCMD} ${R_TEXOPTS} Rd2 || status=1if test $status -gt 0; thenecho "Error in running pdflatex command ('${R_PDFLATEXCMD}')"do_cleanupexit 1fiif test "${index}" != "false"; then## OK for R_MAKEINDEXCMD to fail.${R_MAKEINDEXCMD} Rd2${R_PDFLATEXCMD} ${R_TEXOPTS} Rd2 || status=1if test $status -gt 0; thenecho "Error in running pdflatex command ('${R_PDFLATEXCMD}')"do_cleanupexit 1fifi${R_PDFLATEXCMD} ${R_TEXOPTS} Rd2 || status=1if test $status -gt 0; thenecho "Error in running pdflatex command ('${R_PDFATEXCMD}')"do_cleanupexit 1fielse${R_LATEXCMD} ${R_TEXOPTS} Rd2 || status=1if test $status -gt 0; thenecho "Error in running latex command ('${R_LATEXCMD}')"do_cleanupexit 1fi## OK for R_MAKEINDEXCMD to fail.${R_MAKEINDEXCMD} Rd2${R_LATEXCMD} ${R_TEXOPTS} Rd2 || status=1if test $status -gt 0; thenecho "Error in running latex command ('${R_LATEXCMD}')"do_cleanupexit 1fifiif test ! -f Rd2.${out_ext}; thenecho "Error: no output file was created"do_cleanupexit 1ficd ${start_dir}echo "Saving output to '${output}' ..."cp ${build_dir}/Rd2.${out_ext} ${output}echo "Done"do_cleanup${preview} ${output}exit ${status}### Local Variables: ***### mode: sh ***### sh-indentation: 2 ***### End: ***