2
\documentclass[12pt]{article}
\usepackage[test]{optional}

\begin{document}
\def\optname{test}
\optname  \\  % Prints "test"
\opt{\optname}{
    TEST    % does nothing
}\\
\opt{test}{
    TEST 2    % behaves as expected
}
\end{document}

The above minimal example uses the "optional" package to compile different Versions of the same document. Now I'd like to expand it that the \opt command uses a predefined variable to determine in which version which part of the document gets compiled. The Problem is, that it does not accept the variable. I feel it's some kind of expansion issue, but i haven't found any solution yet.

Heiko Oberdiek
  • 271,626
Doomsel
  • 23

1 Answers1

1

The argument of \opt can be expanded by \expandafter. Then the macro will see test directly instead of the option hidden in the macro \optname:

\documentclass[12pt]{article}
\usepackage[test]{optional}

\begin{document}
\def\optname{test}
\optname  \\  % Prints "test"
\expandafter\opt\expandafter{\optname}{
    TEST
}\\
\opt{test}{
    TEST 2    % behaves as expected
}
\end{document}
Heiko Oberdiek
  • 271,626