1

Below code is working fine.

\begin{eqnarray*}
\begin{split}
    (U\ket{v},U\ket{w}) & = (\ket{v},\ket{w}) \\
    || \ket{Uv} || & = || \ket{v} ||
\end{split}
\end{eqnarray*}

But if I define equation environment in macros, then it is giving error that "Split can't work in math mode".

In preamble,

\newcommand{\benn}{\begin{equation*}}
\newcommand{\eenn}{\end{equation*}}

Using it inside,

\benn
\begin{split}
        (U\ket{v},U\ket{w}) & = (\ket{v},\ket{w}) \\
        || \ket{Uv} || & = || \ket{v} ||
\end{split}
\eenn

Edit: Minimal not working example

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\usepackage[margin=0.8in]{geometry}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{gensymb}

\usepackage{amsthm}
\usepackage{braket}



\newcommand{\beann}{\begin{eqnarray*}}
\newcommand{\eeann}{\end{eqnarray*}}

\begin{document}

    \beann
        \begin{split}
            (U\ket{v},U\ket{w}) & = (\ket{v},\ket{w}) \\
            || \ket{Uv} || & = || \ket{v} ||
        \end{split}
    \eeann
\end{document}
MeetR
  • 113
  • Welcome to TeX.SE: can you see this link please? https://tex.stackexchange.com/questions/155165/split-not-working-with-self-defined-command – Sebastiano Aug 15 '18 at 10:47
  • Ohh sorry, I was not able to find it. Thanks! – MeetR Aug 15 '18 at 10:53
  • Don't worry. Almost two years ago, I was unable to find it myself. :-) – Sebastiano Aug 15 '18 at 10:54
  • 1
    I can't completely agree with @Sebastiano's link. That seems to be a different problem (hidden &). As a matter of fact, the code you posted works perfectly fine for me. I have suspects about what you are doing wrong, but you should post a a full minimal working example which reproduces the issue, starting with \documentclass{...} and ending with \end{document}. – campa Aug 15 '18 at 10:57
  • @campa Mine was just an indication. Not a duplicate at all, I would never have done it for a new user. I simply thought that an old question could make him think. – Sebastiano Aug 15 '18 at 10:58
  • @campa I have added minimal example, can you try that? – MeetR Aug 15 '18 at 11:04
  • 2
    Your MWE works for me. – Steven B. Segletes Aug 15 '18 at 11:09
  • I am using share latex. It is not giving error in "logs and output files" but in writing area it is showing error mark. – MeetR Aug 15 '18 at 11:11
  • The code given by the op also compiles/displays fine for me. However, there is the line in the log file Package amsmath Warning: Cannot use 'split' here; (amsmath) trying to recover with 'aligned' on input line 25. (Which I agree with: your use case really seems better treated by either gather or align or aligned, since the two displayed lines are two distinct equations, not one long equation split on multiple lines.) Can you post a screen cap of what you see on ShareLateX and also post the log file? – Willie Wong Aug 15 '18 at 13:10
  • Also, why are you using eqnarray when using amsmath? https://tex.stackexchange.com/questions/196/eqnarray-vs-align If I replace your eqnarray* in the definition of beann with equation*, the amsmath warning in my previous comment goes away and everything still displays fine. – Willie Wong Aug 15 '18 at 13:17

1 Answers1

5

Please note: in the future please give a MWE and the exact error/warning. In your question you say the compiler

is giving error that "Split can't work in math mode".

while running the code gives the warning

Package amsmath Warning: Cannot use `split' here;
(amsmath)                trying to recover with `aligned' on input line 19.

For people trying to figure out what is going on there is quite a difference :-)

Now to the issue: the amsmath user's guide states

The split environment is designed to serve as the entire body of an equation, or an entire line of an align or gather environment. There cannot be any printed material before or after it within the same enclosing structure.

But eqnarray (which shouldn't be used anyway when amsmath is loaded, see eqnarray vs align) kind of does that, so that's why this is failing.

In this particular case, I see no reason to enclose split within an environment providing aligning points. You can use align* (without split), or \[ ... \]

\documentclass{article}

\usepackage{mathtools} % loads amsmath
\DeclarePairedDelimiter{\norm}{\Vert}{\Vert}
\usepackage{amssymb}
\usepackage{gensymb}
\usepackage{braket}

\begin{document}

Either
\begin{align*}
(U\ket{v},U\ket{w}) & = (\ket{v},\ket{w}) \\
\norm{\ket{Uv}} & = \norm{\ket{v}}
\end{align*}
or
\[
\begin{split}
(U\ket{v},U\ket{w}) & = (\ket{v},\ket{w}) \\
\norm{\ket{Uv}} & = \norm{\ket{v}}
\end{split}
\]
\end{document}
  • I removed a couple of packages irrelevant for the MWE
  • I loaded mathtools (which loads amsmath) and defined a macro \norm
campa
  • 31,130