3

I am making a lualatex-based class, which will be a thin wrapper around a lua library. I would like to use the luakeys package to process my options in lua, and would like to avoid declaring options. My question is two-fold:

  1. Can I allow the package I'm writing to accept arbitrary options?
  2. How would I retrive the options as a string in lua?

MWE:

\ProvidesPackage{MWE}

\RequirePackage{luapackageloader}
\RequirePackage{luacode}

\DeclareOption*{} % I think this is sufficient to allow arbitrary options.. 
\ProcessOptions\relax

\begin{luacode*}
    texio.write_nl('VVVVVVVVVVVVVVVV')
    texio.write_nl(token.get_macro('@nameuse{opt@MWE.sty}'))  -- isn't this
    texio.write_nl(token.get_macro('@classoptionslist'))       -- isnt this

    local luakeys = require('luakeys')
    local kv = luakeys.parse(token.get_macro('???')) --is there a command, or way I can get the raw options
                                                                   --  that were passed to this package as a str ?
    texio.write_nl('VVVVVVVVVVVVVVVV')
    luakeys.print(kv)
\end{luacode*}
6

The macro you want to access for the raw options is \@raw@opt@<file>.<ext>. And to prevent LaTeX from throwing errors on unknown options you should do \let\@unprocessedoptions\relax.

So this here is what you want:

\ProvidesPackage{MWE}

\RequirePackage{luapackageloader}
\RequirePackage{luacode}

\begin{luacode*}
  local luakeys = require('luakeys')
  local kv= luakeys.parse(token.get_macro('@raw@opt@MWE.sty'))
  luakeys.print(kv)
\end{luacode*}
\AtEndOfPackage{\let\@unprocessedoptions\relax}% don't throw errors for option

\endinput

And using this driver file:

\RequirePackage[my=opt, opt=key]{MWE}
\stop

You'll get the following on the terminal output:

{
  ['opt'] = 'key',
  ['my'] = 'opt',
}

Caveat: Your options still need to survive one \edef assignment without breaking due to the way LaTeX handles options historically.

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.