Question: improvement to Latex. Removing extra \\ at end of array conversions

When Maple converts a matrix or a vector to Latex it uses latex array, which  is fine, but what it does is insert an exatra \\ at the end of the last row, just before the \end{array} 

This causes problem for some software which reads the latex file. It causes the software to take this as empty row and inserts a blank row at the end.

Here is a small example

A:=Matrix([[1,2],[3,4]]);
Physics:-Latex(A);

              \left[\begin{array}{cc}1 & 2 \\3 & 4 \\\end{array}\right]

Notice the extra \\  just before the \end{array} In Latex, this tells latex compiler to insert newline basically.

When opening the latex file using external software, which reads Latex and converts it to GUI, it show this

And now I have to go edit the latex by hand removing the extra \\ (inside the editor I can do global search and replace)

A better outout from Maple's Latex command would be the following

\left[\begin{array}{cc}1 & 2 \\3 & 4 \end{array}\right]

Even though both are valid Latex, the above is better.  I was wondering how hard it is to do this change.

All what the conversion needs to do is just check if the row in the matrix (or Vector) is the last one, and omit the extra \\ at the end of the last row. That is all. 

I could ofcourse write code to try to parse this each time I call Latex and to remove \\ myself in the program, but it will be much easier if Maple automatically did this.

 

ps. if the Latex conversion source code could be made public, others could help make improvement to it for free, benefiting Maple and everyone using it. Maplesoft would still approve the changes before checkin, and retain the copy right of the source code ofcourse. 

 

Maple 2020.1

 

Please Wait...