Rd.sty (15857B)
1 %%% Rd.sty ... Style for printing the R manual 2 %%% Part of the R package, https://www.R-project.org 3 %%% Copyright (C) 2003-2022 The R Foundation 4 %%% Distributed under GPL 2 or later 5 %%% 6 %%% Modified 1998/01/05 by Friedrich Leisch 7 %%% Modified 1998/07/07 by Martin Maechler 8 %%% Modified 1999/11/20 by Brian Ripley 9 %%% Modified 1999/12/26 by Kurt Hornik 10 %%% and so on. 11 12 \NeedsTeXFormat{LaTeX2e} 13 \ProvidesPackage{Rd}{} 14 15 \RequirePackage{ifthen} 16 \newboolean{Rd@use@hyper} 17 \setboolean{Rd@use@hyper}{true} 18 \newboolean{Rd@has@times} 19 \newboolean{Rd@use@times} 20 \newboolean{Rd@has@lm} 21 \newboolean{Rd@use@lm} 22 \newboolean{Rd@use@beramono} 23 \newboolean{Rd@use@inconsolata} 24 \DeclareOption{ae}{} % no-op, retained for backward compatibility 25 \DeclareOption{hyper}{\setboolean{Rd@use@hyper}{true}} 26 \DeclareOption{times}{\setboolean{Rd@use@times}{true}} 27 \DeclareOption{lm}{\setboolean{Rd@use@lm}{true}} 28 \DeclareOption{cm-super}{} % no-op, retained for backward compatibility 29 \DeclareOption{beramono}{\setboolean{Rd@use@beramono}{true}} 30 \DeclareOption{inconsolata}{\setboolean{Rd@use@inconsolata}{true}} 31 \ProcessOptions 32 \RequirePackage{longtable} 33 \setcounter{LTchunksize}{250} 34 \ifthenelse{\boolean{Rd@use@hyper}} 35 {\IfFileExists{hyperref.sty}{}{\setboolean{Rd@use@hyper}{false} 36 \message{package hyperref not found}}} 37 {} 38 39 \RequirePackage{bm} % standard boldsymbol 40 \RequirePackage{alltt} % {verbatim} allowing \.. 41 \RequirePackage{verbatim} % small example code 42 \RequirePackage{url} % set urls 43 \RequirePackage{textcomp} % for \textquotesingle etc 44 45 \RequirePackage{amsmath} % for \lVert, \text etc, and KaTeX consistency 46 \RequirePackage{amsfonts,amssymb} 47 \newboolean{Rd@has@rsfs} 48 \IfFileExists{mathrsfs.sty}{\IfFileExists{rsfs/scrload.tex}% 49 {\setboolean{Rd@has@rsfs}{true}}{}}{} 50 \ifthenelse{\boolean{Rd@has@rsfs}}% 51 {\RequirePackage{mathrsfs}}% 52 {\usepackage[mathscr]{eucal}}% part of amsfonts 53 54 55 \addtolength{\textheight}{12mm} 56 \addtolength{\topmargin}{-9mm} % still fits on US paper 57 \addtolength{\textwidth}{24mm} % still fits on US paper 58 \setlength{\oddsidemargin}{10mm} 59 \setlength{\evensidemargin}{\oddsidemargin} 60 61 \newenvironment{display}[0]% 62 {\begin{list}{}{\setlength{\leftmargin}{30pt}}\item}% 63 {\end{list}} 64 \newcommand{\HTML}{{\normalfont\textsc{html}}} 65 \newcommand{\R}{{\normalfont\textsf{R}}{}} 66 \newcommand{\Rdash}{-} 67 68 % \def\href#1#2{\special{html:<a href="#1">}{#2}\special{html:</a>}} 69 70 \newcommand{\vneed}[1]{% 71 \penalty-1000\vskip#1 plus 10pt minus #1\penalty-1000\vspace{-#1}} 72 73 \newcommand{\Rdcontents}[1]{% modified \tableofcontents -- not \chapter 74 \section*{{#1}\@mkboth{\MakeUppercase#1}{\MakeUppercase#1}} 75 \@starttoc{toc}} 76 77 \newcommand{\Header}[2]{% 78 \vneed{1ex} 79 \markboth{#1}{#1} 80 \noindent 81 \nopagebreak 82 \begin{center} 83 \ifthenelse{\boolean{Rd@use@hyper}}% 84 {\def\@currentHref{page.\thepage} 85 \hypertarget{Rfn.#1}{\index{#1@\texttt{#1}}}% 86 \myaddcontentsline{toc}{subsection}{#1}% 87 \pdfbookmark[1]{#1}{Rfn.#1}} 88 {\addcontentsline{toc}{subsection}{#1} 89 \index{#1@\texttt{#1}|textbf}} 90 \hrule 91 \parbox{0.95\textwidth}{% 92 \begin{ldescription}[1.5in] 93 \item[\texttt{#1}] \emph{#2} 94 \end{ldescription}} 95 \hrule 96 \end{center} 97 \nopagebreak} 98 % 99 % 100 % 101 % \alias{<alias>}{<header>} 102 \ifthenelse{\boolean{Rd@use@hyper}} 103 {\newcommand{\alias}[2]{\hypertarget{Rfn.#1}{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}}} 104 {\newcommand{\alias}[2]{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}} 105 \ifthenelse{\boolean{Rd@use@hyper}} 106 {\newcommand{\methalias}[2]{\hypertarget{Rfn.#1}{\relax}}} 107 {\newcommand{\methalias}[2]{}} 108 % \keyword{<topic>}{<header>} 109 \newcommand{\keyword}[2]{\index{$*$ {\textbf{#1}}!#2@\texttt{#2}}} 110 % 111 % used prior to 2.10.0 only 112 \newcommand{\Itemize}[1]{\begin{itemize}{#1}\end{itemize}} 113 \newcommand{\Enumerate}[1]{\begin{enumerate}{#1}\end{enumerate}} 114 \newcommand{\describe}[1]{\begin{description}{#1}\end{description}} 115 116 \newcommand{\Tabular}[2]{% 117 \par\begin{longtable}{#1} 118 #2 119 \end{longtable}} 120 121 \newlength{\ldescriptionwidth} 122 \newcommand{\ldescriptionlabel}[1]{% 123 \settowidth{\ldescriptionwidth}{{#1}}% 124 \ifdim\ldescriptionwidth>\labelwidth 125 % FIXME: labels can become very long for combined arguments 126 % (e.g., in format.Rd) and need line wrapping 127 {\parbox[b]{\labelwidth}% 128 {\makebox[0pt][l]{#1}\\[1pt]\makebox{}}}% 129 \else 130 \makebox[\labelwidth][l]{{#1}}% 131 \fi 132 \hfil\relax} 133 \newenvironment{ldescription}[1][1in]% 134 {\begin{list}{}% 135 {\setlength{\labelwidth}{#1}% 136 \setlength{\leftmargin}{\labelwidth}% 137 \addtolength{\leftmargin}{\labelsep}% 138 \renewcommand{\makelabel}{\ldescriptionlabel}}}% 139 {\end{list}} 140 141 \newenvironment{Rdsection}[1]{% 142 \ifx\@empty#1\else\subsubsection*{#1}\fi 143 \begin{list}{}{\setlength{\leftmargin}{0.25in}}\item\relax} 144 {\end{list}} 145 146 \newenvironment{Arguments}{% 147 \begin{Rdsection}{Arguments}}{\end{Rdsection}} 148 \newenvironment{Author}{% 149 \begin{Rdsection}{Author(s)}}{\end{Rdsection}} 150 \newenvironment{Description}{% 151 \begin{Rdsection}{Description}}{\end{Rdsection}} 152 \newenvironment{Details}{% 153 \begin{Rdsection}{Details}}{\end{Rdsection}} 154 \newenvironment{Examples}{% 155 \begin{Rdsection}{Examples}}{\end{Rdsection}} 156 \newenvironment{Note}{% 157 \begin{Rdsection}{Note}}{\end{Rdsection}} 158 \newenvironment{References}{% 159 \begin{Rdsection}{References}}{\end{Rdsection}} 160 \newenvironment{SeeAlso}{% 161 \begin{Rdsection}{See Also}}{\end{Rdsection}} 162 \newenvironment{Format}{% 163 \begin{Rdsection}{Format}}{\end{Rdsection}} 164 \newenvironment{Source}{% 165 \begin{Rdsection}{Source}}{\end{Rdsection}} 166 \newenvironment{Section}[1]{% 167 \begin{Rdsection}{#1}}{\end{Rdsection}} 168 \newenvironment{Usage}{% 169 \begin{Rdsection}{Usage}}{\end{Rdsection}} 170 \newenvironment{Value}{% 171 \begin{Rdsection}{Value}}{\end{Rdsection}} 172 173 \newenvironment{SubSection}[1]{% 174 \begin{list}{}{\setlength{\leftmargin}{0.1in}}\item \textbf{#1: }}{\end{list}} 175 \newenvironment{SubSubSection}[1]{% 176 \begin{list}{}{\setlength{\leftmargin}{0.1in}}\item \textit{#1: }}{\end{list}} 177 178 \newenvironment{ExampleCode}{\small\verbatim}{\endverbatim} 179 180 \newcommand{\bsl}{\ifmmode\backslash\else\textbackslash\fi} 181 182 %fails for index (but is not used there...) 183 \newcommand{\SIs}{\relax\ifmmode\leftarrow\else$\leftarrow$\fi} 184 \newcommand{\SIIs}{\relax\ifmmode<\leftarrow\else$<\leftarrow$\fi} 185 \newcommand{\Sbecomes}{\relax\ifmmode\rightarrow\else$\rightarrow$\fi} 186 % 187 \newcommand{\deqn}[2]{\[#1\]} 188 \newcommand{\eqn}[2]{$#1$} 189 \renewcommand{\bold}[1]{\ifmmode\bm{#1}\else\textbf{#1}\fi} 190 %% as from R 2.12.0 set \file in monospaced font, not sans-serif 191 \newcommand{\file}[1]{`\texttt{#1}'} 192 193 \newcommand{\Figure}[2]{\includegraphics[#2]{#1}} 194 195 \ifthenelse{\boolean{Rd@use@hyper}} 196 {\newcommand{\link}[1]{\hyperlink{Rfn.#1}{#1}\index{#1@\texttt{#1}}}} 197 {\newcommand{\link}[1]{#1\index{#1@\texttt{#1}}}} 198 199 \ifthenelse{\boolean{Rd@use@hyper}} 200 {\newcommand*{\Rhref}{\begingroup\@makeother\#\@makeother\%\@Rhref} 201 \newcommand*{\@Rhref}[2]{\href{#1}{#2}\endgroup}} 202 {\newcommand*{\Rhref}{\begingroup\@makeother\#\@makeother\%\@Rhref} 203 \newcommand*{\@Rhref}[2]{#2\footnote{\url{#1}}\endgroup}} 204 205 %% as from R 2.10.0 set \email in monospaced font (like \url) 206 %\newcommand{\email}[1]{$\langle$\texttt{#1}$\rangle$} 207 \newcommand{\email}[1]{\normalfont\texttt{\textless#1\textgreater}} 208 209 %% \code without `-' ligatures 210 211 %{\catcode`\-=\active% 212 % \global\def\code{\bgroup% 213 % \catcode`\-=\active \let-\codedash% 214 % \Rd@code}} 215 % \def\codedash{-\discretionary{}{}{}} 216 217 %% If we simply do 218 %% \DeclareRobustCommand\code{\bgroup\@noligs\@vobeyspaces\Rd@code} 219 %% then e.g. 220 %% \code{\LinkA{attr<-}{attr<.Rdash.}} 221 %% will give an undefined control sequence `\< error when hyperref is 222 %% used (so that \LinkA uses \hyperlink). 223 %% Hence, use a noligs list without < and > for now, and use the same 224 %% list for \code and \samp and their variants. 225 \def\Rd@nolig@list{\do\`\do\,\do\'\do\-} 226 \def\Rd@noligs{\let\do\do@noligs \Rd@nolig@list} 227 %% Using \frenchspacing in \Rd@code gives 'Undefined control sequence' 228 %% errors in combination with hyperref and amsmath (e.g., parallel.Rnw): 229 %% Hence try using the variant below. 230 \def\Rd@frenchspacing{\sfcode`.=\@m \sfcode`?=\@m \sfcode`!=\@m 231 \sfcode`:=\@m \sfcode`;=\@m \sfcode`,=\@m } 232 \def\Rd@code#1{% 233 \normalfont 234 \Rd@frenchspacing 235 \spaceskip=\fontdimen2\font\relax 236 \texttt{#1}% 237 \egroup 238 } 239 240 \ifx\l@nohyphenation \@undefined 241 \newlanguage\l@nohyphenation 242 \fi 243 244 % \DeclareRobustCommand{\code}{\bgroup\Rd@noligs\Rd@code} 245 \def\Rd@code@space{\leavevmode\unskip\space\ignorespaces} 246 {\catcode`\ =\active% 247 \gdef\Rd@code@obeyspaces{\catcode`\ \active\let \Rd@code@space}} 248 \def\Rd@code@wrk#1{\texttt{#1}\egroup} 249 \def\Rd@code@ini{% 250 \language\l@nohyphenation 251 \normalfont\spaceskip=\fontdimen2\font\relax 252 \Rd@noligs \Rd@frenchspacing \Rd@code@obeyspaces 253 } 254 \DeclareRobustCommand{\code}{\bgroup \Rd@code@ini \Rd@code@wrk} 255 256 \let\command=\code 257 \let\env=\code 258 259 % \def\Rd@samp#1{\Rd@code{#1}\rq} 260 % \DeclareRobustCommand{\samp}{\lq\bgroup\Rd@noligs\Rd@samp} 261 \def\Rd@samp@wrk#1{\texttt{#1}\egroup\rq} 262 \DeclareRobustCommand{\samp}{\lq\bgroup\Rd@code@ini\Rd@samp@wrk} 263 \let\option=\samp 264 265 \def\AsIs{\bgroup\let\do\@makeother\Rd@AsIs@dospecials\@noligs\obeylines\@vobeyspaces\parskip\z@skip\Rd@AsIsX} 266 \def\Rd@AsIs@dospecials{\do\$\do\&\do\#\do\^\do\_\do\%\do\~} 267 \def\Rd@AsIsX#1{\normalfont #1\egroup} 268 269 % This is a workaround for the old Rdconv to handle \Sexpr by echoing it 270 % Rd2latex() should never let \Sexpr through to here. 271 \newcommand\Sexpr[2][]{{\normalfont\texttt{\bsl Sexpr[#1]\{#2\}}}} 272 273 \newcommand{\var}[1]{{\normalfont\textsl{#1}}} 274 275 \newcommand{\dfn}[1]{\textsl{#1}} 276 \let\Cite=\dfn 277 278 \newcommand{\acronym}[1]{\textsc{\lowercase{#1}}} 279 \newcommand{\kbd}[1]{{\normalfont\texttt{\textsl{#1}}}} 280 281 \newcommand{\strong}[1]{{\normalfont\fontseries{b}\selectfont #1}} 282 \let\pkg=\strong 283 284 \newcommand{\sQuote}[1]{`#1'} 285 \newcommand{\dQuote}[1]{``#1''} 286 287 %% load fontenc (with ec fonts) unless we detect that we are not running pdfTeX 288 \IfFileExists{iftex.sty}{\RequirePackage{iftex}}{} 289 \@ifpackageloaded{iftex}{\ifPDFTeX\usepackage[T1]{fontenc}\fi}{% 290 \usepackage[T1]{fontenc}} 291 292 \IfFileExists{times.sty}{\setboolean{Rd@has@times}{true}}{} 293 \ifthenelse{\boolean{Rd@use@times}\and\boolean{Rd@has@times}}{% 294 \usepackage{times}}{} 295 \IfFileExists{lmodern.sty}{\setboolean{Rd@has@lm}{true}}{} 296 \ifthenelse{\boolean{Rd@use@lm}\and\boolean{Rd@has@lm}}{% 297 \usepackage{lmodern}}{} 298 \ifthenelse{\boolean{Rd@use@beramono}}{% 299 \usepackage[scaled=.8]{beramono}}{} 300 %% it appears that all versions of zi4.sty support [noupquote], 301 %% whereas only those since 2013/06/09 of inconsolata.sty do: such 302 %% installations should also have zi4.sty 303 \ifthenelse{\boolean{Rd@use@inconsolata}}{% 304 \IfFileExists{zi4.sty}{\usepackage[noupquote]{zi4}}{\usepackage{inconsolata}}}{} 305 306 %% needs to come after \code is defined 307 %% inspired by an earlier version of upquote.sty 308 \begingroup 309 \catcode`'=\active \catcode``=\active 310 \g@addto@macro\@noligs {\let`\textasciigrave \let'\textquotesingle} 311 \g@addto@macro\Rd@noligs {\let`\textasciigrave \let'\textquotesingle} 312 \endgroup 313 314 %% We use \pkg{verbatim} for our ExampleCode environment, which in its 315 %% \verbatim@font has an explicit \let\do\do@noligs\verbatim@nolig@list 316 %% rather than (the identical) \@noligs from the LaTeX2e kernel. 317 %% Hence, we add to \verbatim@font ... suggestion by Bernd Raichle 318 %% <raichle@Informatik.Uni-Stuttgart.DE>. 319 \g@addto@macro\verbatim@font\@noligs 320 321 \ifthenelse{\boolean{Rd@use@hyper}}{% 322 \RequirePackage{color} 323 \def\myaddcontentsline#1#2#3{% 324 \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}{page.\thepage}}} 325 \RequirePackage{hyperref} 326 \DeclareTextCommand{\Rpercent}{PD1}{\045} % percent 327 %% <NOTE> 328 %% Formerly in R's hyperref.cfg, possibly to be shared with Sweave.sty 329 \AtBeginDocument{% 330 \definecolor{Blue}{rgb}{0,0,0.8} 331 \definecolor{Red}{rgb}{0.7,0,0}} 332 \hypersetup{% 333 colorlinks,% 334 linktocpage,% 335 plainpages=false,% 336 linkcolor=Blue,% 337 citecolor=Blue,% 338 urlcolor=Red,% 339 pdfstartview=Fit,% 340 pdfview={XYZ null null null}% 341 } 342 %% </NOTE> 343 \renewcommand\tableofcontents{% 344 \if@twocolumn 345 \@restonecoltrue\onecolumn 346 \else 347 \@restonecolfalse 348 \fi 349 \@ifundefined{chapter*}{}{\chapter*{\contentsname 350 \@mkboth{% 351 \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}}% 352 \pdfbookmark{Contents}{contents} 353 \@starttoc{toc}% 354 \if@restonecol\twocolumn\fi 355 } 356 \renewenvironment{theindex} 357 {\if@twocolumn 358 \@restonecolfalse 359 \else 360 \@restonecoltrue 361 \fi 362 \columnseprule \z@ 363 \columnsep 35\p@ 364 \twocolumn[\@makeschapterhead{\indexname}]% 365 \@mkboth{\MakeUppercase\indexname}% 366 {\MakeUppercase\indexname}% 367 \pdfbookmark{Index}{index} 368 \myaddcontentsline{toc}{chapter}{Index} 369 \thispagestyle{plain}\parindent\z@ 370 \parskip\z@ \@plus .3\p@\relax 371 \raggedright 372 \let\item\@idxitem} 373 {\if@restonecol\onecolumn\else\clearpage\fi} 374 }{ 375 \renewenvironment{theindex} 376 {\if@twocolumn 377 \@restonecolfalse 378 \else 379 \@restonecoltrue 380 \fi 381 \columnseprule \z@ 382 \columnsep 35\p@ 383 \twocolumn[\@makeschapterhead{\indexname}]% 384 \@mkboth{\MakeUppercase\indexname}% 385 {\MakeUppercase\indexname}% 386 \addcontentsline{toc}{chapter}{Index} 387 \thispagestyle{plain}\parindent\z@ 388 \parskip\z@ \@plus .3\p@\relax 389 \raggedright 390 \let\item\@idxitem} 391 {\if@restonecol\onecolumn\else\clearpage\fi} 392 } 393 394 % new definitions for R >= 2.0.0 395 \ifthenelse{\boolean{Rd@use@hyper}} 396 {\newcommand{\LinkA}[2]{\hyperlink{Rfn.#2}{#1}\index{#1@\texttt{#1}|textit}}} 397 {\newcommand{\LinkA}[2]{#1\index{#1@\texttt{#1}|textit}}} 398 % 399 % \alias{<alias>}{<header>} 400 \ifthenelse{\boolean{Rd@use@hyper}} 401 {\newcommand{\aliasA}[3]{\hypertarget{Rfn.#3}{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}}} 402 {\newcommand{\aliasA}[3]{\index{#1@\texttt{#1} \textit{(\texttt{#2})}}}} 403 % \aliasB has no indexing. 404 \ifthenelse{\boolean{Rd@use@hyper}} 405 {\newcommand{\aliasB}[3]{\hypertarget{Rfn.#3}{\relax}}} 406 {\newcommand{\aliasB}[3]{}} 407 \ifthenelse{\boolean{Rd@use@hyper}} 408 {\newcommand{\methaliasA}[3]{\hypertarget{Rfn.#3}{\relax}}} 409 {\newcommand{\methaliasA}[3]{}} 410 411 \ifthenelse{\boolean{Rd@use@hyper}} 412 {\newcommand{\CRANpkg}[1]{\href{https://CRAN.R-project.org/package=#1}{\pkg{#1}}}} 413 {\newcommand{\CRANpkg}[1]{\pkg{#1}}} 414 415 \newcommand{\HeaderA}[3]{% 416 \vneed{1ex} 417 \markboth{#1}{#1} 418 \noindent 419 \nopagebreak 420 \begin{center} 421 \ifthenelse{\boolean{Rd@use@hyper}}% 422 {\def\@currentHref{page.\thepage} 423 \hypertarget{Rfn.#3}{\index{#1@\texttt{#1}}}% 424 \myaddcontentsline{toc}{subsection}{#1}% 425 \pdfbookmark[1]{#1}{Rfn.#3}} 426 {\addcontentsline{toc}{subsection}{#1} 427 \index{#1@\texttt{#1}|textbf}} 428 \hrule 429 \parbox{0.95\textwidth}{% 430 \begin{ldescription}[1.5in] 431 \item[\texttt{#1}] \emph{#2} 432 \end{ldescription}} 433 \hrule 434 \end{center} 435 \nopagebreak} 436 \DeclareTextCommandDefault{\Rpercent}{\%{}} 437 %% for use with the output of encoded_text_to_latex 438 \ProvideTextCommandDefault{\textdegree}{\ensuremath{{^\circ}}} 439 \ProvideTextCommandDefault{\textonehalf}{\ensuremath{\frac12}} 440 \ProvideTextCommandDefault{\textonequarter}{\ensuremath{\frac14}} 441 \ProvideTextCommandDefault{\textthreequarters}{\ensuremath{\frac34}} 442 \ProvideTextCommandDefault{\textcent}{\TextSymbolUnavailable\textcent} 443 \ProvideTextCommandDefault{\textyen}{\TextSymbolUnavailable\textyen} 444 \ProvideTextCommandDefault{\textcurrency}{\TextSymbolUnavailable\textcurrency} 445 \ProvideTextCommandDefault{\textbrokenbar}{\TextSymbolUnavailable\textbrokenbar} 446 \ProvideTextCommandDefault{\texteuro}{\TextSymbolUnavailable\texteuro} 447 \providecommand{\mathonesuperior}{\ensuremath{^1}} 448 \providecommand{\mathtwosuperior}{\ensuremath{^2}} 449 \providecommand{\maththreesuperior}{\ensuremath{^3}} 450 451 \InputIfFileExists{Rd.cfg}{% 452 \typeout{Reading personal defaults ...}}{}