
function str=stringmult(nb,str0)
	str=emptystr (str0);
	if size(nb)==size(str0) then
		for i=1:size(nb,1)
			for j=1:size(nb,2)
				for k=1:nb(i,j)
					str(i,j)=str(i,j)+str0(i,j);
				end
			end
		end
	else 
		mkalert("error");
		error ("stringmult: sizes don''t match");
	end		
endfunction
//defines 2*"hey"="heyhey"
function x=%s_m_c(a,b)
x=stringmult(a,b)
endfunction
//defines"hey "*2="hey hey "
function x=%c_m_s(a,b)
x=stringmult(b,a)
endfunction
//defines "string"+5 ="string5"
function x=%c_a_s(a,b)
x=a+string(b)
endfunction
//defines 5+" string" ="5 string"
function x=%s_a_c(a,b)
x=string(a)+b
endfunction
//defines"string"+%t ="stringT"
function x=%c_a_b(a,b)
x=a+string(b)
endfunction
//defines %f+" string" ="F string"
function x=%b_a_c(a,b)
x=string(a)+b
endfunction
//defines ["hi" %t] = ["hi""T"]
function x=%c_c_b(a,b)
x=[a string(b)]
endfunction
function x=%b_c_c(a,b)
x=[string(a) b]
endfunction
//defines ["hi" 5] = ["hi""5"]
function x=%c_c_s(a,b)
x=[a string(b)]
endfunction
function x=%s_c_c(a,b)
x=[string(a) b]
endfunction
function x=%c_f_s(a,b)
x=[a; string(b)]
endfunction
function x=%s_f_c(a,b)
x=[string(a); b]
endfunction
if ~isdef("%b_x_b")
function x=%b_x_b(a,b)
        x=(bool2s(a) .* bool2s(b))==1
endfunction
end
//defines %t*"bonjour" +%f*"bye" ="bonjour"
function x=%b_m_c(a,b)
x=%s_m_c(a+0,b)
endfunction

function m2tabular(matname,headlines,headcols,SAVEDIR)

    if ~isdef("SAVEDIR")
        SAVEDIR="";
    end
    
    if argn(2)<3
        headcols = 1;
    end
    
    if argn(2)<2
        headlines = 1;
    end    
    
    if argn(2)<1
        error("At least one input expected: matname (name of cilab matrix)")
    end
    
    if typeof("a")~="string"
        error("first argument should be the name of a Scilab matrix")
    end
    
    mat =evstr(matname)

    mat(:,2:$) ="& " + mat(:,2:$);
    mat(:,$) = mat(:,$) + " \\";
    mat(headlines,$) = mat(headlines,$) + " \midrule";

    nbcols = size(mat,2)-headcols;

    mat = [ "\begin{tabular}{"+(headcols*" l ")+(nbcols*" c ")+"} \toprule"; strcat(mat,"","c"); "\bottomrule \end{tabular}"]
    
    csvWrite(mat,SAVEDIR+matname+".tex")
endfunction

