Put all package options into one command

The title might not be perfect, but what I want to achieve is:

Inside my own package mypackage.sty, I would like to have a command, say \allpackageoptions, which should have stored the entire package option string. Like this:

Example Code

Document (mydocument.tex):

\usepackage[Lorem Ipsum Dolor]{mypackage}


Package (mypackage.sty):

[...]
\allpackageoptions % shoud output 'Lorem Ipsum Dolor'
[...]


Background

What I would like to achieve with this is to write a small package that simplifies the use of svn keywords. (I know there are some packages out there, but I want something really tiny and simple). SVN can automatically insert a string containing version information whereever I want whenever I commit the file. Look at this:

\documentclass{article}

\def\svn $Id: #1 #2 #3-#4-#5 #6${%
This file is revision r#2.
}

\begin{document}

\svn $Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$
%This string inside  is automatically updated by SVN

\end{document}


The output of this example code is obviously This file is revision r259. My package would provide this interface:

\usepackage[$Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$]{mysvn}


and should provide a command \svnrevision which outputs 259.

-
Which keyval package do you use? However options are separated by commas. In your case there is no comma and everything can be save in a single token. –  Marco Daniel Apr 20 '13 at 11:30
I usually use kvoptions or the default DeclareOption-solution – but I am open for everything. –  ralfix Apr 20 '13 at 11:41
kvoptions saves all options inside the command \KVO@classoptionslist –  Marco Daniel Apr 20 '13 at 11:46

The main problem with the option approach is that LaTeX removes the spaces inside the option.

\usepackage[$Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$]{mysvn}


The package will see:

$Id:somefile.tex2592013-04-2013:22:00Zralfix$


That will make the parsing much more cumbersome. Also curly braces will not help:

\usepackage[{$Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$}]{mysvn}


The braces are already stripped by \usepackage, when it reads its optional argument. This can be prevented by an additional empty option:

\usepackage[,{$Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$}]{mysvn}


Or using a key value interface:

\usepackage[id={$Id: somefile.tex 259 2013-04-20 13:22:00Z ralfix$}]{mysvn}


Packages kvoptions-patch and xkvltxp redefine LateX internals for a better support of spaces and macros inside LaTeX options. But they have to be loaded before such options are used.

Package kvoptions can be used to catch the local options, e.g.:

% mysvn.sty
% Syntax: \usepackage[,{$Id: ...}]{mysvn} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{mysvn}[2013/04/20 SVN version number] \RequirePackage{kvoptions}[2009/07/17] \DeclareDefaultOption{% % dummy actions % * print option value on screen \typeout{[\CurrentOption]}% % * remember option value in \mysvnid \let\mysvnid\CurrentOption } \ProcessLocalKeyvalOptions* \endinput  Example with a key-value option: % mysvn.sty % Syntax: \usepackage[id={$Id: ...}]{mysvn}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mysvn}[2013/04/20 SVN version number]
\RequirePackage{kvoptions}[2009/07/17]

\SetupKeyvalOptions{
family=mysvn,
prefix=mysvn@,
}
% Store value of option id' in \mysvn@id:
\DeclareStringOption{id}
\DeclareLocalOptions{id}% global id' options are ignored
\ProcessKeyvalOptions*
\endinput


Much easier would be a macro interface without options at all:

\usepackage{mysvn}
\mysvn{\$Id: ...}


I would left the parsing of the SVN identification string to a specialized package:

• Parsing of a full Id string.
• Parsing of a compressed Id String, when subversion has not yet written the full Id string.
• Error handling, if the string is not an Id string.
-
Until now, I do not need a full-blown package with extended parsing abilities – my simple approach is enough. Thank you for the idea with the macro interface, regarding the "problems" with space-removal this is the simplest way. –  ralfix Apr 22 '13 at 16:26

The options passed to the package foo.sty are saved in the macro \opt@foo.sty so you can simply do

\newcommand\alloptionslist[1]{\@nameuse{opt@#1.sty}}


The output is just the contents of the optional argument to \usepackage, without any interpretation. But it's easy to manage a comma separated list.

-
Thank you! This answers my question about a command which holds the entire options... however concerning my special case I need the spaces to be kept. –  ralfix Apr 22 '13 at 16:24