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

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


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


12

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


12

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


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


10

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


8

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.


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

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

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

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

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.


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

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

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

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

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


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

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


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



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