# Tag Info

6

There has been no change to \InputIfFileExists since 1995/05/25 so unless you have not upgraded for a long time the system upgrade is probably unrelated. However a better, more portable, and more efficient, markup here would be \documentclass{amsart} \input{macros} \begin{document} text \end{document} or better still rename macros.tex to macros.sty and ...

12

TL;DR: You're actually looking for \IfFileExists{/Mac/path/macros.tex}% {\input{/Mac/path/macros.tex}} {\input{/linux/path/macros.tex}} The macro \InputIfFileExists{<file>}{<true>}{<false>} takes three arguments: the file to check the existence of, the <true> code to execute before inputting the file in case it is found and ...

3

Here comes some sort of safety-belt with(out eTeX) bloatware: \documentclass{article} \makeatletter %%---------------------------------------------------------------------- %% Check whether argument is empty: %%...................................................................... %% \@CheckWhetherNull{<Argument which is to be checked>}% %% ...

4

If arguments 2 and/or 3 are blank, they are omitted, along with the space that follows. \documentclass{article} \newcommand{\entry}[4]{\framebox(7,7){}\hspace{.75em}\markboth{#1}{#1}\textbf{#1}\ % \ifx\relax#2\relax\else{(#2)}\ \fi% \ifx\relax#3\relax\else\textit{#3}\ \fi% $\bullet$\ {#4}} \begin{document} \entry{Purfling}{pur-fling}{Guitar ...

2


1

I marked egreg's answer as accepted, because it actually answered the question as written. I ended up solving the problem a slightly different way and am posting this answer in case it benefits anyone else. I ended up using a \newif. \newif\iftestEmptyBool \newcommand{\testEmpty}[1]{\setbox0=\hbox{#1}\ifdim\wd0=0pt \testEmptyBooltrue\else ...

0

If you don't mind an additional package, pgffor is quite handy to provide foreach-loops. \documentclass{article} \usepackage{graphicx} \usepackage{pgffor} \begin{document} test \foreach \n in {1,...,2}{ \ifnum\n=2% \includegraphics{pic}% \fi% } \end{document}

1

Something like this? \documentclass{article} \begin{document} \newcount\group \newcount\subj \newcount\nors \group=0 \loop \advance\group by 1 \subj=0 {\loop \advance\subj by 1 \nors=0 {\loop \advance\nors by 1 { group \the\group, subject \the\subj, run \the\nors \par \ifnum\group=2 ...

7

The \newif command doesn't check whether the conditional is already existing; the assumption is that a programmer using \newif knows what she/he is doing. If you want an interface like \newcommand, load ifthen and use \newboolean; in this case \newboolean{x} would tell you ! LaTeX Error: Command \ifx already defined. Or name \end... ...

5

Your code is doomed to failure. The conditional \if tests character code equality of the next two unexpandable tokens it finds after it, performing expansion until unexpandable tokens remain. So \if{\tmpOne}{hello} goodbye \fi sees {, which is unexpandable and then expands \tmpOne; after this expansion the input stream is \if{hello}{hello} goodbye \fi ...

5

You can add another guard within the ln and give a safe value (1 here) it doesn't really matter what non-error value you use as it will not affect the result of the outer guard \documentclass{article} \usepackage{tikz} \begin{document} \def\var{0} \pgfmathparse { \var>1 ? ln(\var>1 ? \var:1) : \var}\pgfmathresult \def\var{1} \pgfmathparse { ...

4

In LaTeX, Version dates can be declared by: \ProvidesClass{<class name>}[YYYY/MM/DD ...] \ProvidesPackage{<package name>}[YYYY/MM/DD ...] \ProvidesFile{<file name>}[YYYY/MM/DD ...] and LaTeX provides: \@ifclasslater \@ifpackagelater \@iffilelater is missing and both commands can only be used in the preamble. Package ltxcmds closes ...

5

The babel language files use \ProvidesFile with some version information argument -- this setup is necessary to use the LaTeX core macro \@ifl@ter to check the file date, if it is applied with the correct extension. It checks the file date, see the definition and the usage in latex.ltx: \def\@ifl@ter#1#2{% \expandafter\@ifl@t@r \csname ...

1

I think the easiest way to do this is probably to define a colour newcol, say, which you then set appropriately. This avoids the problems caused by trying to deal with the colour setting while actually testing. Minimising the example a bit: \documentclass{article} \usepackage{tikz} \usepackage{ifthen} \definecolor{newgreen}{RGB}{173,194,0} ...

2

I admit I don't fully understand what you're trying to do here, but as egreg notes, \begin and \item are fragile which is what's causing the problem. It's easy enough to "fix" this particular example \newcommand{\wrapper}[1]{% \test{% \begingroup \let\begin\relax \let\item\relax \let\end\relax \protected@edef\x{% ...

0

The following approach allows skipping of \outer tokens and skipping things like instances of the verbatim environment as well. Be aware that you cannot hide \mySkip{...} within other macros or within macros' arguments and that \mySkip should not be "renamed" (via \let). Matching \mySkip{...}-pairs must not come from macro-expansion but they must occur ...

0

Delimited arguments might be your friends. Ulrich \documentclass{minimal} \makeatletter %%------------------------------------------------------------------------- %% Check whether argument is empty: %%......................................................................... %% \CheckWhetherNull{<Argument which is to be checked>}% %% ...

4

It is not possible to emulate conditionals (\iftrue, \iffalse, \else, \fi) by macros, because TeX's scanning for \else and \fi does not involve macro expansion. The conditional commands can only be assigned to other names (via \let). The starting conditional can be hidden inside macros as long as it is not inside the branch of another conditional. Example ...

2

Your definition of the teachr environment is incorrect. You're probably after something like this: \usepackage{environ} \NewEnviron{teachr} {\ifthenelse{\boolean{teach}}{\BODY}{}} The above uses the environ package to define teachr and condition on the teach boolean. If it's set to true, \BODY is set, otherwise teachr gobbles its entire contents. One ...

1

A very rudimentary version since there is no clue provided how the 'versions' are organized. Use a \newif\ifversionA switch and set it to true with \versionAtrue or false with \versionAfalse. \documentclass{article} \newif\ifversionA \versionAtrue \begin{document} Person X \ifversionA -- is so dreamy \else -- is not really lovely \fi ...

0

Inspired by David's comment (Thanks!), I found this solution: \documentclass{article} \usepackage{needspace} \usepackage{blindtext} \begin{document} \blindtext[3] \needspace{200pt} \blindtext[2] \end{document}

0

Another answer from the perspective of "you don't need variable variables". This uses \long\def and adds a \vtop box to the material under the line. \documentclass{article} \usepackage{setspace} \long\def\sigblockB#1#2#3%\long\def allows for paragraphs { \singlespacing \vskip.75in\noindent\hskip#1in% \hbox ...

5

biblatex has a host of commands for that. There are (see pp. 199-200 of the biblatex doc) \ifinteger to check if the given argument is a positive integer \ifnumeral to check if the argument is a number given either in the Roman or Arabic system \ifnumerals for ranges of (Roman or Arabic) numerals \ifpages for detection of pages Those commands have a ...

1

I posted a similar question on academia.se today and was pointed to this question. I posted a hack there which can work for your situation also. Basically make a separate empty file called myclass.dont.upload.to.arxiv then use IfFileExists function in latex to test whether this file is present or not and take action accordingly. When you have to upload the ...

2

Here is a suggestion based on the following assumptions: You want to enumerate agenda items; and Conditionally print a summary of the enumerated agenda items. We address (1) by writing agenda items as \sections. You already do this using \item{...} (which doesn't take a mandatory argument anyway), hence my suggestion. (2) would be equivalent to writing a ...

1

Testing for the fd-file is useless: It exists anyway, also it contains only font definitions, it is not the font itself. You need to test for a tfm and/or a pfb-font which is specific to the complete version. With pipes enabled you could do something like this (see Search for files first in the texmf trees): \documentclass{article} \pdfmapfile{=mtpro2.map} ...

3

the requested syntax seems very odd, but width= and scale= are just variants of scaling with width implying scaling the natural width so you just need the following which avoids duplicating \includegraphics: \documentclass{article} \usepackage{graphicx} \makeatletter \newcommand\zz[1]{#1\ifdim#1pt<1pt \Gin@nat@width\else\textwidth\fi} \makeatother ...

3

It makes very little sense requiring something like width=1.2\textwidth: if the first item is bigger than 1, the image would be scaled to be wider than the text width. And mixing scale and width is rather dubious. However, the customer's always right. ;-) \documentclass{article} \usepackage{graphicx,xparse} \NewDocumentCommand{\mycmd}{o ...

0

You can do it with a different set of “if-then-else” macros, for instance those provided by etoolbox or by expl3. etoolbox Do \usepackage{etoolbox} in the preamble and use \newcounter{TestCounter} \setcounter{TestCounter}{\ifnumcomp{5}{>}{6}{7}{2}} The relation symbol in between can be <, = or >. expl3 Do \usepackage{expl3} in the preamble, ...

2

A simple wrapper may work here (at least for this simple example) \documentclass{article} %\usepackage{xifthen} \newcommand{\ifelse}[3]{% \ifnum#1 #2% \else #3% \fi } \begin{document} \newcounter{TestCounter} \setcounter{TestCounter}{\ifelse{5 > 6}{7}{2}} \theTestCounter \setcounter{TestCounter}{\ifelse{6 > 5}{7}{2}} ...

4

\ifthenelse is not expandable and can therefore not be used inside the arguments of \setcounter. However, the TeX primitive \ifnum is expandable: \setcounter{TestCounter}{% \ifnum 5>6 % space ends number 6 7% \else 2% \fi } \arabic should not be used in numeric contexts, because it could contain formatting stuff like font settings. The ...

1

Why not? \documentclass{article} \newcounter{Temp} \newcounter{TestCounter} \setcounter{Temp}{5} \begin{document} \ifnum\theTemp>2 \setcounter{TestCounter}{4} \else \setcounter{TestCounter}{7} \fi \theTemp \theTestCounter \end{document}

1

Another option, and for me a simpler one (but perhaps not for your real application), is to use TeX primitives: \documentclass{article} \newif\ifWorkshop\Workshoptrue% set workshop to be true \newif\ifTraining\Trainingfalse% set training to be false \begin{document} \ifWorkshop% \ifTraining Workshop and training!\else Workshop and no training!\fi% ...

3

You are using \ifboolexpr in the wrong way. In your case you need to use the test operator: \documentclass{article} \usepackage{etoolbox} \begin{document} \ifboolexpr { test {\ifundef{\dockerWorkshop}} and test {\ifundef{\training}} } {both undefined} {at least one defined} \end{document}

Top 50 recent answers are included