New answers tagged

3

If you must walk on a tightrope then: \documentclass{scrlttr2} \usepackage{tabularx} \begin{document} \newcounter{x} \setcounter{x}{0} \newcommand\zz[1]{#1} \centering \begin{tabularx}{\linewidth}{c|X} \stepcounter{x} \ifnum\value{x}=20 \zz{it is & 20} \else \zz{it is & ...


3

A conditional cannot straddle two cells. However you can use \ifthenelse: \documentclass{article} \usepackage{tabularx} \usepackage{xifthen} \begin{document} \newcounter{x} %\setcounter{x}{0} \begin{tabular}{c|l} \stepcounter{x}% \ifthenelse{\value{x}=20}{it is & 20}{it is & not}\\ \setcounter{x}{20}% \ifthenelse{\value{x}=20}{it is & 20}{it ...


1

Will this do? \documentclass{article} \usepackage{environ} \newif\ifcopyright \copyrighttrue% defalult is \copyrightfalse \NewEnviron{hidden}[1][]% #1 = warning message (optional) {\ifcopyright #1\else\BODY\fi} \begin{document} This will always appear. \begin{hidden}[\fbox{All rights sold to client.}] This text is hidden. \end{hidden} \end{document}


3

Using \seq_count:N in a wrapper command will provide the number of elements in the sequence. Here the variant \seq_count:c must be used since the sequence name is generated and not known before in a \l_...seq like command name. As can be seen, the \printlength macro is expandable. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \...


2

When conditional text is skipped over, TeX still keeps track of \if..., \else and \fi. When you call \parity{1}{0}, the first \IfEven is expanded, leaving \ifnum in the input stream. Since the conditional returns false, the inner \IfEven is not expanded and the first \else is matched to \ifnum. There is an old trick for this, using \if. The trick is ...


2

don't do \def\IfEven#1{\pgfmathparse{int(mod(#1,2))}\ifnum\pgfmathresult=0} as such a syntax leaves trailing \else and \fi not matched by a tex-primitive \if. Either use \if syntax or use argument syntax \pgfmathparse{int(mod(#1,2))}% \ifnum\pgfmathresult=0 yes \else no \fi or \def\IfEven#1#2#3{\pgfmathparse{int(mod(#1,2))}\ifnum\pgfmathresult=0 %...


3

There are several ways the achieve your goal. One would be to use the filter option to accept only the first two lines. filter uses the ifthen package syntax: filter={\value{csvrow}<2} The complete code is: \documentclass{article} \usepackage{csvsimple,filecontents} \begin{filecontents*}{scientists.csv} name,surname,age Albert,Einstein,133 ...


2

Do the check by comparing with “male” and “female”: \documentclass{article} \makeatletter \newcommand{\Handed}{% \par Handed in by \Apply@Gender\@Author\space on \@Handindate \par } \newcommand{\@Gender}{Unknown} \newcommand{\@Author}{Unknown} \newcommand{\@Handindate}{Unknown} \newcommand{\Gender}[1]{\renewcommand{\@Gender}{#1}} \newcommand{\...


7

Assuming \ifsomething returns false, the “true” text is skipped, except that TeX still balances conditionals. Since \ifSL@AMS is not defined, it is skipped, but then \else is matched to \ifsomething and you end up with an “Extra \else”. This is a good place for using ifthen: \RequirePackage{xifthen} % or ifthen \ifthenelse{\boolean{something}} {% true ...


8

Heiko’s answer is a little terse, so I hope that I will be allowed to add a few words of explanation, even if I do not propose an alternative solution. I would say that the answer to your question is “it depends on whether the outer switch is true or false”. I’ll analyze your second example, that deals with \ifA and \ifB, in order to explain why Heiko’s ...


12

\else and \fi are already defined. But if the starting \ifSL@AMS is not defined, then TeX will not recognize the undefined control sequence as \if... switch and the \if..., \else, and \fi tokens are not properly nested anymore. Workaround: \makeatletter \newif\ifsomething \ifsomething \RequirePackage{showlabels} \expandafter\ifx\csname ifSL@AMS\...


2

This example uses xstring, and pgffor to create a lopp that iterates through a list of accepted phrases. Adding more phrases is as easy as adding them to the list. \def\genderInput{% %Input: <input gender>/<output phrase>,% (without the <>, ending by commma) female/Mrs.,% male/Mr.,% boy/young Mr.,% girl/Miss,% none/} Note that in british,...


4

You cannot do it like this: a lstlisting environment cannot be nested inside an environment defined with \NewEnviron. Moreover, you can't nest an environment in one defined by \NewEnviron if you don't use the proper \begin tag. \documentclass{article} \usepackage{listings} \usepackage{comment} \lstnewenvironment{cpp}[1][] {\lstset{language=C++,#1}} {} ...


1

You think that \ifx \gostorganizatiaopt text% test whether \gostorganizatiaopt is being compared to text. However, it's actually being compared to t, and it will never be true in your case. If you want a text-comparison, use the e-TeX \pdfstrcmp{<strA>}{<strB>} which returns 0 if <strA> = <strB>: \ifnum\pdfstrcmp{\...


0

A counter is the best way for me. In the eskdi.sty file declare macro \newcounter{gostorgcounter}% 0=text; 1=logo \newcommand{\gostorganizatia}[2]{% % \setcounter{gostorgcounter}{#1}% % \ifnum\thegostorgcounter=0% 0 - text; 1 - logo \newcommand{\gostorganizatiatext}[1]{#2} \fi% % \ifnum\thegostorgcounter=1% \newcommand{\...


5

A possible way to achieve the first improvement is by exploiting \ifdefined instead of relying on a \newif, as in the original code. Let us see the new TeX code: \documentclass{article} \begin{document} Question: What is $2+2$? \ifdefined\solutionflag\begin{quote} \textbf{Solution:} $2+2=3$ \end{quote}\fi \end{document} The plan here is straightforward: ...


3

The end code of an environment definition runs within the group set up by \begin.. \end so if it makes local assignments (as \footrue does) they are lost at the end of the group. Depending what you want to do you (and making some (true) assumptions about the implementation of \footrue and \end) you could use \global\footrue or \aftergroup\footrue


1

\documentclass{tufte-book} \usepackage{ifoddpage} \newcounter{mycount} \begin{document} \parindent=0pt \loop \mbox{\checkoddpage \ifoddpage Odd \else Even \fi}\\ \ifnum\themycount<130 \stepcounter{mycount}% \repeat \end{document}


1

This is better, but not perfect -- the first check on a page is always wrong! The reason the OP does not work is that \pageref is not expandable, i.e. its output cannot be used for \ifthenelse or any other \if.... conditional that should check the number, so the output branches always to the false branch, i.e. Even. \getpagerefnumber from refcount package ...



Top 50 recent answers are included