Skip to content

Commit f38216b

Browse files
author
Kasper Peeters
committed
Merge branch 'rev_lookup' of https://github.com/cbehan/cadabra2 into cbehan-rev_lookup
2 parents 08a1590 + b26a25e commit f38216b

File tree

6 files changed

+71
-111
lines changed

6 files changed

+71
-111
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/Parser.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ You should have received a copy of the GNU General Public License
2020

2121
#include "Parser.hh"
2222
#include "PreProcessor.hh"
23+
#include "Symbols.hh"
2324

2425
#include <sstream>
2526
#include <internal/uniconv.h>
@@ -178,6 +179,17 @@ bool Parser::string2tree(const std::string& inp)
178179
ss2 << pp;
179180
std::string str8=" "+ss2.str()+" "; // for lookahead
180181

182+
#ifdef DEBUG
183+
std::cout << "converting Greek unicode to TeX" << std::endl;
184+
#endif
185+
for (auto const& c : cadabra::symbols::greekmap) {
186+
size_t pos1 = 0;
187+
size_t pos2;
188+
while ((pos2 = str8.find(c.second, pos1)) != std::string::npos) {
189+
str8.replace(pos2, c.second.length(), c.first);
190+
pos1 = pos2 + c.first.length();
191+
}
192+
}
181193
#ifdef DEBUG
182194
std::cout << "converting to utf32" << std::endl;
183195
#endif

core/Symbols.cc

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,55 @@
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-
};
5+
const std::map<std::string, std::string> cadabra::symbols::greekmap {
6+
{"\\alpha", "α" },
7+
{"\\beta", "β" }, // beta seems to be reserved
8+
{"\\gamma", "γ" }, // gamma seems to be reserved
9+
{"\\delta", "δ" },
10+
{"\\epsilon", "ε" },
11+
{"\\zeta", "ζ" },
12+
{"\\eta", "η" },
13+
{"\\theta", "θ" },
14+
{"\\iota", "ι" },
15+
{"\\kappa", "κ" },
16+
{"\\lambda", "λ" }, // lambda is reserved
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", "ω" },
5631

32+
{"\\Alpha", "Α" },
33+
{"\\Beta", "Β" },
34+
{"\\Gamma", "Γ" },
35+
{"\\Delta", "Δ" },
36+
{"\\Epsilon", "Ε" },
37+
{"\\Zeta", "Ζ" },
38+
{"\\Eta", "Η" },
39+
{"\\Theta", "ϴ" },
40+
{"\\Iota", "Ι" },
41+
{"\\Kappa", "Κ" },
42+
{"\\Lambda", "Λ" },
43+
{"\\Mu", "Μ" },
44+
{"\\Nu", "Ν" },
45+
{"\\Xi", "Ξ" },
46+
{"\\Omicron", "Ο" },
47+
{"\\Pi", "Π" },
48+
{"\\Rho", "Ρ" },
49+
{"\\Sigma", "Σ" },
50+
{"\\Tau", "Τ" },
51+
{"\\Upsilon", "Υ" },
52+
{"\\Phi", "Φ" },
53+
{"\\Chi", "Χ" },
54+
{"\\Psi", "Ψ" },
55+
{"\\Omega", "Ω" },
56+
};

core/Symbols.hh

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

22
#pragma once
33

4-
#include <set>
4+
#include <map>
55
#include <string>
66

77
namespace cadabra {
88
namespace symbols {
9-
extern const std::set<std::string> greek;
9+
extern const std::map<std::string, std::string> greekmap;
1010
}
1111
}

0 commit comments

Comments
 (0)