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?

  • 2
    At least it should be \newcommand{\cmp}{...} with a backslash. – egreg Mar 20 '14 at 13:36
  • I don't get any error once I add @egreg's backslash... – cslstr Mar 20 '14 at 13:37
  • 2
    You might also want to use _{#2} in case #2 has more than one character. – John Kormylo Mar 20 '14 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? – Ilya Mar 20 '14 at 13:49
  • @Ilya Can you make a simple example of what gives you an error? – egreg Mar 20 '14 at 13:53
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.

  • 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 Jan 25 '15 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}
  • @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 Jan 25 '15 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.