New answers tagged

3

Possible: yes, but it's necessary to change it most times by hand anyway. The main culprit is that different classes provide different features and some of them are contradictory to each other,i.e. one has to make conditionals to choose the correct settings afterwards anyway. \newcommand{\mode}{1} \ifnum\mode=0 \documentclass{article} \else ...


4

I revised my MWE to answer some of the criticisms about the difficulties encountered by having a selectable document class. In the MWE, if I choose the article class, I also redefine other things (in this case \chapter) to make it compatible with the alternate class, which is book in this case. With such an extended approach, one can quickly alternate ...


2

Note that \include should be \input, but it's not the problem. The issue is that \rowcolor must be the first item in a row, after expansion, so you need to use an expandable test, which \ifthenelse isn't. With etoolbox it's easy. By the way, beamer already loads xcolor, so in order to load colortbl it's best to pass it the table option, which is done by ...


4

Try this. \documentclass{beamer} \usepackage[utf8]{inputenc} \usepackage{tabularx,colortbl} \usepackage{xcolor} \usepackage{ifthen} \def\kw{2} \begin{document} \begin{frame}{Title} \begin{tabularx}{\textwidth}{|c|X|} \hline Bla & Blabla\\ \hline \hline 1 & something\ifthenelse{\equal{\kw}{2}}{\\\rowcolor{red}}{\\}% ...


3

Remove the suffix true from the \ifbabel@.... queries! You must use \ifbabel@french etc for the query, but \babel@frenchtrue or \babel@frenchfalse to set the state of the 'variable'. Change \documentclass[report] to \documentclass{report} \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{failedpackage} \newif\ifbabel@french \newif\ifbabel@english ...


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


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


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


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


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

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


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

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


0

Here is a pgfmath version: \documentclass{article} \usepackage{pgfmath}% part of the tikz package \newcommand{\steps}[1]% #1 = unknown real (text) {\bgroup% local definitions \pgfmathint{#1}% or \pgfmathparse{int(#1)} \let\less=\pgfmathresult \pgfmathparse{int(ceil(#1))} \let\more=\pgfmathresult $\less \leq #1 \leq \more \Rightarrow #1 \in ...


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


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

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


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

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}


0

You do not need LaTeX for this, only R: if (file.exists("data.dat")==TRUE) cat("yes") else cat ("no")


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


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


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


9

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


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



Top 50 recent answers are included