Skip to content

Commit 8a7ff2b

Browse files
author
Kasper Peeters
committed
Add LaTeXString object to wrap strings which should display typeset with LaTeX on capable frontends.
1 parent 3598aa6 commit 8a7ff2b

File tree

7 files changed

+71
-12
lines changed

7 files changed

+71
-12
lines changed

core/CMakeLists.txt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,19 @@ set(PROPERTY_SRC_FILES
188188
# )
189189

190190
set(MODULE_SRC_FILES
191-
pythoncdb/py_ntensor.cc
192-
pythoncdb/py_algorithms.cc
193-
pythoncdb/py_ex.cc
194-
pythoncdb/py_globals.cc
195-
pythoncdb/py_helpers.cc
196-
pythoncdb/py_kernel.cc
197-
pythoncdb/py_module.cc
198-
pythoncdb/py_packages.cc
199-
pythoncdb/py_progress.cc
200-
pythoncdb/py_properties.cc
201-
pythoncdb/py_stopwatch.cc
202-
pythoncdb/py_tableau.cc
191+
pythoncdb/py_media.cc
192+
pythoncdb/py_ntensor.cc
193+
pythoncdb/py_algorithms.cc
194+
pythoncdb/py_ex.cc
195+
pythoncdb/py_globals.cc
196+
pythoncdb/py_helpers.cc
197+
pythoncdb/py_kernel.cc
198+
pythoncdb/py_module.cc
199+
pythoncdb/py_packages.cc
200+
pythoncdb/py_progress.cc
201+
pythoncdb/py_properties.cc
202+
pythoncdb/py_stopwatch.cc
203+
pythoncdb/py_tableau.cc
203204
)
204205

205206
set(LOCAL_SRC_FILES
@@ -230,6 +231,7 @@ set(LOCAL_SRC_FILES
230231
IndexClassifier.cc
231232
Kernel.cc
232233
Linear.cc
234+
Media.cc
233235
Parser.cc
234236
PreClean.cc
235237
PreProcessor.cc

core/Media.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
#include "Media.hh"
3+
4+
LaTeXString::LaTeXString(const std::string& s)
5+
: content(s)
6+
{
7+
}
8+
9+
std::string LaTeXString::latex() const
10+
{
11+
return content;
12+
}

core/Media.hh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
class LaTeXString {
6+
public:
7+
LaTeXString(const std::string& );
8+
9+
std::string latex() const;
10+
private:
11+
std::string content;
12+
};

core/cadabra2_defaults.py.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ def display(obj, delay_send=False):
282282
else:
283283
server.send(unicode(obj), "plain", 0, False)
284284

285+
elif isinstance(obj, LaTeXString):
286+
if server.handles('latex_view'):
287+
ret = mopen+obj._latex_()+mclose
288+
if delay_send:
289+
return ret
290+
else:
291+
server.send(ret , "latex_view", 0, False)
292+
else:
293+
server.send(unicode(obj), "plain", 0, False)
294+
285295
elif isinstance(obj, Property):
286296
if server.handles('latex_view'):
287297
ret = mopen+obj._latex_()+mclose

core/pythoncdb/py_media.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <pybind11/pybind11.h>
2+
#include "Media.hh"
3+
4+
namespace py = pybind11;
5+
6+
namespace cadabra {
7+
void init_media(py::module& m)
8+
{
9+
py::class_<LaTeXString>(m, "LaTeXString")
10+
.def(py::init<std::string>())
11+
.def("_latex_", &LaTeXString::latex)
12+
;
13+
}
14+
}

core/pythoncdb/py_media.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
namespace cadabra {
4+
5+
void init_media(pybind11::module& m);
6+
7+
}

core/pythoncdb/py_module.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "py_stopwatch.hh"
1111
#include "py_tableau.hh"
1212
#include "py_ntensor.hh"
13+
#include "py_media.hh"
1314

1415
#include "Kernel.hh"
1516

@@ -35,6 +36,7 @@ namespace cadabra {
3536
init_kernel(m);
3637
init_progress_monitor(m);
3738
init_ntensor(m);
39+
init_media(m);
3840
init_stopwatch(m);
3941
init_ex(m);
4042
init_tableau(m);

0 commit comments

Comments
 (0)