1

When I try to put in my package options with not yet defined macro (even if I use noexpand), the document fails to compile (even if I don't use the macro!). Any idea if it's fundamental or not? (I tried with kvoptions, but also with the regular system) Ideally I'd like to avoid \noexpand but for now any solution is interesting!

MWE:

test.tex:

\documentclass{article}
\usepackage[conf={I would like to use not (yet) defined macro here}]{teststy}
% Uncommenting the following line produces errors:
% \usepackage[conf={The value is: \noexpand\number\noexpand\value{counterAllProofEnd}}]{teststy}

\begin{document}
\section{Options}
\show\pratendOptconf
\newcounter{counterAllProofEnd}
\pratendOptconf %% Should display "The value is: 0"

\stepcounter{counterAllProofEnd}
\pratendOptconf %% Should display 1 "The value is: 1"

\end{document}

teststy.sty:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{teststy}[2019/05/06 A test]

\RequirePackage{kvoptions}

%% https://tex.stackexchange.com/questions/109747/put-all-package-options-into-one-command
%% Forward the options list to the command \pratendOptdefconf
%% in order to use:
%% \usepackage[conf={normal}]{proofAtTheEnd}
\SetupKeyvalOptions{
  family=pratendOpt,
  prefix=pratendOpt,
}
\DeclareStringOption{conf}
\DeclareLocalOptions{conf}% \pratendOptdefconf contains the proof
\ProcessKeyvalOptions*

% \DeclareOption*{\PackageWarning{proofAtTheEnd}{Unknown}}
% \ProcessOptions\relax

\endinput
4

Currently (although there may be plans to change this) the options argument is normalized by the standard option handling code before being passed to the package and so before being accessed by the kvoptions code used by the package.

Basically that means that the code passes through \edef and has white space removed.

That means that it is only really safe to have "classic" valueless options to a package [dvips], [fleqn] etc. In some cases you can make key=value options work but only if they are safe in an edef.

This is why for example hyperref allows kvoptions in the package option list but provides (and recommends) specifying the options separately via \hypersetup{...} which is only parsed by the keyvalue parser and so does not pre-expand the argument.

  • Ok thanks. But why "noexpand" does not work then if it goes through an edef? – tobiasBora May 7 at 12:01
  • 1
    @tobiasBora there are multiple edefs scattered around..... – David Carlisle May 7 at 12:08

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.