annotate Paper/escape_agda.rb @ 0:c59202657321

init
author soto <soto@cr.ie.u-ryukyu.ac.jp>
date Tue, 02 Nov 2021 06:55:58 +0900
parents
children 9176dff8f38a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #!/usr/bin/env ruby
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 # coding: utf-8
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 Suffix = '.agda.replaced'
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 EscapeChar = '@'
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 FileName = ARGV.first
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 ReplaceTable = {
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 '→' => 'rightarrow',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 '->' => 'rightarrow',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 '⊔' => 'sqcup',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 '∷' => 'text{::}',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 '∙' => 'circ',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 '≡' => 'equiv',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 '×' => 'times',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 '⟨' => 'langle',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 '⟩' => 'rangle',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 'ℕ' => 'mathbb{N}',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 '₁' => '_{1}',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 '₂' => '_{2}',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 '∎' => 'blacksquare',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 'λ' => 'lambda',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 '∧' => 'wedge',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 '/\\' => 'wedge',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 '⇒' => 'Rightarrow',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 '¬' => 'neg',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 '≤' => 'leq',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 '⊥' => 'bot',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 '∀' => 'forall',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 '#' => '\#',
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 '⊤' => '\top'
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 }
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 code = File.read(FileName)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ReplaceTable.each do |k, v|
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 escaped_str = EscapeChar + "$\\#{v}$" + EscapeChar
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 code = code.gsub(k, escaped_str)
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 end
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
soto <soto@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 File.write(FileName.sub(/.agda$/, Suffix), code)