8

I would like to know if there's a way to use a command (including custom commands created with \newcommand) as parameter/option values). I would like to do something like this

\usepackage[someoption=\somecommand]{somepackage}
\usepackage[supporters={First line\\ Second Line}]{someotherpackage}
4
  • Not unless you are altering the package itself and adding your options.
    – Mica
    Commented Jan 6, 2010 at 0:23
  • Also note that package options are fully expanded, which makes them sort of impossible to use for anything like this. (Not so with keyval options, though.) Commented Jan 6, 2010 at 2:58
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Commented Jul 27, 2012 at 17:10
  • The original question has been edited into an entirely different one. This is not allowed! The editor should ask their own question. The initial question was about passing option values via \documentclass, not via \usepackage.
    – Ahmed Musa
    Commented Nov 26, 2012 at 11:44

2 Answers 2

5

If you load the xkvltxp (or kvoptions-patch or catoptions) package before \documentclass, you will be fine: you can pass commands as values of options. To load a package before \documentclass, you should of course use \RequirePackage instead of \usepackage.

1

Two options

  1. You can check to see if a csname is defined using \ifdef in the package, so that defining \csname as a macro before invoking \usepackage can be checked. This isn't exactly what you asked, but it should, I guess, do what you want;
  2. You can pass the name of a command as a string without the backslash (say, to \input) in the options, and then bind the command using \edef\inputcs{\def\passname#1{\csname#1\endcsname}\expandafter\passname\input}.

You must log in to answer this question.