-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathusingr.sty
211 lines (173 loc) · 11.8 KB
/
usingr.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
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{usingr}[2022/10/20]
\RequirePackage{booktabs}
\RequirePackage{xspace}
\RequirePackage{xcolor}
\RequirePackage{microtype}
%\usepackage{amsmath,amssymb,amsthm}
\RequirePackage{unicode-math}
\RequirePackage{fontspec}
% WIDOW and ORPHAN lines
% https://tex.stackexchange.com/questions/4152/how-do-i-prevent-widow-orphan-lines
% command to adjust tracking between characters
\newcommand{\Kern}[2]{\addfontfeature{LetterSpace=#1}#2\addfontfeature{LetterSpace=0}\null}%
% first argument for example +1 or -2, second argument the paragraph text
% \looseness can be an alternative
% For example \looseness=-1 within a paragraph will encourage shortening it by 1 line if possible
% \enlargethispage{1cm} or \enlargethispage*{1cm}
\setmainfont{Lucida Bright OT}
\setsansfont{Lucida Sans OT}
\setmonofont{Lucida Console DK}[Scale=1.05]
\setmathfont{Lucida Bright Math OT}
\linespread{1.1} % increase line spacing as we use in-line math and code
% smaller font for URLS
\renewcommand{\UrlFont}{\small\ttfamily}
%\newcommand\tetxtilde{\char"007E}
% We set up some symbol fonts
%\newfontfamily\wingdingsfont{Wingdings}
%\newcommand\wingdings[1]{{\wingdingsfont\symbol{#1}}}
%
%\newfontfamily\wingdingsfontdos{Wingdings2}
%\newcommand\wingdingsdos[1]{{\wingdingsfontdos\symbol{#1}}}
%
%\newfontfamily\wingdingsfonttres{Wingdings3}
%\newcommand\wingdingstres[1]{{\wingdingsfonttres\symbol{#1}}}
%\newfontfamily\meteoconsfont{Meteocons}
%\newcommand\meteocons[1]{{\meteoconsfont\symbol{#1}}}
%\newcommand\meteosun{\metecons{"0042}}
%\newcommand\meteosolidsun{\metecons{"0031}}
\newfontfamily\typiconsfont{Typicons}[Scale=MatchUppercase]
\newcommand\typicons[1]{{\typiconsfont\symbol{#1}}}
\newcommand\typiadvn{\typicons{"E137}}
\newcommand\typiattn{\typicons{"E04E}}
\newcommand\Attention[1]{\marginpar{\centering\colorbox{orange}{\Large\textcolor{white}{\typicons{"E137}}}}\index{#1}}
\newcommand\ilAttention{\noindent\colorbox{orange}{\Large\textcolor{white}{\typicons{"E137}}}\xspace}
\newcommand\Advanced[1]{\marginpar{\centering\colorbox{brown}{\Large\textcolor{white}{\typicons{"E04E}}}}\index{#1}}
\newcommand\ilAdvanced{\noindent\colorbox{brown}{\Large\textcolor{white}{\typicons{"E04E}}}\xspace}
\newcommand\noticestd[1]{{\noticestdfont\symbol{#1}}}
\newcommand\playicon{\noindent{\Large\colorbox{violet}{\textcolor{white}{\typicons{"E098}}}}\xspace}
\newcommand\advplayicon{\noindent{\colorbox{purple}{\textcolor{white}{\Large\typicons{"E098}\typicons{"E04E}}}}\xspace}
%\newfontfamily\noticestdfont{Notice2Std}
%\newcommand\noticestd[1]{{\noticestdfont\symbol{#1}}}
%\newcommand\playicon{\noindent{\large\colorbox{violet}{\textcolor{white}{\noticestd{"0055}}}}\xspace}
%\newcommand\advplayicon{\noindent{\colorbox{purple}{\textcolor{white}{{\large\noticestd{"0055}}{\Large\typicons{"E04E}}}}}\xspace}
\newfontfamily\modpictsfont{ModernPictograms}[Scale=MatchUppercase]
\newcommand\modpicts[1]{{\modpictsfont\symbol{#1}}}
\newcommand\infoicon{\noindent{\Large\colorbox{blue}{\textcolor{white}{\modpicts{"003D}}}}\xspace}
\newcommand\faqicon{\noindent{\Large\colorbox{darkgray}{\textcolor{white}{\modpicts{"003F}}}}\xspace}
\newcommand{\langname}[1]{\textsf{#1}\index{#1@\textsf{#1}}\index{languages!#1@\textsf{#1}}\xspace}
\newcommand{\langnameNI}[1]{\textsf{#1}\xspace}
\newcommand{\pgrmname}[1]{\textsf{#1}\index{#1@\textsf{#1}}\index{programmes!#1@\textsf{#1}}\xspace}
\newcommand{\pgrmnameNI}[1]{\textsf{#1}\xspace}
\newcommand{\pgrmnameTwo}[2]{\textsf{#1}\index{#2@\textsf{#1}}\index{programmes!#2@\textsf{#1}}\xspace}
\newcommand{\pkgname}[1]{`\textsf{#1}'\index{#1@\textsf{`#1'}}\index{packages!#1@\textsf{`#1'}}\xspace}
\newcommand{\pkgnameNI}[1]{`\textsf{#1}'\xspace}
\newcommand{\osname}[1]{\textsf{#1}\index{#1@\textsf{#1}}\index{operating systems!#1@\textsf{#1}}\xspace}
\newcommand{\osnameNI}[1]{\textsf{#1}\xspace}
\newcommand{\ggplot}{\pkgname{ggplot2}}
\newcommand{\ggspectra}{\pkgname{ggspectra}}
\newcommand{\ggmap}{\pkgname{ggmap}}
\newcommand{\ggtern}{\pkgname{ggtern}}
\newcommand{\ggrepel}{\pkgname{ggrepel}}
\newcommand{\ggsignif}{\pkgname{ggsignif}}
\newcommand{\ggpmisc}{\pkgname{ggpmisc}}
\newcommand{\ggpp}{\pkgname{ggpp}}
\newcommand{\cowplot}{\pkgname{cowplot}}
\newcommand{\scales}{\pkgname{scales}}
\newcommand{\plyr}{\pkgname{plyr}}
\newcommand{\dplyr}{\pkgname{dplyr}}
\newcommand{\tydyr}{\pkgname{tidyr}}
\newcommand{\readr}{\pkgname{readr}}
\newcommand{\xts}{\pkgname{xts}}
\newcommand{\Hmisc}{\pkgname{Hmisc}}
\newcommand{\viridis}{\pkgname{viridis}}
\newcommand{\R}{\textsf{R}}
%\newcommand{\Rpgrm}{\pgrmname{R}}
\newcommand{\Rpgrm}{\textsf{R}\xspace} % does not create index entry
\newcommand{\RStudio}{\pgrmname{RStudio}}
\newcommand{\git}{\pgrmname{git}}
\newcommand{\Quarto}{\pgrmname{Quarto}}
\newcommand{\Rlang}{\textsf{R}\xspace} % does not create index entry
\newcommand{\Slang}{\langname{S}}
\newcommand{\Splang}{\langname{S-Plus}}
\newcommand{\Clang}{\langname{C}}
\newcommand{\Cpplang}{\langname{C++}}
\newcommand{\javalang}{\langname{Java}}
\newcommand{\pythonlang}{\langname{Python}}
\newcommand{\pascallang}{\langname{Pascal}}
\newcommand{\perllang}{\langname{Perl}}
\newcommand{\Markdown}{\langname{Markdown}}
\newcommand{\Rmarkdown}{\langname{R markdown}}
\newcommand{\Latex}{{\LaTeX\xspace}\index{Latex@{\LaTeX}}\index{languages!Latex@{\LaTeX}}}
\newcommand{\stackoverflow}{\textsf{StackOverflow}\index{Stackoverflow@\textsf{StackOverflow}}\xspace}
\newcommand{\CRAN}{\textsf{CRAN}\index{CRAN@\textsf{CRAN}}\xspace}
\newcommand{\GitHub}{\textsf{GitHub}\index{GitHub@\textsf{GitHub}}\xspace}
\newcommand{\Bitbucket}{\textsf{Bitbucket}\index{Bitbucket@\textsf{Bitbucket}}\xspace}
\newcommand{\RForge}{\textsf{R-Forge}\index{R-Forge@\textsf{R-Forge}}\xspace}
% index entry
\newcommand{\indexfaq}[1]{\index[faqindex]{#1}}
% text and index entry
\newcommand{\Rclass}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{classes and modes!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rfunction}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rmethod}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Roperator}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{operators!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rloop}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{control of execution!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rcontrol}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{control of execution!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rconst}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{constant and special values!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rscoping}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{names and their scope!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\Rdata}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{data objects!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
% only index entry "quiet version" to create index entries for code chunks
\newcommand{\qRclass}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{classes and modes!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRfunction}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRmethod}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRoperator}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{operators!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRloop}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{control of execution!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRcontrol}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{control of execution!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRconst}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{constant and special values!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\qRscoping}[1]{\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{names and their scope!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\gggeom}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\ggposition}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\ggstat}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\ggtheme}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\ggscale}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
\newcommand{\ggcoordinate}[1]{\code{#1}\index[rindex]{#1@\texttt{#1}}\index[rcatsidx]{functions and methods!#1@\texttt{#1}}\index[cloudindex]{#1}\xspace}
%\newcommand{\gggeom}[1]{\code{#1}\index{plots!geometries!#1@\texttt{#1}}\xspace}
%\newcommand{\ggstat}[1]{\code{#1}\index{plots!statistics!#1@\texttt{#1}}\xspace}
%\newcommand{\ggtheme}[1]{\code{#1}\index{plots!themes!#1@\texttt{#1}}\xspace}
%\newcommand{\ggscale}[1]{\code{#1}\index{plots!scales!#1@\texttt{#1}}\xspace}
%\newcommand{\ggcoordinate}[1]{\code{#1}\index{plots!coordinates!#1@\texttt{#1}}\xspace}
% R commands embedded in main text
%\definecolor{codeshadecolor}{rgb}{0.969, 0.969, 0.900} % same fill as used by knitr
\definecolor{codeshadecolor}{rgb}{0.96, 0.96, 0.96} % not the same fill as now used in chunks
\newcommand{\code}[1]{\texttt{\addfontfeature{Scale = 0.89}{\setlength{\fboxsep}{0.05pt}\colorbox{codeshadecolor}{#1\vphantom{tp}}}}}
% at the moment using `shaded' and code chunks in same box results in the last text paragraph being discarded.
% this is most likely because knitr uses the same environment and we then end with a shaded environment
% nested within another one.
\newenvironment{leftbarc}[1][black]{%
\def\FrameCommand{\removelastskip\hspace{-6pt}{\color{#1}\vrule width 2pt} \hspace{3pt}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\removelastskip\endMakeFramed\removelastskip}
\OuterFrameSep=\parskip
% playgrounds and advanced playgrounds are numbered sharing a counter reset by chapter
\newlength{\iconsep}
\setlength{\iconsep}{.5em}
\newcounter{playground}[chapter]
\renewcommand{\theplayground}{\arabic{chapter}.\arabic{playground}}
\newenvironment{playground}[1]{\begin{leftbarc}[violet]\addtocounter{playground}{1}\playicon\ \textbf{\color{violet}\theplayground}\hspace{\iconsep}#1}{\end{leftbarc}}
\newenvironment{advplayground}[1]{\begin{leftbarc}[purple]\addtocounter{playground}{1}\advplayicon\ \textbf{\color{purple}\theplayground}\hspace{\iconsep}#1}{\end{leftbarc}}
\newenvironment{warningbox}[1]{\begin{leftbarc}[orange]\ilAttention\hspace{\iconsep}#1}{\end{leftbarc}}
\newenvironment{explainbox}[1]{\begin{leftbarc}[brown]\ilAdvanced\hspace{\iconsep}#1}{\end{leftbarc}}
%\newenvironment{infobox}[1]{\begin{leftbarc}[blue]\infoicon\hspace{\iconsep}#1}{\end{leftbarc}}
\newenvironment{faqbox}[2]{\begin{leftbarc}[darkgray]\faqicon\hspace{\iconsep}\textbf{#1}\indexfaq{#1}\\#2}{\end{leftbarc}}
\newenvironment{faqboxNI}[2]{\begin{leftbarc}[darkgray]\faqicon\hspace{\iconsep}\textbf{#1}\\#2}{\end{leftbarc}}
\newcommand{\citebooktitle}[1]{\citetitle{#1}}
%\newcommand{\citebooktitle}[1]{\emph{\citetitle{#1}}}
\definecolor{warningcolor}{rgb}{0.5, 0.4, 0}
% this is to reduce spacing above verbatim, which is used by knitr
% to show R's printed output
% and above and below call-outs
\usepackage{etoolbox}
\makeatletter
\preto{\@verbatim}{\topsep=-4pt \partopsep=-4pt}
\preto{\alltt}{\removelastskip}
\makeatother