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.

I'm currently using LaTeX to make a poster, which is all going very nicely. However for each of the seven boxes on the poster, I've got to pass eight arguments which may change in the future. I thought a sensible thing to do would be:

\newcommand{\details}{textborder=roundedsmall,borderColor=black,headerborder=open,linewidth=1,boxshade=plain,boxColorOne=box,headerColorOne=head1,headerColorTwo=head2}

and then:

\headerbox{Aims}{name=aims,column=0,below=background,\details}{
    Aims
}

However this throws out an error

Package xkeyval Error: blabla (the contents of \details) undefined in families posterbox.

I have checked that replacing the \details with the contents of the custom command works fine!

Any ideas on how to solve this?

share|improve this question
1  
Welcome to TeX.SE. If the answer below does not solve your issue, keep in mind that while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This will also help to ensure that the proposed solution actually works for you. –  Peter Grill Jan 29 '12 at 0:45
1  
@craq the original fails because xkeyval (following keyval) goes to some lengths not to expand macros in its argument so that you can have a setting such as zzz=\wibble and the value of the value of the key is \wibble not the value of \wibble prematurely expanded while parsing the key list. –  David Carlisle Nov 21 at 11:35
    
@craq Are you asking why the code in the question failed or why Dan's initial attempt to implement the answer given didn't work? (But I thought the latter was addressed in the comments.) –  cfr Nov 22 at 23:37
    
@cfr I was asking about the initial attempt. I agree, @DavidCarlisle's comment explains that nicely. I assume that there is no workaround, such as double-escaping e.g. zzz=\\wibble in the same vein as nested arguments ##1 or like shell scripts? –  craq Nov 24 at 8:45
    
@craq you can pre-expand the argument see the added example (below the line) in my answer using \edef –  David Carlisle Nov 24 at 9:53

1 Answer 1

one way is to invert the call structure:

\newcommand\myhead[][2]{%
\headerbox{#2}{#1,textborder=roundedsmall,borderColor=black,
               headerborder=open,linewidth=1,boxshade=plain,boxColorOne=box,
               headerColorOne=head1,headerColorTwo=head2}}


..

\myhead[name=aims,column=0,below=background]{Aims}{
    Aims
}

If you do not want to do that you need to expand \details before passing the keyval optional argument to the macro, one way is

\newcommand{\details}{textborder=roundedsmall,borderColor=black,
                       headerborder=open,linewidth=1,boxshade=plain,
                       boxColorOne=box,headerColorOne=head1,headerColorTwo=head2}

\edef\tmp{%
\noexpand\headerbox{Aims}{name=aims,column=0,below=background,\details}}
\tmp{
    Aims
}
share|improve this answer
    
Thanks for the reply, but unfortunately this doesn't seem to work. I think it might be due to head1 and head2 being custom colours (set with \definecolor)? –  Dan Jan 29 '12 at 0:09
    
@Dan David had missed an open brace. Apart from that, his code should do exactly what you seem to be asking for. Since you are not telling us what packages you are loading, it is impossible to know what "custom colours set with \definecolor" are (also, that would probably be a different question than this one). –  Bruno Le Floch Jan 29 '12 at 0:14

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.