Hot answers tagged

9

as plain tex but works in latex as well: \def\mycommand{1\gdef\mycommand{2}} \mycommand \mycommand \mycommand \bye


6

Note that \usekomavar has a starred version and can take an optional argument. So it is not fully expandable. So it can not be used inside \pdfstrcmp or the KOMA-script command \ifstr. I have asked Markus. The optional argument can be used for commands like \MakeUppercase which influences the contents of its argument (that is explained in the manual) but ...


5

the main culprits are the incorrect use of % after the 1 which prevents the 1 being terminated, and the lack of a space after 0. In some cases you can terminate a number with \relax but that leaves a \relax in the token stream which is not always desirable, a space is absorbed as part of the number. \newcount\animalnum \def\nextanimal{% \ifcase\animalnum ...


5

Several ways, one way to do it with two \expandafter is \documentclass{standalone} \def\myvar{foobar} \begin{document} \makeatletter \in@{foo}{foobar}\ifin@ Yes\else No\fi, \def\zz{\in@{foo}} \expandafter\zz\expandafter{\myvar}\ifin@ Yes\else No\fi \makeatother \end{document}


5

\in@ doesn't expand its arguments; you can easily define a new macro \ein@ that expands (once) its argument: \documentclass{article} \def\myvar{foobar} \makeatletter \def\ein@#1#2{% \expandafter\ein@@\expandafter{#2}{#1}% } \def\ein@@#1#2{\in@{#2}{#1}} \makeatother \begin{document} \makeatletter \in@{foo}{foobar}\ifin@ Yes\else No\fi, ...


5

You can just set a "toggle", which starts out as being false, and is set to true once you've received the special input. Below I've made an \if that represents this toggle: \documentclass{article} \makeatletter \newif\if@mycommand@special \newcommand\mycommand[1]{% \ifnum\pdfstrcmp{#1}{7}=0 % Compare argument to "7" (or something special) ...


4

Use \ifnum instead of \ifx. \documentclass{article} \newcounter{counterA} \newcounter{counterB} \setcounter{counterA}{2} \setcounter{counterB}{2} \newcommand\maccommand{% \ifnum\the\value{counterA}=\the\value{counterB} Just so you know, counterA (= \the\value{counterA}) holds the same value as counterB (= \the\value{counterB}).% \else ...


3

\thecounterA works only if the counter wasn't redefined: \documentclass{article} \newcounter{counterA}\renewcommand\thecounterA{A\arabic{counterA}} \newcounter{counterB}\renewcommand\thecounterB{B\arabic{counterB}} \setcounter{counterA}{2} \setcounter{counterB}{2} \newcommand\maccommand{% \ifnum\value{counterA}=\value{counterB} Just so you know, ...


3

LaTeX has such a test built in already, so you just need to define your requested syntax: \documentclass{article} \makeatletter \newcommand\ifmember[2]{% \in@{#1}{#2}% \ifin@ \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } \makeatother \begin{document} \ifmember{elem1}{elem1,elem2,elem3}{true}{false} ...


3

This might be a simple typing error. In your \ifnum you use \hasbeenseen but everywhere else it's \hasbeencalled. If you change it you get a working \documentclass{article} \begin{document} \def\hasbeencalled{0} \newcommand\mycommand[1] { \ifnum\hasbeencalled=0 1 \global\def\hasbeencalled{1} \else 2 \fi } \mycommand{} ...


2

Your Z-column definition is malformed or incomplete. Since it seems like you only want to condition on whether the user supplies left, center or right, here's how you can achieve that: \documentclass{article} \usepackage{array,colortbl} \newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}} \newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} ...


2

You can certainly do, in plain TeX, \newcount\counterA \counterA=2 \ifx\counterA>2 Just so you know, counterA is greater to than 2. \else Just so you know, counterA is not greater than 2. \fi but this will compare the token \counterA with the token > and find they've different meanings, so everything up to \else will be gobbled and you'll ...


2

It's easy. ;-) With \newcommand{\myletterwriter}[1]{\renewcommand\myletterA{#1}} the macro \myletterA is \long, whereas \cachedata is defined with \def that makes it non \long. Just do \newcommand{\myletterwriter}[1]{\renewcommand*\myletterA{#1}}


2

Here is a solution without using any special package: \newcount\tmpnum \def\definestepfunction#1#2#3{% \def#1##1{\def\sfv{##1}\dostepfunction#2;;\end#3\endgame} } \def\dostepfunction#1;{% \ifdim\sfv pt<#1pt \outofrange \fi \dostepfunctionA#1;% } \def\dostepfunctionA#1;#2;{% \ifx;#2;\outofrange \fi \advance\tmpnum by1 \ifdim\sfv ...


2

There are many ways to do this. Here is one using a single, primitive \if (since you only have two courses): Course: math Teacher: Bill \documentclass{article} \newcommand{\course}{% \ifmathcourse math% \else% not mathcourse physics% \fi } \newcommand{\teacher}{% \ifmathcourse Bill% \else% not mathcourse Susan% \fi } ...


2

This version adopts etoolbox, very powerful package for setting conditions. I guess it could be included in the \tikzset but I'm not sure how yet. I'll edit the answer in case. Output Code \documentclass[margin=10pt]{standalone} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{tikz} ...


2

Here's a way of doing it with PGF keys and a couple of macros. It allows you to say \tikzset{% S1 set={3,5,8}, S2 set={1,4}, } for example, to determine which nodes should take each of styles S1 and S2. It is probably a bad idea to name nodes using numbers alone, but I've not changed this in the code below. (Giving each a standard prefix is an easy ...


1

Thanks to @jfbu's comment, I added the following \def statements to my preamble. \def\useParens{\isstrcmp{\subParen}{parens} \ifstrcmp \def\whichIndex{\subIndex} \else \def\whichIndex{\parenIndex}\fi} \def\useSubs{\isstrcmp{\subParen}{sub} \ifstrcmp \def\whichIndex{\subIndex} \else \def\whichIndex{\parenIndex} \fi} Now, if I type \useParens or \useSubs in ...


1

Frankly said, I do not understand what you doing in your code and what should be your result, so the main purposes of this answer is clarify this. The MWE below generate this picture: where colors are select on basis even/odd number in \label: \documentclass[10pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage{amsmath,amsfonts,amssymb} ...


1

Just set up suitably the third argument of \definetestfunction, where you can use #1 to refer to the argument passed to \test (or whatever name you choose for the function). \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\definestepfunction}{mmm} { % #1 is the function's name % #2 is the semicolon separated subdivision ...


1

Based on the answer given by John Kormylo, and after reading the doc of pgf, I got a more simple solution based on pgfmaths, which is applicable on more general cases. The following program tests in which interval is a value, for the intervals with bounds are (for example) \bzero=0, \bone=1.7, \btwo=2.3, \bthree=5.6. \documentclass{article} ...


1

I can offer you an expl3 interface: \documentclass{article} \usepackage[table]{xcolor} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\NewArray}{mm} { \seq_new:c { g_aloui_array_#1_seq } \seq_set_from_clist:cn { g_aloui_array_#1_seq } { #2 } } \NewDocumentCommand{\PrintArray}{mmmm} {% #1 = array name, #2 = treshold, #3 = lower color, #4 = ...


1

There is no “if token list begins with” predefined function. You can build it easily with l3regex: \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\whatever}{} { \tl_use:N \g_macmadness_whatever_tl } \tl_new:N \g_macmadness_whatever_tl \cs_generate_variant:Nn \regex_match:nnTF { nV } ...


1

Here's a quick expl3 (well, xparse method, for checking whether the second argument is in the list. However, the clist-variable would be in a command macro, usually,otherwise you would know if it is in the list. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\IsMember}{mm+m+m}{% \clist_set:Nx \l_tmpa_clist {#1} ...



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