[GiNaC-list] LaTeX Output
Charles White
whitece6 at hawaii.edu
Tue Apr 18 22:38:48 CEST 2023
Hi GiNaC!
I love the library! Keep up the good work!
Currently though I am having trouble with LaTeX output; I would like to
parse an expression, then set the LaTeX name to the symbols that were
generated from the reader. I can do that, but the expression doesn't change
when I print it. Here is an minimal example:
#include <ginac/ginac.h>
std::string addTeXbrackets(std::string const& in)
{
std::string ret = in;
std::string::size_type pos = 0;
while((pos = ret.find('_', pos)) != std::string::npos)
{
ret.replace(pos, 1, "_{");
pos += 1; // move past the dot (and the extra '\n')
ret.push_back('}');
}
return ret;
}
int main(){
GiNaC::parser reader;
GiNaC::ex e = reader("2*x_1+sin(y_2)");
GiNaC::symtab & vars = reader.get_syms();
std::cout << GiNaC::latex;
for (std::pair<std::string, GiNaC::ex> var : vars) {
// loop through each symbol then texify and use "set_TeX_name()"
GiNaC::ex_to<GiNaC::symbol
&>(var.second).set_TeX_name(addTeXbrackets(var.first));
std::cout<<var.second<<std::endl;
} //<- Not sure how to add latex to the output yet
std::cout<<e<<std::endl;
}
//output is:
x_{1}
y_{2}
2 x_1+\sin(y_2)
Thanks!
Charles
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.ginac.de/pipermail/ginac-list/attachments/20230418/8129593b/attachment.htm>
More information about the GiNaC-list
mailing list