Sometimes I exploit WolframAlpha to do some simple calculations and then insert results in my latex code. But I find annoying to adapt the output given by WA to the LaTeX syntax.
When the output is a matrix the copyable (plain text) output is something like that
a | b | c
d | e | f
g | h | i
so I decided to change the catcode of the vertical bar |
to that of an aligning character with the command
\catcode`|=4
of course I have to do that inside a group in order to avoid serious issues. Here I got a code that works fine, but I'm asking if it is the right way to do it and why it does not work when some modifications are added. Here is my code.
\[ \catcode`|=4 %changing the catcode to that of alignment character
M(f_{V})=\begin{pmatrix}
2 | 0 | 0\\
1 | 1 | 3\\
0 | 0 | -2
\end{pmatrix}
\]
Putting inside a \begigroup
\endgroup
works fine:
\[
M=\begingroup \catcode`|=4\begin{pmatrix}
a|b|c\\ d|e|f\\ g|h|i
\end{pmatrix} \endgroup=M(f|V) %It works either
\]
but inside `\begin{matrix}` `\end{matrix}` it does not:
\[
M= \begin{pmatrix}\catcode`|=4 %It doesn't work
a|b|c\\ d|e|f\\ g|h|i
\end{pmatrix}
\]
Finally, is there any difference between
\[M=\begingroup \catcode`|=4\begin{pmatrix}
a|b|c\\ d|e|f\\ g|h|i
\end{pmatrix} \endgroup=M(f|V)
\]
and
\[{ \catcode`|=4\begin{pmatrix}
a|b|c\\ d|e|f\\ g|h|i
\end{pmatrix} }=M(f|V) \] ?
I use \documentclass{article} \usepackage{amsmath}
in the preamble.