2

I try to write a little package for my personal use. For this I use kvoptions. Now I have to give a string to one of the options which contains \\ but this fails with: undefined control sequence. \let \reserved@e.

My texfile looks like this:

\documentclass{scrlttr2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[myoption={Street\\City}]{mypackage}

\begin{document}
\begin{letter}{some name}
\opening{Dear ...}
\closing{Regards ...}
\end{letter}
\end{document}

And the content of the .sty-file:

\ProvidesPackage{mypackage}
\RequirePackage{kvoptions}
\SetupKeyvalOptions{
    family=mypackage
    ,prefix=mypackage@
}
\DeclareStringOption[]{myoption}[]
\ProcessLocalKeyvalOptions*\relax
\setkomavar{fromaddress}{\mypackage@myoption} %just for example

In reality I do more than just that with myoption but I need it to accept \\ in the string. This is the only problem. As long as I don't use \\ in the strings everything works fine. I can use a default for the option like this:

\DeclareStringOption[Other street\\Other city]{myoption}

Inside of the .sty but the moment I want to enter another value for myoption containing \\ it fails. How is it possible to allow such characters in the options?

EDIT: added the \ProcessLocalKeyvalOptions

  • 1
    Your package misses \ProcessLocalKeyvalOptions*, but that's not the solution – user31729 Jan 7 '17 at 19:02
  • Oh, just forget that in the MWE... But thanks, I'll edit it :) – Skillmon Jan 7 '17 at 19:04
  • 2
    really latex doesn't support this (\\ dies in the package loading code before kvoptions can see it.) You'd have to load a package that redefined \usepackage before you used an option in this way – David Carlisle Jan 7 '17 at 19:07
  • @DavidCarlisle that's too bad. But thanks for the clarification. Do you by any chance know any package that does that or can pinpoint me in the right direction? – Skillmon Jan 7 '17 at 19:11
  • 2
    kvoptions ought to but I just tried loading it earlier with no effect, there are other packages that define key=value package option handling (I forget which:-) or just put \let\\\relax before the package load (and put it back afterwards) – David Carlisle Jan 7 '17 at 19:12
2

You would need to load a package that redefines \usepackage to make this safe before the \usepackage call that uses the option. Unfortunately just loadingkvoptions` earlier doesn't seem to work. There are other packages that define key=value package option handling (I forget which:-) or just put

\let\savednl=\\
\let\\=\relax 

before the package load and put it back afterwards with

\let\\=\savednl

then it will be safe during the package option handling, but back to normal by the time you use the option value.

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.