Rev 14341 | Blame | Last modification | View Log | Download | RSS feed
#! /bin/sh## 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/base/man/*.Rd | sort | uniq`revision='$Revision: 1.33 $'version=`set - ${revision}; echo ${2}`version="Rd2dvi ${version}Copyright (C) 2000-2001 The R Core Development Team.This is free software; see the GNU General Public Licence 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.Options:-h, --help print short help message and exit-v, --version print version info and exit--debug turn on shell debugging (set -x)--no-clean do not remove created temporary files--no-preview do not preview generated output file--os=NAME use OS subdir \`NAME\' (unix, mac 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 doneReport bugs to <r-bugs@r-project.org>."TEXINPUTS=.:${R_HOME}/share/texmf:${TEXINPUTS}export TEXINPUTSstart_dir=`pwd`clean=truedebug=falseout_ext="dvi"output=""preview=xdviverbose=falseOSdir=${R_OSTYPE-"unix"}while test -n "${1}"; docase ${1} in-h|--help)echo "${usage}"; exit 0 ;;-v|--version)echo "${version}"; exit 0 ;;--debug)debug=true ;;--no-clean)clean=false ;;--no-preview)preview=false ;;--pdf)out_ext="pdf";preview=false;R_RD4DVI=${R_RD4PDF-"ae,hyper"};R_LATEXCMD=${PDFLATEX-pdflatex} ;;--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;;--output=*)output=`echo "${1}" | sed -e 's/[^=]*=//'` ;;--OS=*|--os=*)OSdir=`echo "${1}" | sed -e 's/[^=]*=//'` ;;-V|--verbose)verbose=echo ;;--|*)break ;;esacshiftdoneif test -z "${output}"; thenoutput=Rd2.${out_ext}fiif ${debug}; then set -x; fi. ${R_HOME}/share/sh/dcf.sh # get_dcf_field()Rdconv_dir_or_files_to_LaTeX () {## Convert Rd files in a dir or a list of Rd files to LaTeX, appending## the result to OUTFILE.## Usage:## Rdconv_dir_or_files_to_LaTeX OUTFILE DIR## Rdconv_dir_or_files_to_LaTeX OUTFILE FILES${verbose} $@out="${1}"shiftif test -d ${1}; thenfiles=`ls ${1}/*.[Rr]d`if test -d ${1}/${OSdir}; thenfiles="${files} `ls ${1}/${OSdir}/*.[Rr]d`"fifiles=`LC_ALL=C echo ${files} | sort`elsefiles="${@}"fiecho "Converting Rd files to LaTeX ..."for f in ${files}; doecho ${f}${R_CMD} Rdconv -t latex ${f} >> ${out}done}Rd_DESCRIPTION_to_LaTeX () {## Typeset the contents of a DESCRIPTION file in a LaTeX description## list.## Usage:## Rd_DESCRIPTION_to_LaTeX FILEfields=`sed '/^[ ]/d; s/^\([^:]*\):.*$/\1/' $1`echo "\\begin{description}"echo "\\raggedright{}"for f in `echo "${fields}" | sed '/Package/d; /Bundle/d;'`; dotext=`get_dcf_field ${f} ${1}`echo "\\item[${f}] \\AsIs{${text}}"doneecho "\\end{description}"}is_bundle=nois_base_package=nofile_sed='s/[_$]/\\&/g'toc="\\Rdcontents{\\R{} topics documented:}"if test -d "${1}"; thenif test -f ${1}/DESCRIPTION; thenif test -n "`grep '^Bundle:' ${1}/DESCRIPTION`"; thenecho "Hmm ... looks like a package bundle"is_bundle=yesbundle_name=`get_dcf_field Bundle "${1}/DESCRIPTION"`bundle_pkgs=`get_dcf_field Contains "${1}/DESCRIPTION"`title=${title-"Bundle \`${bundle_name}'"}elseecho "Hmm ... looks like a package"package_name=`get_dcf_field Package "${1}/DESCRIPTION"`title=${title-"Package \`${package_name}'"}dir=${1}/manfielif test -f ${1}/DESCRIPTION.in && \test -n "`grep '^Priority: *base' ${1}/DESCRIPTION.in`"; thenis_base_package=yesecho "Hmm ... looks like a package from the R distribution"package_name=`get_dcf_field Package "${1}/DESCRIPTION.in"`title=${title-"Package \`${package_name}'"}dir=${1}/manelseif test -d ${1}/man; thendir=${1}/manelsedir=${1}fisubj="all in \\file{`echo ${dir} | sed ${file_sed}`}"fielseif test ${#} -gt 1 ; thensubj=" etc.";elsesubj=toc=fisubj="\\file{`echo ${1} | sed ${file_sed}`}${subj}"fititle=${title-"\\R{} documentation}} \\par\\bigskip{{\\Large of ${subj}"}## Prepare for building the documentation.if test -f ${output}; thenecho "file \`${output}' exists; please remove first"exit 1fibuild_dir=.Rd2dvi${$}if test -d ${build_dir}; thenrm -rf ${build_dir} || echo "cannot write to build dir" && exit 2fimkdir ${build_dir}## Rd2.tex part 1: headercat > ${build_dir}/Rd2.tex <<EOF\\documentclass[${R_PAPERSIZE}paper]{book}\\usepackage[${R_RD4DVI-ae}]{Rd}\\usepackage{makeidx}\\makeindex{}\\begin{document}EOFif test ${is_bundle} = no; thencat >> ${build_dir}/Rd2.tex <<EOF\\chapter*{}\\begin{center}{\\textbf{\\huge ${title}}}\\par\\bigskip{\\large \\today}\\end{center}EOFif test -f ${1}/DESCRIPTION; thenRd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.texfiif test ${is_base_package} = yes; thenR_version=unknownif test -f ${1}/../../../VERSION; thenR_version=`cat ${1}/../../../VERSION`fiecho "`pwd`: ${1} ${R_version}"Rd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION.in | \sed "s/@VERSION@/${R_version}/" >> ${build_dir}/Rd2.texfielsecat >> ${build_dir}/Rd2.tex <<EOF\\pagenumbering{Roman}\\begin{titlepage}\\strut\\vfill\\begin{center}{\\textbf{\\Huge ${title}}}\\par\\bigskip{\\large \\today}\\end{center}\\par\\bigskipEOFRd_DESCRIPTION_to_LaTeX ${1}/DESCRIPTION >> ${build_dir}/Rd2.texcat >> ${build_dir}/Rd2.tex <<EOF\\vfill\\vfill\\end{titlepage}EOFfi## Rd2.tex part 2: bodyif test ${is_bundle} = no; thenecho ${toc} >> ${build_dir}/Rd2.texRdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${dir-${@}}elsecat >> ${build_dir}/Rd2.tex <<EOF\\pagenumbering{roman}\\tableofcontents{}\\cleardoublepage{}\\pagenumbering{arabic}EOFfor p in ${bundle_pkgs}; doecho "Bundle package: \`${p}'"echo "\\chapter{Package \`${p}'}" >> ${build_dir}/Rd2.texif test -f ${1}/${p}/DESCRIPTION.in; thenRd_DESCRIPTION_to_LaTeX ${1}/${p}/DESCRIPTION.in \>> ${build_dir}/Rd2.texfiRdconv_dir_or_files_to_LaTeX ${build_dir}/Rd2.tex ${1}/${p}/manecho "\\clearpage{}" >> ${build_dir}/Rd2.texdoneecho "\\cleardoublepage{}" >> ${build_dir}/Rd2.texfi## Rd2.tex part 3: footercat >> ${build_dir}/Rd2.tex <<EOF\\printindex{}\\end{document}EOFecho "Creating ${out_ext} output from LaTeX ..."cd ${build_dir}${R_LATEXCMD-latex} Rd2${R_MAKEINDEXCMD-makeindex} Rd2${R_LATEXCMD-latex} Rd2if test ${out_ext} = pdf; then${R_LATEXCMD-latex} Rd2ficd ${start_dir}cp ${build_dir}/Rd2.${out_ext} ${output}echo "Done"if ${clean}; thenrm -rf ${build_dir}elseecho "You may want to clean up by \`rm -rf ${build_dir}'"fi${preview} ${output}exit 0### Local Variables: ***### mode: sh ***### sh-indentation: 2 ***### End: ***