# Command as default argument of macro

I'm able to create a macro without problems which takes a command as one of its arguments, eg:

\newcommand{formatnodefault}[2]{#1 #2}
% both of these work
\formatnodefault{\mathcal}{ABC}
\formatnodefault{\mathfrak}{ABC}


But when I try to give a default for the command, it still works when using the default but not when I explicitly pass in the command to use

\newcommand{formatdefault}[2][\mathcal]{#1 #2}
\formatdefault{ABC} % this works fine
\formatdefault{\mathfrak}{ABC} % this doesn't work


Is there something that I'm doing wrong with entering/overriding the default here? If it matters, this is being processed by MathJax from a Jupyter notebook.

• \formatdefault[\mathfrak]{ABC} -- you're defining it with an optional argument, so \mathfrak should be inside that, otherwise it would try to call \mathcal \mathfrak. And you're missing a the backslash in \newcommand
– user31729
Mar 1 '18 at 16:44
• Syntax, syntax, syntax! Mar 1 '18 at 16:44

This works in LaTeX, but I am unsure about MathJax, which isn't TeX etc. anyway, apart from a similar syntax.

It should be called \formatdefault[\mathfrak]{ABC} otherwise \formatdefault would use \mathcal \mathfrak, taking \mathfrak to be the second argument whereas it was meant as first one.

\documentclass{article}

\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsfonts}

\newcommand{\formatdefault}[2][\mathcal]{#1{#2}}

\begin{document}

$\formatdefault{ABC}$ % this works fine
$\formatdefault[\mathfrak]{ABC}$

\end{document}

• It also works in MathJax. Mar 1 '18 at 16:50