Tag Info

Hot answers tagged

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 ...


16

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}} % ...


16

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 ...


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) ...


12

pgfkeys.sty, part of PGF/TikZ Author: Till Tantau


12

kvoptions.sty Author: Heiko Oberdiek Supports keyval processing of package/class options.


11

The big problem is that you want to pass to \write commands such as \textbf or \textcolor that don't survive it. The kernel has \protected@write for this, but no “immediate” version. However, it's easy to define one as done in How to write the € symbol into a file, when using Package [utf8]{inputenc} You also must ensure that \textcolor is protected, ...


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}


10

A possible solution with LaTeX3 key-value interface: tmpsty.sty \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{tmpsty}[2013/09/24 Standard Style File For Assessments At SHJC] \RequirePackage[letterpaper,tmargin=2cm,bmargin=2cm,lmargin=2.5cm,rmargin=2.5cm,showframe]{geometry} \RequirePackage{amsmath,amssymb,amsfonts} \RequirePackage{booktabs,array} ...


9

keyval.sty Author: David Carlisle The original and (probably) most widely used keyval package. Provides \define@key and \setkeys but all processing for special key-types must be done manually. Removes one or two layers of braces around each "val". Note: this package can have scope problems with nesting \setkeys. Nowadays I'd recommend a more modern ...


8

l3keys.sty, part of expl3 Author: Joseph Wright (through the LaTeX3 Project) Inspired by pgfkeys. Use l3keys2e to use it in options of LaTeX2e packages and classes.


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} {}% ...


7

Use \PassOptionsToClass instead of \PassOptionsToPackage.


7

Firstly @ is made a letter in package and class files automatically. \DeclareOptionX{style}{% \def\my@emphstyle{\csname my@style@#1\endcsname}} The xkeyval package uses this to define what happens when in the document you go \setemph{style=bold} basically the (x)keyval parser uses the macro defined by the declaration and passes it the value (the part ...


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]


6

xkeyval.sty Author: Hendri Adriaens Cannot be loaded before \documentclass. Note: in the past controversial because it overwrites keyval's \setkeys macro and in some cases caused (long-standing) incompatibilities. But I believe any problems resulting from this are now fixed.


6

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> ...


6

You can test the argument of define@boolkey. It's easier to handle: \newcommand{\newboolkey}[1]{% \define@boolkey{fam}[@bool@]{#1}[true]{% \in@{true}{##1} \ifin@ \setkeys{fam}{align=#1}% \fi }% } If you want to use your code you can use: \newcommand{\newboolkey}[1]{ \define@boolkey{fam}[@bool@]{#1}[true]{% \csname ...


6

Note that \setkeys doesn't expand its second argument. I'm not sure what you're after, but this works. \documentclass{article} \usepackage{etoolbox} \usepackage{xparse} \usepackage{xkeyval} \makeatletter \define@key{myfam}{somekey}{% \def\somekeyvalue{#1}% } \define@key{myfam}{someotherkey}{% \def\somekeyothervalue{#1}% } \makeatother ...


6

The key value parser sees \pgfkeysvalueof{/test/options} as option list. Since there is no equal sign or comma, it is interpreted as key only. The example is fixed by expanding the option list first, see the \expandafter in the example which expands \romannumeral-`\x, which then triggers the expansion of \pgfkeysvalueof{/test/options} until \romannumeral ...


5

The command \setkeys{METest}{wide=false} sets this key to false, so you have no chance to provide another value. \setkey should be inside the macro using the syntax \setkeys{METest}{wide=false,#1}, such that a possible override within #1 of the key value is handled. You can specify a default value to an option, using the [] syntax as I have done with the ...


5

You have to use \expandafter\forcsvlist\expandafter {\expandafter\index\expandafter}% \expandafter{\KVMacroCSVList} Yes, five of them, because you want to expand the list macro before \forcsvlist acts upon it. A different approach with expl3: \documentclass{scrbook} \usepackage{imakeidx} \usepackage{xparse} \makeindex \ExplSyntaxOn ...


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

As of version 0.9b, Biblatex renamed the defernums option to defernumbers http://www.tex.ac.uk/CTAN/macros/latex/exptl/biblatex/RELEASE


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

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

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

When \setkeys examines the key-value pairs it does no expansion; something like \begin{itemize}[label=\arabic*] would tragically fail if this was used. So, in your second case, \SomeKeyValue is passed without any expansion as the value for DummyBoolKey and it's illegal, because this key wants either true or false (or nothing at all, which would be ...



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