Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Straight forward question:

\newcommand{\optaxis}[1][]{
   \ifemptyarg{#1}
    {\begin{axis} [xtick={0},   xmin=-1,  xmax =1,  xticklabels={#2},   box plot width=5mm]}
    {\begin{axis} [xtick={0,1}, xmin=-1,  xmax =2,  xticklabels={{#1},{#2}},    box plot width=5mm]}%

}

How can I get the part here to work correctly - {{#1},{#2}} - I am getting a variety of errors which I cannot seem to resolve. If I change that to {test,test2} it works and compiles fine.

The specific error message is:

You meant to type ## instead of #, right?


edit:

I am trying to use from here:

\makeatletter


\def\ifemptyarg#1{%
  \if\relax\detokenize{#1}\relax % H. Oberdiek
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi}

\makeatother

\newcommand{\optaxis}[1][]{
   \ifemptyarg{#2}
    {\begin{axis} [xtick={0},   xmin=-1,  xmax =1,  xticklabels={#1},   box plot width=5mm]}
    {\begin{axis} [xtick={0,1}, xmin=-1,  xmax =2,  xticklabels={{#1},{#2}},    box plot width=5mm]}
}

I want to be able to call this like:

\optaxis{test1}
\optaxis{test1, test2}

and have each called respectively.

share|improve this question
2  
I answered the specific error but if you made your example into a complete (small) document that showed what you were trying to do we could suggest how to change the code. –  David Carlisle Mar 29 '13 at 22:25
    
@DavidCarlisle I've updated the question with more. –  enderland Mar 29 '13 at 22:29
    
There is only one parameter in \optaxis{test1, test2} which is test1, test2. If you used \optaxis{test1}{test2} then you would have two parameters. –  Peter Grill Mar 29 '13 at 22:30
    
See my answer, you just want one parameter which can have a comma, you have defined it as optional so my examples use [] if you do not define it as optional then the argument would be surrounded by {} –  David Carlisle Mar 29 '13 at 22:33

1 Answer 1

up vote 8 down vote accepted

You have defined a command with one argument

\newcommand{\optaxis}[1][]{

so you can't use #2

I suspect you just want

\newcommand{\optaxis}[1][]{%%%
 \begin{axis} [xtick={0},   xmin=-1,  xmax =1,  xticklabels={#1},   box plot width=5mm]}

so that

\optaxis

is xticklabels={}

\optaxis[test1]

is xticklabels={test1}

\optaxis[test1,test2]

is xticklabels={test1,test2}

Or perhaps no optional argument at all so

\newcommand{\optaxis}[1]{%%%
 \begin{axis} [xtick={0},   xmin=-1,  xmax =1,  xticklabels={#1},   box plot width=5mm]}

so that

\optaxis{test1}

is xticklabels={test1}

\optaxis{test1,test2}

is xticklabels={test1,test2}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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