-
Notifications
You must be signed in to change notification settings - Fork 2
/
doc.fs
297 lines (259 loc) · 10.2 KB
/
doc.fs
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
(*
Copyright (c) 2022 Jun-ichiro Sugisaka
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*)
namespace Aqualis
open Aqualis_base
type eqmode() =
///<summary>改行</summary>
member _.eqReturn() =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\\\")
|_ ->
()
///<summary>数式番号なし</summary>
member _.eqNonumber() =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\nonumber")
|_ ->
()
///<summary>改行</summary>
member _.eqLabel(lb:string) =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\label{"+lb+"}")
|_ ->
()
///<summary>数式番号なし改行</summary>
member this.nnReturn() =
this.eqNonumber()
this.eqReturn()
///<summary>空白の左辺</summary>
member _.nl with get() = Var(Zt,"")
///<summary>変数宣言</summary>
type doc () =
///<summary>段落</summary>
static member para code =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\par")
code()
|_ ->
code()
///<summary>テキスト</summary>
static member text (s:string) =
let q = p.param
match p.lang with
|T ->
q.codewrite(s)
|_ ->
! s
///<summary>図の挿入</summary>
static member inputfigure (filename:string) (caption:string) =
let q = p.param
p.incld("\\usepackage{graphicx}")
match p.lang with
|T ->
q.codewrite("\\begin{figure}[htbp]")
q.codewrite("\\begin{center}")
q.codewrite("\\includegraphics{"+filename+"}")
q.codewrite("\\end{center}")
q.codewrite("\\caption{"+caption+"}")
q.codewrite("\\label{"+filename+"}")
q.codewrite("\\end{figure}")
|_ ->
! (filename+": "+caption)
///<summary>番号付き箇条書き</summary>
static member enumerate (slst:(unit->unit)list) =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\begin{enumerate}")
for s in slst do
q.codewrite("\\item")
s()
q.codewrite("\\end{enumerate}")
|_ ->
for s in slst do
s()
///<summary>番号なし箇条書き</summary>
static member itemize (slst:(unit->unit)list) =
let q = p.param
match p.lang with
|T ->
q.codewrite("\\begin{itemize}")
for s in slst do
q.codewrite("\\item")
s()
q.codewrite("\\end{itemize}")
|_ ->
for s in slst do
s()
///<summary>数式</summary>
static member eq code =
let q = p.param
let e = eqmode()
match p.lang with
|T ->
AqualisCompiler.set_EquationSimplify OFF
q.codewrite("\\begin{align}")
code e
q.codewrite("\\end{align}")
AqualisCompiler.set_EquationSimplify ON
|H ->
AqualisCompiler.set_EquationSimplify OFF
q.codewrite("\\[")
q.codewrite("\\begin{align}")
code e
q.codewrite("\\end{align}")
q.codewrite("\\]")
AqualisCompiler.set_EquationSimplify ON
|_ ->
code e
///<summary>変数(変数リストに追加しない)</summary>
static member var (tp,name:string) =
Var(tp,name)
///<summary>単独の数式</summary>
static member f (a:num0) = a.code
///<summary>単独の数式</summary>
static member f (a:bool0) = a.code
///<summary>単独の数式(インライン)</summary>
static member fi (a:num0) = "$"+a.code+"$"
///<summary>単独の数式(インライン)</summary>
static member fi (a:bool0) = "$"+a.code+"$"
///<summary>総和</summary>
static member sum (a:num0,i:num0) = fun (b:num0) (c:num0) ->
match p.lang with
|T ->
p.param.frac_style <- 1
let ta = a.code
let ti = i.code
p.param.frac_style <- 0
let tb = b.code
let tc = c.code
Var(c.etype,"\\sum_{"+ta+"="+ti+"}^{"+tb+"} "+tc)
|_ ->
NaN
///<summary>総和</summary>
static member sum (a:num0,i:int) = fun (b:num0) (c:num0) ->
doc.sum (a,i.I) b c
///<summary>総和</summary>
static member sum (a:num0) = fun (b:num0) (c:num0) ->
match p.lang with
|T ->
p.param.frac_style <- 1
let ta = a.code
p.param.frac_style <- 0
let tb = b.code
let tc = c.code
Var(c.etype,"\\sum_{"+ta+"}^{"+tb+"} "+tc)
|_ ->
NaN
///<summary>積分</summary>
static member integral (a:num0,b:num0) = fun (eq:num0) (x:num0) ->
match p.lang with
|T ->
p.param.frac_style <- 1
let ta = a.code
let tb = b.code
p.param.frac_style <- 0
let te = eq.code
let tx = x.code
Var(x.etype,"\\int_{"+ta+"}^{"+tb+"} "+te+"\\mathrm{d}"+tx)
|_ ->
NaN
///<summary>積分</summary>
static member integral (a:int,b:num0) = fun (eq:num0) (x:num0) ->
doc.integral (a.I,b) eq x
///<summary>積分</summary>
static member integral (a:num0,b:int) = fun (eq:num0) (x:num0) ->
doc.integral (a,b.I) eq x
///<summary>積分</summary>
static member integral (a:int,b:int) = fun (eq:num0) (x:num0) ->
doc.integral (a.I,b.I) eq x
///<summary>微分</summary>
static member diff (f:num0) (x:num0) =
match p.lang with
|T ->
let tf = f.code
let tx = x.code
Var(f.etype,"\\frac{\\mathrm{d}"+tf+"}^{\\mathrm{d}"+tx+"}")
|_ ->
NaN
///<summary>偏微分</summary>
static member pdiff (f:num0) (x:num0) =
match p.lang with
|T ->
let tf = f.code
let tx = x.code
Var(f.etype,"\\frac{\\partial "+tf+"}^{\\partial "+tx+"}")
|_ ->
NaN
///<summary>場合分け</summary>
static member cases (lst:(num0*string)list) =
let q = p.param
match p.lang with
|T ->
let c =
[0..lst.Length-1]
|> List.fold (fun acc i ->
let (f,x) = lst[i]
let tf = f.code
(acc+tf+" & \\left("+x+"\\right)"+(if i=lst.Length-1 then "" else "\\\\")+"\n")) ""
Var(Nt,"\\begin{dcases}"+"\n"+c+"\\end{dcases}")
|_ ->
NaN
///<summary>場合分け</summary>
static member cases (lst:(num0*num0)list) =
let q = p.param
match p.lang with
|T ->
let c =
[0..lst.Length-1]
|> List.fold (fun acc i ->
let (f,x) = lst[i]
let tf = f.code
let tx = x.code
(acc+tf+" & "+tx+(if i=lst.Length-1 then "" else "\\\\"))+"\n") ""
Var(Nt,"\\begin{dcases}"+"\n"+c+"\\end{dcases}")
|_ ->
NaN
///<summary>場合分け</summary>
static member cases (lst:(num0*bool0)list) =
let q = p.param
match p.lang with
|T ->
let c =
[0..lst.Length-1]
|> List.fold (fun acc i ->
let (f,x) = lst[i]
let tf = f.code
let tx = x.code
(acc+tf+" & \\left("+tx+"\\right)"+(if i=lst.Length-1 then "" else "\\\\")+"\n")) ""
Var(Nt,"\\begin{dcases}"+"\n"+c+"\\end{dcases}")
|_ ->
NaN
///<summary>括弧「()」</summary>
static member par1 (v:num0) = Par(v.etype,"\\left(","\\right)",v)
///<summary>括弧「[]」</summary>
static member par2 (v:num0) = Par(v.etype,"\\left[","\\right]",v)
///<summary>括弧「[]」+下付き・上付き文字</summary>
static member par2 (v:num0,a:num0,b:num0) = Par(v.etype,"\\left[","\\right]_{"+a.code+"}^{"+b.code+"}",v)
///<summary>括弧「[]」+下付き・上付き文字</summary>
static member par2 (v:num0,a:int,b:num0) =
doc.par2 (v,I a,b)
///<summary>括弧「[]」+下付き・上付き文字</summary>
static member par2 (v:num0,a:num0,b:int) =
doc.par2 (v,a,I b)
///<summary>括弧「[]」+下付き・上付き文字</summary>
static member par2 (v:num0,a:int,b:int) =
doc.par2 (v,I a,I b)
///<summary>括弧「{}」</summary>
static member par3 (v:num0) = Par(v.etype,"\\left\\{","\\right\\}",v)