質問編集履歴
1
別のソースコードの例
title
CHANGED
File without changes
|
body
CHANGED
@@ -34,4 +34,174 @@
|
|
34
34
|
\inputminted{octave}{kakunin2.m}
|
35
35
|
\caption{Example from external file}
|
36
36
|
\end{listing}
|
37
|
-
%\end{multicols}
|
37
|
+
%\end{multicols}
|
38
|
+
|
39
|
+
似たような?
|
40
|
+
----
|
41
|
+
```
|
42
|
+
\documentclass{article}
|
43
|
+
\usepackage[utf8]{inputenc}
|
44
|
+
\usepackage[english]{babel}
|
45
|
+
|
46
|
+
\usepackage{minted}
|
47
|
+
\usepackage{multicol}
|
48
|
+
\usepackage{xcolor}
|
49
|
+
|
50
|
+
\definecolor{LightGray}{gray}{0.9}
|
51
|
+
%\definecolor{DarkGray}{gray}{0.1}
|
52
|
+
|
53
|
+
%\pagecolor{DarkGray}
|
54
|
+
|
55
|
+
\usemintedstyle{borland}
|
56
|
+
|
57
|
+
%New colors defined below
|
58
|
+
\definecolor{codegreen}{rgb}{0,0.6,0}
|
59
|
+
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
|
60
|
+
\definecolor{codepurple}{rgb}{0.58,0,0.82}
|
61
|
+
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
|
62
|
+
|
63
|
+
\title{Code Listing}
|
64
|
+
\author{someone}
|
65
|
+
\date{ }
|
66
|
+
|
67
|
+
\begin{document}
|
68
|
+
|
69
|
+
\maketitle
|
70
|
+
|
71
|
+
\section{Code examples}
|
72
|
+
|
73
|
+
\begin{listing}[ht]
|
74
|
+
\begin{minted}{python}
|
75
|
+
import numpy as np
|
76
|
+
|
77
|
+
def incmatrix(genl1,genl2):
|
78
|
+
m = len(genl1)
|
79
|
+
n = len(genl2)
|
80
|
+
M = None #to become the incidence matrix
|
81
|
+
VT = np.zeros((n*m,1), int) #dummy variable
|
82
|
+
|
83
|
+
#compute the bitwise xor matrix
|
84
|
+
M1 = bitxormatrix(genl1)
|
85
|
+
M2 = np.triu(bitxormatrix(genl2),1)
|
86
|
+
|
87
|
+
for i in range(m-1):
|
88
|
+
for j in range(i+1, m):
|
89
|
+
[r,c] = np.where(M2 == M1[i,j])
|
90
|
+
for k in range(len(r)):
|
91
|
+
VT[(i)*n + r[k]] = 1;
|
92
|
+
VT[(i)*n + c[k]] = 1;
|
93
|
+
VT[(j)*n + r[k]] = 1;
|
94
|
+
VT[(j)*n + c[k]] = 1;
|
95
|
+
|
96
|
+
if M is None:
|
97
|
+
M = np.copy(VT)
|
98
|
+
else:
|
99
|
+
M = np.concatenate((M, VT), 1)
|
100
|
+
|
101
|
+
VT = np.zeros((n*m,1), int)
|
102
|
+
|
103
|
+
return M
|
104
|
+
\end{minted}
|
105
|
+
\caption{Minimal working example}
|
106
|
+
\label{listing:1}
|
107
|
+
\end{listing}
|
108
|
+
|
109
|
+
\clearpage
|
110
|
+
|
111
|
+
%Python code highlighting
|
112
|
+
\begin{listing}[ht]
|
113
|
+
\begin{minted}
|
114
|
+
[
|
115
|
+
frame=lines,
|
116
|
+
framesep=2mm,
|
117
|
+
baselinestretch=1.2,
|
118
|
+
bgcolor=LightGray,
|
119
|
+
fontsize=\footnotesize,
|
120
|
+
linenos
|
121
|
+
]
|
122
|
+
{python}
|
123
|
+
|
124
|
+
import numpy as np
|
125
|
+
|
126
|
+
def incmatrix(genl1,genl2):
|
127
|
+
m = len(genl1)
|
128
|
+
n = len(genl2)
|
129
|
+
M = None #to become the incidence matrix
|
130
|
+
VT = np.zeros((n*m,1), int) #dummy variable
|
131
|
+
|
132
|
+
#compute the bitwise xor matrix
|
133
|
+
M1 = bitxormatrix(genl1)
|
134
|
+
M2 = np.triu(bitxormatrix(genl2),1)
|
135
|
+
|
136
|
+
for i in range(m-1):
|
137
|
+
for j in range(i+1, m):
|
138
|
+
[r,c] = np.where(M2 == M1[i,j])
|
139
|
+
for k in range(len(r)):
|
140
|
+
VT[(i)*n + r[k]] = 1;
|
141
|
+
VT[(i)*n + c[k]] = 1;
|
142
|
+
VT[(j)*n + r[k]] = 1;
|
143
|
+
VT[(j)*n + c[k]] = 1;
|
144
|
+
|
145
|
+
if M is None:
|
146
|
+
M = np.copy(VT)
|
147
|
+
else:
|
148
|
+
M = np.concatenate((M, VT), 1)
|
149
|
+
|
150
|
+
VT = np.zeros((n*m,1), int)
|
151
|
+
|
152
|
+
return M
|
153
|
+
\end{minted}
|
154
|
+
\caption{Example with line numbers enabled}
|
155
|
+
\end{listing}
|
156
|
+
|
157
|
+
\clearpage
|
158
|
+
|
159
|
+
The next code will be directly imported from a file:
|
160
|
+
|
161
|
+
%Importing code from file
|
162
|
+
%\begin{multicols}{2}
|
163
|
+
\begin{listing}[ht]
|
164
|
+
\inputminted{octave}{BitXorMatrix.m}
|
165
|
+
\caption{Example from external file}
|
166
|
+
\label{listing:3}
|
167
|
+
\end{listing}
|
168
|
+
|
169
|
+
\begin{listing}[ht]
|
170
|
+
\inputminted{octave}{BitXorMatrix.m}
|
171
|
+
\caption{Example from external file}
|
172
|
+
\label{listing:4}
|
173
|
+
\end{listing}
|
174
|
+
%\end{multicols}
|
175
|
+
|
176
|
+
\clearpage
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
\renewcommand\listoflistingscaption{List of source codes}
|
181
|
+
\listoflistings
|
182
|
+
|
183
|
+
\end{document}
|
184
|
+
```
|
185
|
+
```
|
186
|
+
function X = BitXorMatrix(A,B)
|
187
|
+
%function to compute the sum without charge of two vectors
|
188
|
+
|
189
|
+
%convert elements into usigned integers
|
190
|
+
A = uint8(A);
|
191
|
+
B = uint8(B);
|
192
|
+
|
193
|
+
m1 = length(A);
|
194
|
+
m2 = length(B);
|
195
|
+
X = uint8(zeros(m1, m2));
|
196
|
+
for n1=1:m1
|
197
|
+
for n2=1:m2
|
198
|
+
X(n1, n2) = bitxor(A(n1), B(n2));
|
199
|
+
end
|
200
|
+
end
|
201
|
+
```
|
202
|
+
|
203
|
+
上記のソースコード(main.tex , BitXorMatrix.m)
|
204
|
+
---
|
205
|
+
上記のソースコード内のlisting3とlisting4を2段組みにしようとするが消えてしまう。
|
206
|
+
これを2段組みにしたい。
|
207
|
+
%\begin{multicols}{2}と\end{multicols}の%を外す
|