# Special characters in kvoptions (like \\)

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


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

• 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 likes topanswers.xyz Jan 7 '17 at 19:04
• 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 likes topanswers.xyz Jan 7 '17 at 19:11
• 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

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\\=\savednl
`