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


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


14

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


13

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}


9

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


8

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


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

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

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

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

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


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


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

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


5

Keyval implements tend to be very careful not to expand input 'out of order', and thus the problem you see is not xkeyval-specific. For keys which take a fixed list of choices, which includes boolean keys, this deliberate behaviour means that \def\myvariable{some-valid-input} \KeySettingCommand{valid-key-name=\myvariable} will not work. As a result, you ...


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


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


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