How can I add a math command with custom look and LaTeX code to LyX? I know this is possible for custom citation commands and character styles, so this should be possible for math commands as well!
EDIT: Actually, one can indeed change the alignment of array
in LyX by GUI means, Besides, I learnt that array
is a bad way of doing what I describe in the "Background" below and I should use alignat
. However, I think this question is relevant nevertheless, because there might be cases one wants to include own commands... for example an array
with >{\cmd}l
-style alignment specifyers, which is currently not possible to enter in the GUI.
Background:
I want to typeset a system of ordinary differential equations where I have similar terms in the same columns, left-aligned. I am not able to do that in LyX because all of the math environments I know center-align their contents.
The best I can up with using LyX-functions is to open a math equation (Ctrl-Shift-M) followed by typing \array
followed by the space key, which opens up a table-like environment where I can enter math:
However, I can not change the alignment of the columns like I can when creating a table outside the math environment. This results in code like the following:
\documentclass{article} % Added for MWE
\begin{document} % Added for MWE
\newcommand\d{\mathrm{d}} % Added for MWE
\[
\begin{array}{ccc}
\frac{\d V}{\d t} & =-\delta_{V} & -k_{inf}\cdot C\cdot V\\
\frac{\d C}{\d t} & =\lambda-\delta_{C} & -k_{inf}\cdot C\cdot V
\end{array}
\]
\end{document} % Added for MWE
Looking like this:
My problem is: I can not change the {ccc}
part of the array
environment yet.
I want to stay with LyX, because the preview feature saves me from repeatedly compiling my document, which takes quite some time.
The best I could come up with so far is to embed raw LaTeX code inside a "Preview" box (code same as above, except lll
):
So the best would be to define a command in LyX, which looks like array
in the LyX window, and invokes a custom environment. This uses the correct alignment which I define beforehand in a macro:
% Defined in LyX preamble
\newenvironment{myarray}{\begin{array}{\al}}{\end{array}}
% Defined as Evil Red Text (ERT) before Equation
\newcommand\al{llll}
% Created by LyX with the same appearance as if I had typed
% \array in LyX math mode
\[
\begin{myarray}
\frac{\d V}{\d t} & =-\delta_{V} & -k_{inf}\cdot C\cdot V\\
\frac{\d C}{\d t} & =\lambda-\delta_{C} & -k_{inf}\cdot C\cdot V
\end{myarray}
\]