<html><head></head><body bgcolor="#FFFFFF"><div>Hi Jason,<br></div><div><br>On 07/02/2014, at 8:14, "J. McKenzie Alexander" <<a href="mailto:jalex@lse.ac.uk">jalex@lse.ac.uk</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div>Hello,</div><div><br></div><div>I’ve written a simple package which permits conditional inclusion of material with more sophisticated logical constraints on what gets included than can easily be generated with \newif conditionals. But it misbehaves in one context, and I was wondering if there was some clever way around it…</div><div><br></div><div>Let me first describe the package (in case anyone is interested), before I mention the misbehaviour.</div><div><br></div><div>The package is available here, in case anyone wants to try it (bug reports appreciated!):</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre"> </span><a href="https://www.dropbox.com/s/l1vmwlsfui6sbxt/ifkeys.sty">https://www.dropbox.com/s/l1vmwlsfui6sbxt/ifkeys.sty</a></div><div><br></div><div>Here’s how it works… You call a macro called \SetKeys with a comma-separated list of key names (spaces permitted). Those keys are true, all other keys are false.</div></div></blockquote><div><br></div><div>Is \SetKeys called just once, in the preamble say, or do you change the keys throughout the document?</div><div><br></div><div>And is the material that is conditionally supplied complete environments, or can it be material that is inline within paragraphs?</div><div><br></div><div>If inline is allowed, then you will be restricted in various ways; nesting of lots of \if... commands can be very tricky, as you are discovering.</div><div><br></div><div>If you only use full environments, then the comment.sty package can be very useful.</div><div>But the more keys you have, the more \include... and \exclude... environments will be needed, and you may not be able to change the key settings within the body of the document.</div><div>(Not sure on this, as I've not tried it with real typesetting jobs.)</div><div><br></div><div>If all possible combinations of keys need to be supported, then the number of environment definitions goes up exponentially as a power of 2.</div><br><blockquote type="cite"><div><div><br></div><div>Another macro, \ifkeys, is defined, which takes an expression in *disjunctive normal form* as its argument. It then checks whether that expression is satisfied and, if so, evaluates to \iftrue, otherwise \iffalse. The expression uses commas to separate each disjunct, and && to indicate conjunction of key values within each disjunct. And ~ is allowed to specify negation of key values, too. (Since every expression can be written in disjunctive normal form, this allows all logical constraints on keys to be specified, even if at some expense of length.)</div><div><br></div><div>Here’s an example of how it can be used (the number of spaces used in keys doesn’t matter):</div><div><div><br></div><div>\SetKeys{ key one, key two, key three, a really long key name }</div><div><br></div><div>\ifkeys{ key one && key two }</div><div>This is where you put some additional material to be conditionally included exactly when ``key one'' and ``key two'' are both set.</div><div>\fi</div><div><br></div><div>\ifkeys{ key one && ~key three }</div><div>This is where you put some additional material to be conditionally included exactly when ``key one'' is set and ``key three'' is not.</div><div>\else</div><div>You can also use an \verb+\else+ clause to insert material in</div><div>cases where the specified condition is not satisfied.</div><div>\fi</div></div></div></blockquote><div><br></div><div>Do you change the \catcode of & (and ~ ) on the fly?</div><div>I can envision big problems using this within tabular contexts.</div><div><br></div><br><blockquote type="cite"><div><div><div><br></div><div>\ifkeys{a really long key name}</div><div>Keys can have long names with spaces, as well!</div><div>\fi </div><div><br></div><div>\ifkeys{ key one && ~key two, ~key three, ~key four}</div><div>Keys which are not mentioned in \verb+\SetKeys+ are assumed to be false, so this will appear.</div><div>\fi </div></div><div><br></div><div><br></div><div>Ok — now for the problem… The \ifkeys macro cannot be nested with itself or other conditionals, because TeX has a special mechanism for skipping past material at high speeds once it encounters an \iffalse. (It generates the “Extra \fi” error message.) I suspect that there’s no easy / elegant solution for this, but I wanted to ask just in case.</div></div></blockquote><div><br></div><div>This is very hard; indeed impossible to do it this way, I think.</div><div><br></div><div>The reason is that when skipping over the undesired block, \ifkeys will not be expanded.</div><div>This means that its matching \else and \fi will be assumed to delimit the previous \if... .</div><div>Thus your logical structure is not properly captured and you will get those <span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">“Extra \fi” and </span><span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); ">“Extra \else” error messages.</span></div><div><br></div><div>You need your delimiters to always be evaluated.</div><div><br></div><div>Have a look at comment.sty and see whether this is suitable for your actual needs.</div><br><blockquote type="cite"><div><div><br></div><div>Many thanks,</div><div><br></div><div>Jason</div><br><div>
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Prof. J. McKenzie Alexander</div><div>Department of Philosophy, Logic and Scientific Method</div><div>London School of Economics</div><div>Houghton Street, London WC2A 2AE</div></div></span></div></span></div></div></div></blockquote><br><div><br></div><div>Hope this helps,</div><div><br></div><div> Ross</div></body></html>