1
\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.

  • 1
    Welcome to TeX.SX! Please make your example compilable. – TeXnician Nov 19 '17 at 11:19
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}

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.