Skip to content

Commit 48ecf09

Browse files
author
Kasper Peeters
committed
Copy some functionality of Ex to ExNode.
1 parent 5cd5b22 commit 48ecf09

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CADABRA_VERSION_MAJOR 2)
22
set(CADABRA_VERSION_MINOR 4)
33
set(CADABRA_VERSION_PATCH 3)
4-
set(CADABRA_VERSION_TWEAK 4)
4+
set(CADABRA_VERSION_TWEAK 5)
55
set(COPYRIGHT_YEARS "2001-2023")
66
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
77
find_program(GIT git PATHS ${GIT_DIR})

core/ExNode.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "DisplayTeX.hh"
1212
#include "DisplaySympy.hh"
1313
#include "DisplayTerminal.hh"
14+
#include "pythoncdb/py_ex.hh"
1415
#include <sstream>
1516

1617
//#define DEBUG 1
@@ -51,6 +52,17 @@ ExNode ExNode::copy() const
5152
return ret;
5253
}
5354

55+
std::string ExNode::input_form() const
56+
{
57+
// FIXME: this is a duplicate of Ex_as_string; unify the logic.
58+
std::ostringstream str;
59+
60+
DisplayTerminal dt(*get_kernel_from_scope(), get_ex(), false);
61+
dt.output(str);
62+
63+
return str.str();
64+
}
65+
5466
ExNode ExNode::getitem_string(std::string tag)
5567
{
5668
ExNode ret(kernel, ex);

core/ExNode.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class ExNode : public cadabra::IndexClassifier {
4040

4141
std::string __str__() const;
4242
std::string _latex_() const;
43-
43+
std::string input_form() const;
44+
4445
std::string get_name() const;
4546
void set_name(std::string);
4647

core/cadabra2_defaults.py.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ def display(obj, delay_send=False):
269269
else:
270270
server.send(unicode(obj), "plain", 0, False)
271271

272+
elif isinstance(obj, ExNode):
273+
if server.handles('latex_view'):
274+
if delay_send:
275+
return obj._latex_()
276+
else:
277+
ret = mopen+obj._latex_()+mclose
278+
id=server.send(ret, "latex_view", 0, False)
279+
# print(id)
280+
# Make a child cell of the above with input form content.
281+
server.send(obj.input_form(), "input_form", id, False)
282+
else:
283+
server.send(unicode(obj), "plain", 0, False)
284+
272285
elif isinstance(obj, Property):
273286
if server.handles('latex_view'):
274287
ret = mopen+obj._latex_()+mclose

core/pythoncdb/py_ex.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ namespace cadabra {
653653
pybind11::class_<ExNode>(m, "ExNode", "Iterator over elements of an Ex mathematical expression.")
654654
.def("__iter__", &ExNode::iter)
655655
.def("__next__", &ExNode::next, pybind11::return_value_policy::reference_internal)
656+
.def("input_form", &ExNode::input_form)
656657
.def("__getitem__", &ExNode::getitem_string)
657658
.def("__getitem__", &ExNode::getitem_iterator)
658659
.def("__setitem__", &ExNode::setitem_string)

0 commit comments

Comments
 (0)