I'd like to use ClickToCopy to display a matrix equation, and have its TeX form be copyable. I started with something like
ClickToCopy[M == IdentityMatrix[2],
ToString@TeXForm[M == IdentityMatrix[2]]]
but then the copied text is a String and not something I can just paste into a tex file:
"M=\\left(\n\\begin{array}{cc}\n 1 & 0 \\\\\n 0 & 1 \\\\\n\
\\end{array}\n\\right)"
So, following advice here, I added RawBoxes
:
ClickToCopy[M == IdentityMatrix[2],
RawBoxes@ToString@TeXForm[M == IdentityMatrix[2]]]
This is much closer to being correct, but now I get
M = \left (
\begin {array} {cc}
1 & 0 \\
0 & 1 \\
\end {array}
\r ight)
In the last line, "\right" gets an unwanted space. Looking at other examples, this behavior seems to be connected with the backslash, but I'm not sure exactly what makes it happen.
Is there (a) a way of fixing the original ClickToCopy without RawBoxes, or (b) a way to fix this behavior in RawBoxes?