# Exporting column vector as matrix in latex via "Copy as" doesn't always work. Example with vector

I want the simplest way of exporting matrices, and vector from mathematica to Latex.

Usually, I display my matrices in MatrixForm and copy as Latex to paste in my latex document. However it seems it doesn't always work, take the following code:

vv = {1, 2};
vv // MatrixForm


If from the display you do "copy as -> Latex", it returns you:

\{1,2\}


Instead of (for example):

$$\begin{pmatrix} 1 \\ 2 \end{pmatrix}$$


Which would match the mathematica display. If I input a matrix however (thus having more than 1 column), it works as it should.

How to make it really returns me something that will look like a column vector in latex ?

• In version 12, I only get array, not pmatrix. Jan 16, 2020 at 13:10
• @HenrikSchumacher I don't necesserally want a pmatrix and indeed it is not what it returns me for a "real" matrix (not a column vector). But I want a proper array to represent the column vector which he doesn't give me. Jan 16, 2020 at 13:45

## 1 Answer

What about

export[v_?VectorQ] := export@Partition[vv, 1];
export[A_?MatrixQ] := CopyToClipboard@TeXForm@A;


and then

vv // export


?

A way to enforce pmatrix could be

export[v_?VectorQ] := export@Partition[vv, 1];
export[A_?MatrixQ] := CopyToClipboard@StringJoin[
"\\begin{pmatrix}\n",
ExportString[
Join[
Map[TeXForm, A, {2}],
Append[ConstantArray["\\\\", {Length[A] - 1, 1}], {""}],
2],
"Table",
"FieldSeparators" -> " & "
],
"\n\\end{pmatrix}"
];


Btw., MatrixForm is super superfluous here.

• Thank you for your answer. So actually the "real" answer inside is that I have to do Partition[vv, 1] to tell mathematica to write it as a matrix (even if it is a column vector). So that when I export in latex he knows he has to write a column vector using array. Would you confirm ? Jan 16, 2020 at 13:47
• Mathematica just does not distinguish between "column vectors" and "row vectors". But you can transform an $n$-vector v into a $n \times 1$-matrix with Partition[v,1]. Btw., I strongly believe that Mathematica is a "she". But who knows...? Jan 16, 2020 at 13:52
• Ok thanks. Well actually I'm french so I sometime replace it by he or she as we don't have impersonal pronouns ^^ Jan 16, 2020 at 14:00