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