jupyter-xeus / xeus-octave

Jupyter kernel for GNU Octave
https://xeus-octave.readthedocs.io/
GNU General Public License v3.0
57 stars 10 forks source link

Error rendering latex of matrices assigned using eval with displayformat matrix latex #114

Open cjwomack opened 8 months ago

cjwomack commented 8 months ago

Description

I wanted to reduce repeated code by sprintf and eval in conjunction with a for loop. However, matrices do not render properly and show raw latex code. I suspect this is because I used eval and perhaps this use case was not thought of when writing the code re displaying matrices when using eval.

What I Did

n = [2 5 10];
q = ['i' 'ii' 'iii'];

displayformat matrix latex;

for i = 1:length(n)
    var_name = sprintf('H_%d', n(i));
    b_name = sprintf('b_%d', n(i));
    x_g_name = sprintf('x_g_%d', n(i) );
    x_b_name = sprintf('x_b_%d', n(i) );
    g_toc_name = sprintf('g_toc_%d', n(i) );
    b_toc_name = sprintf('b_toc_%d', n(i) );

    eval(['disp("R3.2' q(i) '\n------------");'])

    eval([b_name ' =  zeros(n(i));']);
    eval([var_name ' = hilb(n(i));']);

    tic;
    eval([ x_g_name ' = solve_eq(' var_name ', ' b_name  ')']);
    eval([g_toc_name ' = toc']);

    tic;
    eval([ x_b_name ' = ' var_name ' \ ' b_name  ';']);
    eval([b_toc_name ' = toc']);

    if i <= 3
        disp("\n")
    end