1

I tried to write a very simple code in Magma to print a matrix in a way that can be copypasted directly in Latex.

PrintLatex:= function(M)
for i in [1..NumberOfRows(M)] do
for j in [1..NumberOfColumns(M)-1] do
printf("%o &", M[i,j]);
end for;
printf("%o \\", M[i,NumberOfColumns(M)]);
end for;
return 0;
end function;
M:=ZeroMatrix(Integers(),3,3);
PrintLatex(M);

However, when I run the following code I get an error, saying

PrintLatex(
    M: [0 0 0] [0 0 0] [0 0 0]
)
>> printf("%o \\", M[i,NumberOfColumns(M)]);
         ^
Runtime error in elt< ... >: No permutation group context in which to create
cycle

I have no idea what the online calculator is talking about. Permutation group context?! Can anyone point me in the right direction?

1 Answers1

1

I can run the result after modification, but I don't know if it meets your requirements

PrintLatex := function (M)
printf "\\left(\n\\begin{array}{";
for i := 1 to NumberOfColumns (M)  do printf "c", i; end for;
printf "}\n";
for i in[1 .. NumberOfRows (M)] do
for j in[1 .. NumberOfColumns (M) - 1] do
printf "%o &", M[i, j];
end for;
printf "%o \\\\\n", M[i, NumberOfColumns (M)];
end for;
printf "\\end{array}\n\\right)\n";
return 0;
end function;
M := ZeroMatrix (Integers (), 3, 3);
PrintLatex (M);