TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'


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:


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


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


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.

share|improve this question
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
up vote 6 down vote accepted

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:


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}
\ProvidesPackage{mysvn}[2013/04/20 SVN version number]

  % dummy actions
  % * print option value on screen
  % * remember option value in \mysvnid

Example with a key-value option:

% mysvn.sty
% Syntax: \usepackage[id={$Id: ...}]{mysvn}
\ProvidesPackage{mysvn}[2013/04/20 SVN version number]

% Store value of option `id' in `\mysvn@id`:
\DeclareLocalOptions{id}% global `id' options are ignored

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

\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.
share|improve this answer
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


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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.