The problem is that the \begin{...}
and \end{...}
pair commands automatically create a "group" so that, in effect, the &
and \\
are "out of scope" for the tabular, while inside the "production" environment they just show up at a place where the compiler is not expecting them.
A second problem with your definitions is that, even if they would work, they would be adding an extra \\
at the end of the tabular, adding an unwanted space at the end. Perhaps some more appropriate definitions would be
\documentclass[a4paper,10pt]{article}
\newcommand{\production}[1]{#1 ::= &}
\newenvironment{grammar}{\tabular{p{3cm}l}}{\endtabular}
\begin{document}
\begin{grammar}
\production{XmlStartTag} ... \\
\production{XmlOtherTag} ... \\
\production{XmlEndTag} ...
\end{grammar}
\end{document}
Note no \\
at the end of the last production. Also in the definition of the grammar
you don't need to repeat the work of \begin
/\end
, and you can instead directly use \tabular
and \endtabular
.
Let's see how commath
should define its macros.
\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{amsmath}
%%% Here start the definitions
\newcommand{\dif}{\mathop{}\!\mathrm{d}}
\newcommand{\Dif}{\mathop{}\!\mathrm{D}}
\makeatletter
\newcommand{\spx}[1]{%
\if\relax\detokenize{#1}\relax
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{^{#1}}%
}
\makeatother
\newcommand\pd[3][]{\frac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\newcommand\tpd[3][]{\tfrac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\newcommand\dpd[3][]{\dfrac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\newcommand{\md}[6]{\frac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}
\newcommand{\tmd}[6]{\tfrac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}
\newcommand{\dmd}[6]{\dfrac{\partial\spx{#2}#1}{\partial#3\spx{#4}\partial#5\spx{#6}}}
\newcommand{\od}[3][]{\frac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}
\newcommand{\tod}[3][]{\tfrac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}
\newcommand{\dod}[3][]{\dfrac{\dif\spx{#1}#2}{\dif#3\spx{#1}}}
\newcommand{\genericdel}[4]{%
\ifcase#3\relax
\ifx#1.\else#1\fi#4\ifx#2.\else#2\fi\or
\bigl#1#4\bigr#2\or
\Bigl#1#4\Bigr#2\or
\biggl#1#4\biggr#2\or
\Biggl#1#4\Biggr#2\else
\left#1#4\right#2\fi
}
\newcommand{\del}[2][-1]{\genericdel(){#1}{#2}}
\newcommand{\set}[2][-1]{\genericdel\{\}{#1}{#2}}
\let\cbr\set
\newcommand{\sbr}[2][-1]{\genericdel[]{#1}{#2}}
\let\intoo\del
\let\intcc\sbr
\newcommand{\intoc}[2][-1]{\genericdel(]{#1}{#2}}
\newcommand{\intco}[2][-1]{\genericdel[){#1}{#2}}
\newcommand{\eval}[2][-1]{\genericdel.|{#1}{#2}}
\newcommand{\envert}[2][-1]{\genericdel||{#1}{#2}}
\let\abs\envert
\newcommand{\sVert}[1][0]{%
\ifcase#1\relax
\rvert\or\bigr|\or\Bigr|\or\biggr|\or\Biggr
\fi
}
\newcommand{\enVert}[2][-1]{\genericdel\|\|{#1}{#2}}
\let\norm\enVert
\newcommand{\fullfunction}[5]{%
\begin{array}{@{}r@{}r@{}c@{}l@{}}
#1 \colon & #2 & {}\longrightarrow{} & #3 \\
& #4 & {}\longmapsto{} & #5
\end{array}
}
%%% end of the definitions
\linespread{2} % just for this test file
\begin{document}
$f(x)\dif x\quad f(x)\Dif x$
$\pd{f}{x}\displaystyle\pd[2]{f}{x}$
$\tpd{f}{x}\displaystyle\tpd[2]{f}{x}$
$\dpd{f}{x}\displaystyle\dpd[2]{f}{x}$
$\od{f}{x}\displaystyle\od[2]{f}{x}$
$\tod{f}{x}\displaystyle\tod[2]{f}{x}$
$\dod{f}{x}\displaystyle\dod[2]{f}{x}$
$\md{f}{5}{x}{2}{y}{3}\displaystyle\md{f}{5}{x}{2}{y}{3}$
$\tmd{f}{5}{x}{2}{y}{3}\displaystyle\tmd{f}{5}{x}{2}{y}{3}$
$\dmd{f}{5}{x}{2}{y}{3}\displaystyle\dmd{f}{5}{x}{2}{y}{3}$
$\del{\dfrac{1}{2}}\del[0]{x}\del[1]{x}\del[2]{x}\del[3]{x}\del[4]{x}$
$\sbr{\dfrac{1}{2}}\sbr[0]{x}\sbr[1]{x}\sbr[2]{x}\sbr[3]{x}\sbr[4]{x}$
$\set{\dfrac{1}{2}}\set[0]{x}\set[1]{x}\set[2]{x}\set[3]{x}\set[4]{x}$
$\intoo{a,b}\intoo[0]{a,b}\intoo[1]{a,b}\intoo[2]{a,b}\intoo[3]{a,b}\intoo[4]{a,b}$
$\intcc{a,b}\intcc[0]{a,b}\intcc[1]{a,b}\intcc[2]{a,b}\intcc[3]{a,b}\intcc[4]{a,b}$
$\intoc{a,b}\intoc[0]{a,b}\intoc[1]{a,b}\intoc[2]{a,b}\intoc[3]{a,b}\intoc[4]{a,b}$
$\intco{a,b}\intco[0]{a,b}\intco[1]{a,b}\intco[2]{a,b}\intco[3]{a,b}\intco[4]{a,b}$
$
\eval{f(x)}_a^b
\eval[0]{f(x)}_a^b
\eval[1]{f(x)}_a^b
\eval[2]{f(x)}_a^b
\eval[3]{f(x)}_a^b
\eval[4]{f(x)}_a^b
$
$\abs{x}\abs[0]{x}\abs[1]{x}\abs[2]{x}\abs[3]{x}\abs[4]{x}$
$\norm{x}\norm[0]{x}\norm[1]{x}\norm[2]{x}\norm[3]{x}\norm[4]{x}$
\linespread{1}\selectfont % return to normal
$\fullfunction{f}{A}{B}{x}{y}$
\end{document}
I have omitted the \...ref
macros that are better managed with cleveref
.
As you see, it's only a collection of dubiously useful macros.
Main errors in commath
: the definitions of \dif
and \Dif
are plainly wrong. The usage of \ifinner
is completely wrong; what the author intends to do by \ifinner
with \tfrac
and \dfrac
is already done (better) by the standard \frac
macro.
The "delimiters" macros are wrong in that they use by default \left
and \right
, which is disputable; I've left them as in the original, but defining them in terms of a generic macro.
Best Answer
You can add
\displaystyle
within the inline math environment, e.g.