# \newcommand bug

I am trying to define the following new command:

\newcommand{\kernel}[2]{k\left( #1, #2 \right)}


which when implemented via

$\kernel{\cdot}{Y}$


yields k(.,Y) (not sure how to reproduce the \cdot here)

which works, however I would like to set a default for the first argument to be \cdot, and I tried to do it via the following:

\newcommand{\kernel}[2][\cdot]{k\left( #1, #2 \right)}


however if I implement it via

$\kernel{}{Y}$


it gives k(.,)Y and not k(.,Y)!!!

This seems like a weird bug and I was wondering if anyone knew how to fix it, I tried using xparse instead to define the command but I got the same bug. Thanks in advance!

• Since it is an optional argument, you would say $\kernel[]{Y}$ with square brackets around the optional (null) argument. – Steven B. Segletes Mar 28 '17 at 10:16
• This is no bug but wrong usage ;-) – user31729 Mar 28 '17 at 10:20
• Isn't there already a \ker command that indicates the kernel of a vector space? – user31729 Mar 28 '17 at 10:27

The given definition of the \kernel command is ok, but the calling is wrong. [2][\cdot] means that the first argument is optional and has be to called with \kernel[foo]{Y},i.e. [...] indicates the optional argument.

In the code below I show an xparse version, also replacing k with a operator (expanding to k) and removing the \left(...\right) pair.

\documentclass{article}

\usepackage{xparse}
\usepackage{mathtools}
\DeclareMathOperator{\kernelop}{k}

\NewDocumentCommand{\kernel}{O{\cdot}m}{\kernelop(#1,#2)}

\begin{document}

$\kernel{Y}$

$\kernel[\oplus]{X}$

\end{document}


• I usually give some room to the dot, with \,\cdot or even \,\cdot\,. – Manuel Mar 28 '17 at 10:45
• @Manuel: That depends on personal preferences. The issue was the wrong usage of the command, I only improved it somewhat :-) – user31729 Mar 28 '17 at 12:15