質問編集履歴
1
別のソースコードの例
test
CHANGED
File without changes
|
test
CHANGED
@@ -71,3 +71,343 @@
|
|
71
71
|
\end{listing}
|
72
72
|
|
73
73
|
%\end{multicols}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
似たような?
|
78
|
+
|
79
|
+
----
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
\documentclass{article}
|
84
|
+
|
85
|
+
\usepackage[utf8]{inputenc}
|
86
|
+
|
87
|
+
\usepackage[english]{babel}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
\usepackage{minted}
|
92
|
+
|
93
|
+
\usepackage{multicol}
|
94
|
+
|
95
|
+
\usepackage{xcolor}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
\definecolor{LightGray}{gray}{0.9}
|
100
|
+
|
101
|
+
%\definecolor{DarkGray}{gray}{0.1}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
%\pagecolor{DarkGray}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
\usemintedstyle{borland}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
%New colors defined below
|
114
|
+
|
115
|
+
\definecolor{codegreen}{rgb}{0,0.6,0}
|
116
|
+
|
117
|
+
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
|
118
|
+
|
119
|
+
\definecolor{codepurple}{rgb}{0.58,0,0.82}
|
120
|
+
|
121
|
+
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
\title{Code Listing}
|
126
|
+
|
127
|
+
\author{someone}
|
128
|
+
|
129
|
+
\date{ }
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
\begin{document}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
\maketitle
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
\section{Code examples}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
\begin{listing}[ht]
|
146
|
+
|
147
|
+
\begin{minted}{python}
|
148
|
+
|
149
|
+
import numpy as np
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
def incmatrix(genl1,genl2):
|
154
|
+
|
155
|
+
m = len(genl1)
|
156
|
+
|
157
|
+
n = len(genl2)
|
158
|
+
|
159
|
+
M = None #to become the incidence matrix
|
160
|
+
|
161
|
+
VT = np.zeros((n*m,1), int) #dummy variable
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
#compute the bitwise xor matrix
|
166
|
+
|
167
|
+
M1 = bitxormatrix(genl1)
|
168
|
+
|
169
|
+
M2 = np.triu(bitxormatrix(genl2),1)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
for i in range(m-1):
|
174
|
+
|
175
|
+
for j in range(i+1, m):
|
176
|
+
|
177
|
+
[r,c] = np.where(M2 == M1[i,j])
|
178
|
+
|
179
|
+
for k in range(len(r)):
|
180
|
+
|
181
|
+
VT[(i)*n + r[k]] = 1;
|
182
|
+
|
183
|
+
VT[(i)*n + c[k]] = 1;
|
184
|
+
|
185
|
+
VT[(j)*n + r[k]] = 1;
|
186
|
+
|
187
|
+
VT[(j)*n + c[k]] = 1;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
if M is None:
|
192
|
+
|
193
|
+
M = np.copy(VT)
|
194
|
+
|
195
|
+
else:
|
196
|
+
|
197
|
+
M = np.concatenate((M, VT), 1)
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
VT = np.zeros((n*m,1), int)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
return M
|
206
|
+
|
207
|
+
\end{minted}
|
208
|
+
|
209
|
+
\caption{Minimal working example}
|
210
|
+
|
211
|
+
\label{listing:1}
|
212
|
+
|
213
|
+
\end{listing}
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
\clearpage
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
%Python code highlighting
|
222
|
+
|
223
|
+
\begin{listing}[ht]
|
224
|
+
|
225
|
+
\begin{minted}
|
226
|
+
|
227
|
+
[
|
228
|
+
|
229
|
+
frame=lines,
|
230
|
+
|
231
|
+
framesep=2mm,
|
232
|
+
|
233
|
+
baselinestretch=1.2,
|
234
|
+
|
235
|
+
bgcolor=LightGray,
|
236
|
+
|
237
|
+
fontsize=\footnotesize,
|
238
|
+
|
239
|
+
linenos
|
240
|
+
|
241
|
+
]
|
242
|
+
|
243
|
+
{python}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
import numpy as np
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
def incmatrix(genl1,genl2):
|
252
|
+
|
253
|
+
m = len(genl1)
|
254
|
+
|
255
|
+
n = len(genl2)
|
256
|
+
|
257
|
+
M = None #to become the incidence matrix
|
258
|
+
|
259
|
+
VT = np.zeros((n*m,1), int) #dummy variable
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
#compute the bitwise xor matrix
|
264
|
+
|
265
|
+
M1 = bitxormatrix(genl1)
|
266
|
+
|
267
|
+
M2 = np.triu(bitxormatrix(genl2),1)
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
for i in range(m-1):
|
272
|
+
|
273
|
+
for j in range(i+1, m):
|
274
|
+
|
275
|
+
[r,c] = np.where(M2 == M1[i,j])
|
276
|
+
|
277
|
+
for k in range(len(r)):
|
278
|
+
|
279
|
+
VT[(i)*n + r[k]] = 1;
|
280
|
+
|
281
|
+
VT[(i)*n + c[k]] = 1;
|
282
|
+
|
283
|
+
VT[(j)*n + r[k]] = 1;
|
284
|
+
|
285
|
+
VT[(j)*n + c[k]] = 1;
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
if M is None:
|
290
|
+
|
291
|
+
M = np.copy(VT)
|
292
|
+
|
293
|
+
else:
|
294
|
+
|
295
|
+
M = np.concatenate((M, VT), 1)
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
VT = np.zeros((n*m,1), int)
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
return M
|
304
|
+
|
305
|
+
\end{minted}
|
306
|
+
|
307
|
+
\caption{Example with line numbers enabled}
|
308
|
+
|
309
|
+
\end{listing}
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
\clearpage
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
The next code will be directly imported from a file:
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
%Importing code from file
|
322
|
+
|
323
|
+
%\begin{multicols}{2}
|
324
|
+
|
325
|
+
\begin{listing}[ht]
|
326
|
+
|
327
|
+
\inputminted{octave}{BitXorMatrix.m}
|
328
|
+
|
329
|
+
\caption{Example from external file}
|
330
|
+
|
331
|
+
\label{listing:3}
|
332
|
+
|
333
|
+
\end{listing}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
\begin{listing}[ht]
|
338
|
+
|
339
|
+
\inputminted{octave}{BitXorMatrix.m}
|
340
|
+
|
341
|
+
\caption{Example from external file}
|
342
|
+
|
343
|
+
\label{listing:4}
|
344
|
+
|
345
|
+
\end{listing}
|
346
|
+
|
347
|
+
%\end{multicols}
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
\clearpage
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
\renewcommand\listoflistingscaption{List of source codes}
|
360
|
+
|
361
|
+
\listoflistings
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
\end{document}
|
366
|
+
|
367
|
+
```
|
368
|
+
|
369
|
+
```
|
370
|
+
|
371
|
+
function X = BitXorMatrix(A,B)
|
372
|
+
|
373
|
+
%function to compute the sum without charge of two vectors
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
%convert elements into usigned integers
|
378
|
+
|
379
|
+
A = uint8(A);
|
380
|
+
|
381
|
+
B = uint8(B);
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
m1 = length(A);
|
386
|
+
|
387
|
+
m2 = length(B);
|
388
|
+
|
389
|
+
X = uint8(zeros(m1, m2));
|
390
|
+
|
391
|
+
for n1=1:m1
|
392
|
+
|
393
|
+
for n2=1:m2
|
394
|
+
|
395
|
+
X(n1, n2) = bitxor(A(n1), B(n2));
|
396
|
+
|
397
|
+
end
|
398
|
+
|
399
|
+
end
|
400
|
+
|
401
|
+
```
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
上記のソースコード(main.tex , BitXorMatrix.m)
|
406
|
+
|
407
|
+
---
|
408
|
+
|
409
|
+
上記のソースコード内のlisting3とlisting4を2段組みにしようとするが消えてしまう。
|
410
|
+
|
411
|
+
これを2段組みにしたい。
|
412
|
+
|
413
|
+
%\begin{multicols}{2}と\end{multicols}の%を外す
|