Skip to content

Commit b26a25e

Browse files
committed
Consolidate Greek character searches
Searching for keys in a map is just like searching for elements in a set so we can have everything use the same list of Greek characters. Signed-off-by: Connor Behan <[email protected]>
1 parent 8c98d09 commit b26a25e

File tree

5 files changed

+6
-112
lines changed

5 files changed

+6
-112
lines changed

core/DisplayTeX.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ bool DisplayTeX::reads_as_operator(Ex::iterator obj, Ex::iterator arg) const
101101
// FIXME: this needs fine-tuning; there are more cases where
102102
// no brackets are needed.
103103
const LaTeXForm *lf = kernel.properties.get<LaTeXForm>(arg);
104-
if((*arg->name).size()==1 || lf || cadabra::symbols::greek.find(*arg->name)!=cadabra::symbols::greek.end()) return true;
104+
if((*arg->name).size()==1 || lf || cadabra::symbols::greekmap.find(*arg->name)!=cadabra::symbols::greekmap.end()) return true;
105105
}
106106

107107
if(*obj->name=="\\cos" || *obj->name=="\\sin" || *obj->name=="\\tan" || *obj->name=="\\exp") {
108108
const LaTeXForm *lf = kernel.properties.get<LaTeXForm>(arg);
109109
if(*arg->multiplier==1)
110-
if((*arg->name).size()==1 || lf || cadabra::symbols::greek.find(*arg->name)!=cadabra::symbols::greek.end()) return true;
110+
if((*arg->name).size()==1 || lf || cadabra::symbols::greekmap.find(*arg->name)!=cadabra::symbols::greekmap.end()) return true;
111111
}
112112

113113
auto it=curly_bracket_operators.find(*obj->name);

core/DisplayTerminal.cc

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#include "Algorithm.hh"
33
#include "DisplayTerminal.hh"
4+
#include "Symbols.hh"
45
#include "properties/Accent.hh"
56

67
using namespace cadabra;
@@ -18,59 +19,6 @@ DisplayTerminal::DisplayTerminal(const Kernel& k, const Ex& e, bool uuc)
1819
{"\\int", "" },
1920
{"\\sum", "" }
2021
};
21-
22-
greekmap = {
23-
{"\\alpha", "α" },
24-
{"\\beta", "β" }, // beta seems to be reserved
25-
{"\\gamma", "γ" }, // gamma seems to be reserved
26-
{"\\delta", "δ" },
27-
{"\\epsilon", "ε" },
28-
{"\\zeta", "ζ" },
29-
{"\\eta", "η" },
30-
{"\\theta", "θ" },
31-
{"\\iota", "ι" },
32-
{"\\kappa", "κ" },
33-
{"\\lambda", "λ" }, // lambda is reserved
34-
{"\\mu", "μ" },
35-
{"\\nu", "ν" },
36-
{"\\xi", "ξ" },
37-
{"\\omicron", "ο" },
38-
{"\\pi", "π" },
39-
{"\\rho", "ρ" },
40-
{"\\sigma", "σ" },
41-
{"\\tau", "τ" },
42-
{"\\upsilon", "υ" },
43-
{"\\phi", "φ" },
44-
{"\\chi", "χ" },
45-
{"\\psi", "ψ" },
46-
{"\\omega", "ω" },
47-
48-
{"\\Alpha", "Α" },
49-
{"\\Beta", "Β" },
50-
{"\\Gamma", "Γ" },
51-
{"\\Delta", "Δ" },
52-
{"\\Epsilon", "Ε" },
53-
{"\\Zeta", "Ζ" },
54-
{"\\Eta", "Η" },
55-
{"\\Theta", "ϴ" },
56-
{"\\Iota", "Ι" },
57-
{"\\Kappa", "Κ" },
58-
{"\\Lambda", "Λ" },
59-
{"\\Mu", "Μ" },
60-
{"\\Nu", "Ν" },
61-
{"\\Xi", "Ξ" },
62-
{"\\Omicron", "Ο" },
63-
{"\\Pi", "Π" },
64-
{"\\Rho", "Ρ" },
65-
{"\\Sigma", "Σ" },
66-
{"\\Tau", "Τ" },
67-
{"\\Upsilon", "Υ" },
68-
{"\\Phi", "Φ" },
69-
{"\\Chi", "Χ" },
70-
{"\\Psi", "Ψ" },
71-
{"\\Omega", "Ω" },
72-
73-
};
7422
}
7523

7624
// Logic: each node should check whether it needs to have brackets printed around
@@ -665,8 +613,8 @@ void DisplayTerminal::print_other(std::ostream& str, Ex::iterator it)
665613
auto rn1 = symmap.find(sbit);
666614
if(rn1!=symmap.end())
667615
sbit = rn1->second;
668-
auto rn = greekmap.find(sbit);
669-
if(rn!=greekmap.end())
616+
auto rn = cadabra::symbols::greekmap.find(sbit);
617+
if(rn!=cadabra::symbols::greekmap.end())
670618
sbit = rn->second;
671619
}
672620
str << sbit;

core/DisplayTerminal.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace cadabra {
6666

6767
bool children_have_brackets(Ex::iterator ch) const;
6868

69-
std::map<std::string, std::string> symmap, greekmap;
69+
std::map<std::string, std::string> symmap;
7070
};
7171

7272
const char *unichar(kunichar c);

core/Symbols.cc

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,6 @@
22
#include "Symbols.hh"
33

44

5-
const std::set<std::string> cadabra::symbols::greek {
6-
"\\alpha",
7-
"\\beta",
8-
"\\gamma",
9-
"\\delta",
10-
"\\epsilon",
11-
"\\zeta",
12-
"\\eta",
13-
"\\theta",
14-
"\\iota",
15-
"\\kappa",
16-
"\\lambda",
17-
"\\mu",
18-
"\\nu",
19-
"\\xi",
20-
"\\omicron",
21-
"\\pi",
22-
"\\rho",
23-
"\\sigma",
24-
"\\tau",
25-
"\\upsilon",
26-
"\\phi",
27-
"\\varphi",
28-
"\\chi",
29-
"\\psi",
30-
"\\omega",
31-
"\\Alpha",
32-
"\\Beta",
33-
"\\Gamma",
34-
"\\Delta",
35-
"\\Epsilon",
36-
"\\Zeta",
37-
"\\Eta",
38-
"\\Theta",
39-
"\\Iota",
40-
"\\Kappa",
41-
"\\Lambda",
42-
"\\Mu",
43-
"\\Nu",
44-
"\\Xi",
45-
"\\Omicron",
46-
"\\Pi",
47-
"\\Rho",
48-
"\\Sigma",
49-
"\\Tau",
50-
"\\Upsilon",
51-
"\\Phi",
52-
"\\Chi",
53-
"\\Psi",
54-
"\\Omega"
55-
};
56-
575
const std::map<std::string, std::string> cadabra::symbols::greekmap {
586
{"\\alpha", "α" },
597
{"\\beta", "β" }, // beta seems to be reserved

core/Symbols.hh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11

22
#pragma once
33

4-
#include <set>
54
#include <map>
65
#include <string>
76

87
namespace cadabra {
98
namespace symbols {
10-
extern const std::set<std::string> greek;
119
extern const std::map<std::string, std::string> greekmap;
1210
}
1311
}

0 commit comments

Comments
 (0)