1

I would like to define the command A\!\!_B\!C in a math mode as a macros, and I am using the following:

\newcommand{\cmp}[3]{#1\!\!_#2\!#3}

Unfortunately I get an error that there are {} missing. Any hint is appreciated.

Is there any possibility to get a Mathematica-like syntax with only one argument, splitting it a the comma?

10
  • 2
    At least it should be \newcommand{\cmp}{...} with a backslash.
    – egreg
    Commented Mar 20, 2014 at 13:36
  • I don't get any error once I add @egreg's backslash...
    – cslstr
    Commented Mar 20, 2014 at 13:37
  • 2
    You might also want to use _{#2} in case #2 has more than one character. Commented Mar 20, 2014 at 13:39
  • @egreg: I had that in code, didn't copy properly here. Could you clarify how shall I call \cmp then in the body?
    – SBF
    Commented Mar 20, 2014 at 13:49
  • @Ilya Can you make a simple example of what gives you an error?
    – egreg
    Commented Mar 20, 2014 at 13:53

2 Answers 2

3

For example:

\def\cmp#1{\cmpA#1,}
\def\cmpA#1,#2,#3,{{#1}\!\!_{#2}\!{#3}}

$a = \cmp{A,B,C}$

But I don't understand, why do you need the ugly clump of letters.

1
  • I've been asking myself the same question. But look at how old the queston is, i bet we will never here the answer.
    – Johannes_B
    Commented Jan 25, 2015 at 16:15
4

With your original command you have to remember to give it three arguments.

With package xparse you can split one argument at a given symbol (here the comma) and hence stick with the syntax you know from Mathematica.

The output looks a little bit odd though, but this is a different matter.

\documentclass{article}
\usepackage{xparse}
\newcommand{\cmp}[3]{#1\!\!_{#2}\!#3}
\NewDocumentCommand{\cmpA}{  >{\SplitArgument{2}{,}} m}
{\cmp#1}%<- feeding the three arguments to the original command

\begin{document}
\[ \cmp{A}{B}{C} \]
\[ \cmpA{A,B,C} \]
\end{document}
1
  • @egreg I changed it for the sake of generity. I thought about it as well (it is also above in the comments), but decided against it as there is some kind of logic behind that thing (at least i hope so).
    – Johannes_B
    Commented Jan 25, 2015 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .