I want to create a Lyx-macro that takes two inputs in math and stacks them above each other, upper and lower part of the same size. Below is the definition in Latex and its desired use. How can I define the command in Lyx as macro?

I do not know how to insert a \\ in the macro environment. Ctrl-Enter is disabled and Enter leaves the macro environment and typing \\ gives me \backslash. When I edit the .lyx file and add the \\ directly I get the desired result. But I don't know how input this in the lyx-editor.

\newcommand{\vchop}[2]{\begin{gathered}#1 \\ #2 \end{gathered}}
\newcommand{\vchopp}[3]{\begin{gathered}#1 \\ #2 \\ #3\end{gathered}}

Edit: Copying a gathered environment with the desired number of rows from a math-expression not in a macro into the macro works. But this is not optimal.

  • 2
    I see your problem. It also seems to work if you write out \begin{gathered}#1 \\ #2 \end{gathered} in non-math mode, then paste it into the TeX field, or highlight a non-math line newcommand... and then choose Insert > Inline formula. A keybaord shortcut with function command-sequence math-insert \begin{gathered}; newline-insert newline will also work. – Rasmus May 8 '14 at 13:26

When your cursor is inside the gathered (or similar) environment in a math macro, several math toolbars should appear at the bottom. One will have the button for adding a row; it looks like a row in a matrix highlighted in green with a green plus next to it.

  • This only works outside of macro-definitions. – Heinrich Ody Jul 19 '14 at 10:41
  • @HeinrichOdy I just double checked, and the toolbar button to insert a row in a \gathered definitely works in a macro definition. Sometimes it's greyed out if LyX is a bit confused about what thing you want a row added to, but this isn't unique to macro definitions and is solved by moving your cursor within the row. – Jim Oldfield Jul 20 '14 at 11:41
  • @JimOldfield If "LyX is a bit confused" is a bug or could be improved, please file a feature request on trac with a reproducible example and I will take a look at it, although no promises for when. – scottkosty Sep 14 '14 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.