# Incomplete \iffalse error in AMS alignment

MWE:

\documentclass[a4paper]{report}
\usepackage{amsmath,xparse}
\makeatletter
\newif\ifinvd@lims\invd@limsfalse
\newif\iflr\lrfalse
\ExplSyntaxOn
\newcommand{\delim}[3][lr]{
\begingroup
\str_case:nnF { #1 }
{
{ lr }{\def\lsize{\left}\def\rsize{\right}    \lrtrue}
}
{\typeout{#1}
}
\str_case:nnF { #2 }
{
{ v }{\def\ldel{|}\def\rdel{|}}
}
{\typeout{#2}
}
\ifinvd@lims
\ldel #3 \rdel
\else
\lsize\ldel #3 \rsize\rdel
\fi
\endgroup
}
%\ExplSyntaxOff
\newcommand{\abs}[1][lr]{\delim[#1]{v}}

\begin{document}
$\abs{Jh(x,y,z)}=\begingroup \str_case:nnF {lr} { { lr }{\def\lsize{\left}\def\rsize{\right} \lrtrue} } {\typeout{} } \str_case:nnF {v} { { v }{\def\ldel{|}\def\rdel{|}} } {\typeout{} } \ifinvd@lims % \ldel #3 \rdel \else \lsize\ldel \begin{matrix} y-z & x & -x \\ 0 & 2(y+z) & 2(y+z) \\ 2z & 4y & 4z \end{matrix} \rsize\rdel \fi \endgroup$
\begin{align*}
\abs{Jh(x,y,z)}=&\abs{\begin{matrix}
y-z & x & -x \\
0 & 2(y+z) & 2(y+z) \\
2z & 4y & 4z
\end{matrix}}=(y-z)\abs{\begin{matrix} 2(y+z) & 2(y+z) \\ 4y & 4z \end{matrix}}+{} \\
{}+&2x\abs{\begin{matrix} x & -x \\ 2(y+z) & 2(y+z) \end{matrix}}=4(y-z)(y+z)\abs{\begin{matrix} 1 & 1 \\ y & z \end{matrix}}+4x^2(y-z)\abs{\begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix}}=-8(y-z)^2(y+z)+8x^2(y+z)=8(y+z)(x^2-(y-z)^2\!).
\end{align*}
\end{document}


This generates the error Incomplete \iffalse: all text was ignored after line 64, line 64 being the second \end{align*}. If I use an align* the first time too (i.e. where there is $…$ in the code above), the error shifts to line 53 (\end{matrix} \rsize\rdel), and the incomplete if is and \ifx. If I use $…$ the second time too, everything compiles, and I get: which is what I want, save for the hyper-overfull \hbox, which is why I wanted the align* basically. So what is happening in here? Everything seems to be align*'s fault, though even a gather* gives the problem. Removing the stars also does nothing. How do I get this to compile?

• you've been on the site long enough to know that really isn't a useful title for future archival purposes – David Carlisle Nov 5 '14 at 15:31
• You have to put \makeatother somewhere. Please minimize your code! You are talking about two aligns but show one. The error results in an other line number so this information does not help either. It is very difficult to understand your hole post. – LaRiFaRi Nov 5 '14 at 15:33
• I don't think anybody is willing to plunge into that messy code without even the slightest information about the expected result. – egreg Nov 5 '14 at 15:40
• By the way, I'm that used to expl3 formatting that when I see expl3 badly formatted, I simply can't read it. I think it's nice to have a guideline to write code in a way that eases understanding. – Manuel Nov 5 '14 at 15:40
• .\@ foo doesn't work if @ is a letter. – David Carlisle Nov 5 '14 at 15:47

You haven't given any indication of what this code is intended to do and it is a very bizarre mix of latex3, latex2e and tex primitives, so I haven't attempted to guess what it is doing, but this version runs without error.

\documentclass[a4paper]{report}
\usepackage{amsmath,xparse}
\makeatletter
\newif\ifinvd@lims\invd@limsfalse
\newif\iflr\lrfalse
\ExplSyntaxOn
\newcommand{\delim}[3][lr]{
\begingroup
\str_case:nnF { #1 }
{
{ lr }{\def\lsize{\left}\def\rsize{\right}    \lrtrue}
}
{\typeout{#1}
}
\str_case:nnF { #2 }
{
{ v }{\def\ldel{|}\def\rdel{|}}
}
{\typeout{#2}
}
\ifinvd@lims
\ldel #3 \rdel
\else
\lsize\ldel #3 \rsize\rdel
\fi
\endgroup
}
%\ExplSyntaxOff
\newcommand{\abs}[1][lr]{\delim[#1]{v}}

\begin{document}
$\abs{Jh(x,y,z)}=\begingroup \str_case:nnF {lr} { { lr }{\def\lsize{\left}\def\rsize{\right} \lrtrue} } {\typeout{} } \str_case:nnF {v} { { v }{\def\ldel{|}\def\rdel{|}} } {\typeout{} } \ifinvd@lims % \ldel #3 \rdel \else \lsize\ldel \begin{matrix} y-z & x & -x \\ 0 & 2(y+z) & 2(y+z) \\ 2z & 4y & 4z \end{matrix} \rsize\rdel \fi \endgroup$
\begin{align*}
{\abs{Jh(x,y,z)}}=&
{\abs{\begin{matrix}
y-z & x & -x \\
0 & 2(y+z) & 2(y+z) \\
2z & 4y & 4z
\end{matrix}}}=(y-z){\abs{\begin{matrix} 2(y+z) & 2(y+z) \\ 4y & 4z \end{matrix}}}+{} \\
{}+&2x
{\abs{\begin{matrix} x & -x \\ 2(y+z) & 2(y+z) \end{matrix}}}
=4(y-z)(y+z)
{\abs{\begin{matrix} 1 & 1 \\ y & z \end{matrix}}}
+4x^2(y-z)
{\abs{\begin{matrix} 1 & -1 \\ 1 & 1 \end{matrix}}}
=-8(y-z)^2(y+z)+8x^2(y+z)=8(y+z)(x^2-(y-z)^2\!).
\end{align*}
\end{document}

• The code is meant to define a flexible delimiter command (there are many more cases in the actual thing, for many size combinations and delimiter combinations, but I needed it to be minimal here) and then to use it in that equation with the align to solve the overfull \hbox and align as your version shows (plus another line change I will plug in afterwards). It defines \abs in terms of \delim too, for the sake of clarity and shortness. That equation was in the middle of my notes, but I extracted it to give an MWE. So the problem is solved. I wonder why grouping solved it… – MickG Nov 5 '14 at 15:54
• \ifinvd@lims is defined to be used in \delim when using combinations such as ]…[, which need \mathopen and/or \mathclose which has to include the size command too, meaning I need to do \ldel\rdel and not \lsize\ldel\rsize\rdel, since the size is in the \ldel\rdel pair. The grouping inside the \delim command is to avoid the redefinition of those commands to be problematic in nested \delims: suppose I do \pa{\abs{…}}. The result without the \begingroup…\endgroup is (|…||. With it, it becomes (|…|), as wanted. – MickG Nov 5 '14 at 15:57
• Any idea why the {…} you added around each \abs with matrix inside solved the error? – MickG Nov 5 '14 at 15:58
• @MickG the error message implied you had the scopes wrong somewhere there was no way I was going to debug the code (really there must be a better way of doing whatever it is doing) so the first thing I tried was putting {} around each use. The error went away so I posted. – David Carlisle Nov 5 '14 at 15:59
• @MickG don't ask new questions in comments {} and \begingroup\endgroup are completely different in math (and in alignments) and an ams alignment is a an alignment in math... {} forms a new math list and returns a mathord atom \begingroup affects the grouping without making a new list or math atom, you can (with care) have an unmatched \begingroup in an alignment cell, but you can't have an unmatched { as the & will not be taken as cell end if it is at a different brace level – David Carlisle Nov 5 '14 at 16:30