Sharedlatex-tests / test.texOpen in CoCalc
Author: Harald Schilly
1
\documentclass{article}\usepackage[]{graphicx}\usepackage[]{color}
2
%% maxwidth is the original width if it is less than linewidth
3
%% otherwise use linewidth (to make sure the graphics do not exceed the margin)
4
\makeatletter
5
\def\maxwidth{ %
6
\ifdim\[email protected]@width>\linewidth
7
\linewidth
8
\else
9
\[email protected]@width
10
\fi
11
}
12
\makeatother
13
14
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
15
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
16
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
17
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
18
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
19
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
20
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
21
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
22
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
23
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
24
\let\hlipl\hlkwb
25
26
\usepackage{framed}
27
\makeatletter
28
\newenvironment{kframe}{%
29
\def\[email protected]@[email protected]{}%
30
\ifinner\ifhmode%
31
\def\[email protected]@[email protected]{\end{minipage}}%
32
\begin{minipage}{\columnwidth}%
33
\fi\fi%
34
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
35
\colorbox{shadecolor}{##1}\hskip-\fboxsep
36
% There is no \\@totalrightmargin, so:
37
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
38
\MakeFramed {\advance\hsize-\width
39
\@totalleftmargin\[email protected] \linewidth\hsize
40
\@setminipage}}%
41
{\par\unskip\endMakeFramed%
42
\[email protected]@[email protected]}
43
\makeatother
44
45
\definecolor{shadecolor}{rgb}{.97, .97, .97}
46
\definecolor{messagecolor}{rgb}{0, 0, 0}
47
\definecolor{warningcolor}{rgb}{1, 0, 1}
48
\definecolor{errorcolor}{rgb}{1, 0, 0}
49
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
50
51
\usepackage{alltt}
52
\usepackage[utf8]{inputenc}
53
\usepackage[T1]{fontenc}
54
\usepackage{url}
55
56
57
\title{Knitr in CoCalc}
58
59
\author{Harald Schilly}
60
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
61
\begin{document}
62
63
\maketitle
64
65
You can type R commands in your \LaTeX{} document and they will be properly run and the output printed in the document.
66
67
\begin{knitrout}
68
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
69
\begin{alltt}
70
\hlkwd{library}\hlstd{(knitr)}
71
\hlstd{opts_chunk}\hlopt{$}\hlkwd{set}\hlstd{(}\hlkwc{fig.path}\hlstd{=}\hlstr{'figure/latex-'}\hlstd{,} \hlkwc{cache.path}\hlstd{=}\hlstr{'cache/latex-'}\hlstd{)}
72
\end{alltt}
73
\end{kframe}
74
\end{knitrout}
75
76
\begin{knitrout}
77
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
78
\begin{alltt}
79
\hlstd{R.version}
80
\end{alltt}
81
\begin{verbatim}
82
## _
83
## platform x86_64-pc-linux-gnu
84
## arch x86_64
85
## os linux-gnu
86
## system x86_64, linux-gnu
87
## status
88
## major 3
89
## minor 4.4
90
## year 2018
91
## month 03
92
## day 15
93
## svn rev 74408
94
## language R
95
## version.string R version 3.4.4 (2018-03-15)
96
## nickname Someone to Lean On
97
\end{verbatim}
98
\end{kframe}
99
\end{knitrout}
100
101
\begin{knitrout}
102
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
103
\begin{alltt}
104
\hlstd{ip} \hlkwb{<-} \hlkwd{installed.packages}\hlstd{()}
105
\hlkwd{dim}\hlstd{(ip)}
106
\end{alltt}
107
\begin{verbatim}
108
## [1] 2937 16
109
\end{verbatim}
110
\end{kframe}
111
\end{knitrout}
112
113
\begin{knitrout}
114
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
115
\begin{alltt}
116
\hlcom{# Create a sequence of numbers}
117
\hlstd{X} \hlkwb{=} \hlnum{2}\hlopt{:}\hlnum{10}
118
119
\hlcom{# Display basic statistical measures}
120
\hlkwd{summary}\hlstd{(X)}
121
\end{alltt}
122
\begin{verbatim}
123
## Min. 1st Qu. Median Mean 3rd Qu. Max.
124
## 2 4 6 6 8 10
125
\end{verbatim}
126
\end{kframe}
127
\end{knitrout}
128
129
\begin{knitrout}
130
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
131
\begin{alltt}
132
\hlstd{myF} \hlkwb{<-} \hlkwa{function}\hlstd{(}\hlkwc{x}\hlstd{) \{}
133
\hlkwd{print}\hlstd{(}\hlnum{2}\hlopt{*}\hlstd{x} \hlopt{+} \hlnum{1}\hlstd{)}
134
\hlstd{\}}
135
\hlkwd{myF}\hlstd{(}\hlnum{22}\hlstd{)}
136
\end{alltt}
137
\begin{verbatim}
138
## [1] 45
139
\end{verbatim}
140
\end{kframe}
141
\end{knitrout}
142
143
$$x^y$$
144
145
\begin{knitrout}
146
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
147
\begin{alltt}
148
\hlstd{a} \hlkwb{<-} \hlnum{111}
149
\end{alltt}
150
\end{kframe}
151
\end{knitrout}
152
153
\begin{knitrout}
154
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
155
\begin{alltt}
156
\hlstd{x} \hlkwb{<-} \hlkwd{c}\hlstd{(}\hlnum{2}\hlstd{,}\hlnum{3}\hlstd{,}\hlnum{4}\hlstd{,}\hlnum{5}\hlstd{,}\hlnum{1}\hlstd{,}\hlnum{2}\hlstd{,}\hlnum{3}\hlstd{,}\hlnum{2}\hlstd{)}
157
\hlkwd{summary}\hlstd{(x)}
158
\end{alltt}
159
\begin{verbatim}
160
## Min. 1st Qu. Median Mean 3rd Qu. Max.
161
## 1.00 2.00 2.50 2.75 3.25 5.00
162
\end{verbatim}
163
\end{kframe}
164
\end{knitrout}
165
166
\begin{knitrout}
167
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
168
\begin{alltt}
169
\hlkwd{hist}\hlstd{(x)}
170
\end{alltt}
171
\end{kframe}
172
\includegraphics[width=.75\linewidth]{figure/latex-histogram-plot-1}
173
174
\end{knitrout}
175
176
Sum of 2+3+4+5+1+2+3+2 is 22.
177
178
test
179
180
test 123
181
182
test
183
184
test
185
186
test
187
188
test
189
190
test
191
192
test
193
194
test
195
196
test
197
198
test
199
200
test
201
202
test
203
204
test
205
206
test
207
208
209
210
where am I? here.
211
212
t
213
214
t
215
216
t
217
218
asdf
219
220
t
221
222
t
223
224
t
225
226
t
227
228
t
229
230
t
231
232
t
233
234
t
235
236
t
237
238
t
239
123
240
241
t
242
243
244
this line
245
246
t
247
248
t
249
250
t
251
252
\begin{knitrout}
253
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
254
\begin{alltt}
255
\hlkwd{hist}\hlstd{(x)}
256
\end{alltt}
257
\end{kframe}
258
\includegraphics[width=.4\linewidth]{figure/latex-histogram-plot2-1}
259
260
\end{knitrout}
261
262
t
263
264
t
265
266
t
267
268
ok
269
270
t
271
272
t
273
274
t
275
276
t
277
278
t
279
280
t
281
282
\begin{knitrout}
283
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
284
\begin{alltt}
285
\hlkwd{hist}\hlstd{(x)}
286
\end{alltt}
287
\end{kframe}
288
\includegraphics[width=.4\linewidth]{figure/latex-histogram-plot3-1}
289
290
\end{knitrout}
291
t
292
293
t
294
295
t
296
297
t
298
299
t
300
301
t
302
303
t
304
305
t
306
307
t
308
309
\pagebreak
310
311
\begin{knitrout}
312
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
313
\begin{alltt}
314
\hlstd{data} \hlkwb{<-} \hlkwd{rnorm}\hlstd{(}\hlnum{1000}\hlstd{)}
315
\hlkwd{hist}\hlstd{(data)}
316
\end{alltt}
317
\end{kframe}
318
\includegraphics[width=.9\linewidth]{figure/latex-histogram-plot4-1}
319
320
\end{knitrout}
321
322
0.0588235 and \ensuremath{1.23\times 10^{-6}}.
323
324
EOF
325
326
\end{document}
327
328
329