Tag Info

22

In general, the order of keys does matter where there is some interaction between the keys. That is because keys are normally processed in a left-to-right sense, and so the settings from the 'earlier' keys can be altered by those 'later' in the list. There are cases where internally implementations use multiple pass approaches to setting keys. This is done ...

15

The order is only important if the keys depend to each other. dx is a PSTricks length and it can be used with or without a unit. Without a unit it takes the current value of psxunit into account! And that value is set by the key xunit. That is the expected behaviour of a relative length setting! Using dx with an absolute length (has a unit like \psPiH cm) ...

13

Accepting key-value input can be done using a number of packages, and the general approach is the same for all of them: I covered this in some detail in a TUGboat article. Essentially, there are three things you need to do Define one or more keys; Tell LaTeX to process package options using these keys; Provide a macro for setting keys after package ...

12

Let me provide a simple (but full) example: \ProvidesPackage{myemph}[2011/03/12 v1.0 a test package] \providecommand\my@emphstyle{\em} % Note that the argument must be expandable, % or use xkvltxp package before \documentclass (see manual of xkeyval) \RequirePackage{xkeyval} \DeclareOptionX{style}{% \def\my@emphstyle{\csname my@style@#1\endcsname}} % ...

10

You should use \tikzset{MyStyle/.style={->, red}} instead of a \def to define your own custom style to be applied: \documentclass{article} \usepackage{tikz} \tikzset{MyStyle/.style={->, red}} \begin{document} \begin{tikzpicture} \draw[MyStyle] (0, 0) -- (1, 1); \end{tikzpicture} \end{document}

8

Although any key-value system gives the appearance of "setting properties" of some kind (for example, the numerical parameters of a picture), in fact to some extent they are all "calling methods" instead. I really only know about pgfkeys, which is not what you're asking about, but in that system, keys are as powerful as TeX macros and, therefore, can have ...

7

Marco's already posted a version, but this is I think a bit closer to what you were trying, just fixed the #1/##1 confusion. \documentclass{article} \usepackage{lipsum}% http://ctan.org/pkg/lipsum \usepackage{xkeyval}% http://ctan.org/pkg/xkeyval \newenvironment{realign}[1][] {\let\myalignment\relax\setkeys{fam}{#1}\myalignment}% \begin{realign} {}% ...

6


6

It is a good idea not to change the syntax of standard commands such as \chapter and \section. Although LaTeX allows you to refine any part of the system, taking advantage of that flexibility will make your document fragments hard to process in any other context. You are already using \include which is designed to support partial compilation which appears ...

6

For figure you can use \begin{figure} with no option but before that set the default value: \let\fps@figure\XKV@myStyle@floating@placement@value in general you can \def\zz{\begin{figure}[} \expandafter\zz\XKV@myStyle@floating@placement@value]

5

The default value is used when you specify the key, but don't assign a value: \begin{myenv}[foo] will define \foo to what. Say \newenvironment{myenv}[1][]% {\setkeys{Mystuff}{foo,bar,#1}BEGIN \foo} {END \bar} so that the default values will be applied. Or say \define@key{Mystuff}{foo}{\def\foo{#1}} \define@key{Mystuff}{bar}{\def\bar{#1}} and ...

5

From the documentation of etoolbox: \ifblank{<string>}{<true>}{<false>} Expands to <true> if the <string> is blank (empty or spaces), and to <false> otherwise. The <string> is not expanded in the test. In myclass.cls the macro is called with: \ifblank{\myclass@firstoption}{}{\myclass@firstoption: } ...

5

Summarizing my comments in an answer: First thing is to define the custom setting without \setkeys as a simple list of key/value pairs: \newcommand*\mylstset{keywordstyle=\color{blue}, commentstyle=\itshape\color{red}} Now, the main problem is, that this macro needs to be expanded once before fed to \lstinputlisting: ...

5

Here is a small example using scrbase: \begin{filecontents}{preview.cls} \ProvidesClass{preview}[2012/12/15 v 0.01 class for creating a tight PSTricks diagram] \RequirePackage{scrbase} \DefineFamily{preview} \DefineFamilyMember{preview} \DefineFamilyKey{preview}{PreviewBorder}[0pt]{% \if@atdocument% before or after \begin{document}? ...

5

You need to differential between an initial value (set even if the key is never used) and a default value (used if the key is given with no value). In your example you seem to want an initial value rather than a default. There are several packages which can do what you want: I'd probably use kvoptions for this relatively simple case. ...

5

It works for me with a fully updated Tex Live 2010. Do not use the Ubuntu texlive packages when you want to use fontspec (or any other modern packages). The version in Ubuntu are now more than a year and a half old, and thus have many bugs that have long since been fixed. Install TeX Live directly. There are a few other things worth pointing out: The ...

5

You do not have to use \DeclareOptionX to set up options using xkeyval. As with any other keyval package for LaTeX, anything which is set up as a key will work as an option for the appropriate family. Thus you can use \define@choicekey or \define@boolkey directly: \define@choicekey*{fam}{key}{val1,Val2,VAL3}{You chose: #1} \ProcessOptionsX<fam> ...

4

The xkeyval doesn't provide for auto-initialization of keys. Your best bets are the keyreader and ltxkeys packages; they provide commands that automatically initialize keys to their default values after the keys have been defined. The keyreader package is easier to follow than the ltxkeys package, but of course has fewer features. Here is an example based on ...

4

You have to expand the option list buried in \otherArgs before \setkeys sees that macro: remember that \setkeys doesn't perform expansion. \newcommand{\prefilled}[2][toMakeItMoreComplex]{% \begingroup\edef\x{\endgroup\noexpand\dispKeys[#1]{a=prefilled,#2}}\x } As Martin remarks, this bears some risks, as the expansion is complete, so the values given to ...

4

First of all, \tikzstyle{<key>}=[<value>] is the same as \tikzset{<key>/.style={<value>}} From this point I will only use the \tikzset syntax (→ Should \tikzset or \tikzstyle be used to define TikZ styles?). But you would've had the same problem with \tikzset. The assignment is not a problem, the style TIKZStyle contains ...

4

Rearranging the order of setting keys internally (from a user key-value list) will be expensive. Setting the list twice may make the order of the list less relevant, but the key author has to exercise some caution. Let us assume the following keys. \mp@a depends on \mp@b that comes later, so we have to make the evaluation of \mp@a conditional on knowing ...

4

The right test to use is \ifdefempty \NeedsTeXFormat{LaTeX2e} \ProvidesClass{gaussler}[2013/07/19] \RequirePackage{xkeyval} \def\myclass@firstoption{} \def\myclass@secondoption{} \DeclareOptionX{firstoption}[]{\def\myclass@firstoption{#1}} \DeclareOptionX{secondoption}[]{\def\myclass@secondoption{#1}} \ProcessOptionsX\relax \LoadClass{memoir} ...

3

By rereading the documentation of kvoptions once more, I figured it out myself. This is the result: \RequirePackage{expl3,kvoptions,siunitx} \SetupKeyvalOptions{family=threshold,prefix=threshold@} \DeclareStringOption[1]{low}[0.01] \DeclareStringOption[1]{high}[100] \ProcessKeyvalOptions* \sisetup{scientific-notation=true} \ExplSyntaxOn \cs_new_eq:NN ...

3

You are trying to use an option for version 2 of siunix but have version 1 installed. You should always check the manual for the version of siunitx (or any other package) you have installed to see what is valid. Here texdoc siunitx at the Terminal will show you that there is no per-mode option in version 1, but rather an option simply called per. As you ...

3

There's no \XKV@myStyle@floating@placement@value defined when you do \define@cmdkey[myStyle]{floating}{placement}{} The macro that stores the value is instead \cmdmyStyle@floating@placement. So here's what you probably want to do: \documentclass{article} \usepackage{xkeyval} \usepackage[demo]{graphicx} \usepackage{lipsum} \makeatletter ...

3

The definitions are made within the first cell of the tabular and don't survive to the next cell. You need to make their definitions global so they can span multiple columns. If you change \def to \gdef in the key definitions it will work. \documentclass{article} \usepackage{xkeyval}% http://ctan.org/pkg/xkeyval \begin{document} \makeatletter ...

3

Without \gdef; this has the advantage that if you need to omit some entry, you just don't set the key (provided you set up at the beginning an empty value for each key). \documentclass{article} \usepackage{xkeyval} \makeatletter \define@key{myrowkey}{name}{\def\MyRowName{#1}} \define@key{myrowkey}{num}{\def\MyRowNum{#1}} \newcommand\myrow[1]{% ...

3

In the minimal example, the graphics package is implicitly loaded. But the command \includegraphics[width=4in]{anyfile.eps} requires graphicx because of the key=value syntax in the optional argument. That's why the compilation must fail. It's probably good to update to the most recent versions of chemstyle and siunitx. Ubuntu packages might be not ...

3

If \otherArgs is actually added by some internal code, not by the user directly, you can expand it first and add the expanded code at the right position using an auxiliary macro as shown by \withotherargs and \@withotherargs below. If the \otherArgs comes from the user instead you can provide a second argument to pass such a macro. \documentclass{article} ...

3

A more universal and robust solution turned out to be cheaper than I had thought. I choose to normalize the key-value set because without first normalizing the list the scheme of pre-expanding each keyname will not always work. This is because the \expandafter may simply act on a blank space. Normalization also deals with active commas and equal signs. ...

Only top voted, non community-wiki answers of a minimum length are eligible