diff --git a/webui/src/interfaces/NodeOutputs.ts b/webui/src/interfaces/NodeOutputs.ts index b1f73d9872c53d37d91fa87cba8a7d58a0e2fcbc..8d6a656f629b08eeceb8f88c850d576b71f3616a 100644 --- a/webui/src/interfaces/NodeOutputs.ts +++ b/webui/src/interfaces/NodeOutputs.ts @@ -2,6 +2,7 @@ export interface StringNodeOutput { plain?: string, pretty?: string, dot?: string, + latex?: string, } export interface NodeOutputs { diff --git a/worker/src/evaluator/evaluator.cpp b/worker/src/evaluator/evaluator.cpp index c69fea5ed6b578138c07a762ed7ea9d4f219fa5d..66148ff5ddaf625a304539d09a18ae07599ed642 100644 --- a/worker/src/evaluator/evaluator.cpp +++ b/worker/src/evaluator/evaluator.cpp @@ -35,6 +35,10 @@ Json::Value replyOutputs(const AlgorithmGraph::EvaluatedGraph& eval) outputsJson[nodeId]["result"]["dot"] = output; } + for (const auto& [nodeId, output] : eval.latexOutputs) { + outputsJson[nodeId]["result"]["latex"] = output; + } + for (const auto& [nodeId, outputType] : eval.types) { outputsJson[nodeId]["type"] = outputType; } diff --git a/worker/src/evaluator/graph/AlgorithmGraph.cpp b/worker/src/evaluator/graph/AlgorithmGraph.cpp index 340e2ee4132065bf0b6704df65f837ef26ab67c9..92d9041cd6ff6c460b49bb29c845de0ec24e49b3 100644 --- a/worker/src/evaluator/graph/AlgorithmGraph.cpp +++ b/worker/src/evaluator/graph/AlgorithmGraph.cpp @@ -34,6 +34,7 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate() std::map<std::string, std::string> outputs; std::map<std::string, std::string> prettyOutputs; std::map<std::string, std::string> dotOutputs; + std::map<std::string, std::string> latexOutputs; std::map<std::string, std::string> resultTypes; cli::Environment environment; @@ -61,10 +62,14 @@ AlgorithmGraph::EvaluatedGraph AlgorithmGraph::evaluate() dotOutputs[node->getId()] = std::move(*nodeRes); } + if (auto nodeRes = node->getResultLatex()) { + latexOutputs[node->getId()] = std::move(*nodeRes); + } + if (auto nodeType = node->getResultType()) { resultTypes[node->getId()] = ext::to_string(nodeType); } } - return {outputs, prettyOutputs, dotOutputs, resultTypes}; + return {outputs, prettyOutputs, dotOutputs, latexOutputs, resultTypes}; } diff --git a/worker/src/evaluator/graph/AlgorithmGraph.hpp b/worker/src/evaluator/graph/AlgorithmGraph.hpp index 9c627c6ab7bd3ab41bb2c629ab17f6127239d276..de932d99d403e7be69e3c86a5b30bb1b77b84a8e 100644 --- a/worker/src/evaluator/graph/AlgorithmGraph.hpp +++ b/worker/src/evaluator/graph/AlgorithmGraph.hpp @@ -14,6 +14,7 @@ public: std::map<std::string, std::string> outputs; std::map<std::string, std::string> prettyOutputs; std::map<std::string, std::string> dotOutputs; + std::map<std::string, std::string> latexOutputs; std::map<std::string, std::string> types; }; diff --git a/worker/src/evaluator/graph/nodes/AbstractNode.hpp b/worker/src/evaluator/graph/nodes/AbstractNode.hpp index bbbd062c6b6f6f1e76a6bbd90e15d9e528441d9f..c64b1bfe605e9fcb7542260c42d2311554c7592f 100644 --- a/worker/src/evaluator/graph/nodes/AbstractNode.hpp +++ b/worker/src/evaluator/graph/nodes/AbstractNode.hpp @@ -82,6 +82,12 @@ public: */ virtual std::optional<std::string> getResultDot() { return std::nullopt; } + /** + * Returns the result of the node printed with convert::LatexConverter + * @return std::optional result of evaluation + */ + virtual std::optional<std::string> getResultLatex() { return std::nullopt; } + /** * Returns the type of the result of the algorithm node or std::nullopt for other nodes. * @see core::type_details diff --git a/worker/src/evaluator/graph/nodes/OutputNode.cpp b/worker/src/evaluator/graph/nodes/OutputNode.cpp index a328c77ee1c14f182550e311023bc979c288e4dd..0bb531f8c91d11dc5c260294c643aaeaa3ac9ad1 100644 --- a/worker/src/evaluator/graph/nodes/OutputNode.cpp +++ b/worker/src/evaluator/graph/nodes/OutputNode.cpp @@ -37,6 +37,11 @@ std::optional<std::string> OutputNode::getResultDot() return resultDot; } +std::optional<std::string> OutputNode::getResultLatex() +{ + return resultLatex; +} + std::optional<core::type_details> OutputNode::getResultType() { return resultType; @@ -58,4 +63,10 @@ void OutputNode::evaluate(abstraction::TemporariesHolder& environment) resultDot = utils::trim(abstractValueToString(composeValue)); } catch (...) { } + + try { + auto composeValue = abstraction::EvalHelper::evalAlgorithm(environment, "convert::LatexConverter", {}, {params[0]}, abstraction::AlgorithmCategories::AlgorithmCategory::NONE); + resultLatex = utils::trim(abstractValueToString(composeValue)); + } catch (...) { + } } diff --git a/worker/src/evaluator/graph/nodes/OutputNode.hpp b/worker/src/evaluator/graph/nodes/OutputNode.hpp index b43d6447242c22d50cf7456597164287a6b6d1fc..7412ad3b2581261a3082dbb960bcb8574646974b 100644 --- a/worker/src/evaluator/graph/nodes/OutputNode.hpp +++ b/worker/src/evaluator/graph/nodes/OutputNode.hpp @@ -25,6 +25,8 @@ public: std::optional<std::string> getResultDot() override; + std::optional<std::string> getResultLatex() override; + /** * Returns result type of the input */ @@ -40,4 +42,5 @@ protected: std::optional<core::type_details> resultType; // FIXME: core::type_details doesn't have an 0-param constructor so it is uninitialized until the actual evaluation takes place std::optional<std::string> resultCompose; std::optional<std::string> resultDot; + std::optional<std::string> resultLatex; };