Hot answers tagged

7

For example: \makeatletter \@ifundefined{ifSomething}{% \newif\ifSomething \Somethingtrue }{} \makeatother \@ifundefined generates the macro name from the argument string and tests, whether the command is undefined (or \relax). This removes the \if... token from the test. Also the branching is syntactically realized via arguments and not by ...


7

You're overthinking: the tool is already there, namely tabular. \documentclass{article} \newcommand{\sigblock}[3]{% \par\vspace{\medskipamount}\noindent \hspace*{#1in}\makebox[#2in]{\hrulefill}\\*[.2ex] \hspace*{#1in}% \begin{tabular}{@{}l@{}} #3 \end{tabular}% } \begin{document} \sigblock{0}{3}{Notary Public \\ At Large} ...


5

You are not comparing two numbers, but the set of instructions to print them; so the test cannot succeed. This is a job for expl3 and its floating point module. \documentclass[a4paper]{article} \usepackage{xparse} \usepackage{numprint} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\numcompare}{O{=}mmmm} { \fp_compare:nTF { #2 #1 #3 } { #4 } { #5 } ...


4

As you say, if you do not use \makeatletter...\makeatother everything "works" (so to say...). And if you call \onetwoside you will get "twoside" (try!). What is going on? Without \makeatletter...\makeatother the @ is not a letter and thus not part of a command. What the human eye reads as \if@oneside is for TeX the token list \if @ o n e s i d e and so on. ...


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


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}


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


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

You can do testing the part before dot and the part after dot separately. Edit If you need to do other tests (< or >, not only =), then the "after-dot" part must be re-calculated using \tnC macro. Zeros are appended to nine digits in total by this macro. If there are more than nine digits in the "after-dot" part then the rest is simply ignored. So, ...


3

I don't understand what you are trying to do but \expandafter\global\newcommand is wrong and you probably wanted \global\expandafter\newcommand\csname...\endcsname[1]{...}, but that can't work either because \newcommand checks non expandably for various things and the \global will be without effect. But \long\global\expandafter\def\csname...\endcsname ...


3

With \let\TokenIsIn=a, the control sequence \TokenIsIn becomes an unexpandable token; more precisely, it becomes an “implicit a”. The tests \if\TokenIsIn a and \ifx\TokenIsIn a return true, but \ifthenelse makes the comparison in a different way; basically, \ifthenelse{\equal{X}{Y}} does something like \edef\first{X}\edef\second{Y}\ifx\first\second and ...


3

A proof of concept, as details are missing from the question. The \tarassinput command inputs the file only if the first line agrees with the second argument. \begin{filecontents*}{typea.tex} % type A here latex stuff \end{filecontents*} \begin{filecontents*}{typeb.tex} % type B here latex stuff \end{filecontents*} \documentclass{article} \makeatletter ...


3

You can't have verbatim-like environments in the arguments to \ifthen. But you can use the primitive conditionals. \documentclass{article} \usepackage{listing} \usepackage[framed]{matlab-prettifier} \newcounter{ctr} \setcounter{ctr}{1} \lstnewenvironment{myMP} {\lstset{style={Matlab-editor}}} {} \begin{document} \ifnum\value{ctr}=1 \begin{myMP} a = 1 ...


3

Short and sweet, done with recursion. \documentclass{article} \usepackage[T1]{fontenc} \usepackage{etoolbox} %% toggles \newtoggle{A} \newtoggle{B} \newtoggle{C} \newtoggle{D} %% chosen toggle \toggletrue{C} \newcommand{\Question}[3]{% \def\toggletmp{F}% \Togl #1,\relax\relax% \if T\toggletmp #2\else#3\fi% } \def\Togl#1,#2\relax{\ifboolexpr {togl #1}% ...


2

You can do it with xparse. You'll need to rename \newtoggle, \toggletrue and \togglefalse if you plan to use etoolbox. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn % emulate \newtoggle \NewDocumentCommand{\newtoggle}{m} { \bool_new:c { l_twww_toggle_#1_bool } } \NewDocumentCommand{\toggletrue}{m} { \bool_set_true:c { ...


2

Certain things in (La)TeX have limited scope. If you want its modifications to survive the group within which the change is made, you have to ensure that it's made \globally (or, perhaps, in such a way that it happens after the group): \documentclass{article} \usepackage{etoolbox,etextools} \newcommand{\showtoggle}[1]{#1: \iftoggle{#1}{true}{false}\par} ...


2

I agree with egreg's and David's comments that just putting $...$ would be the best way; nevertheless I try to point out what you are making unnecessarily complicated. First the spacing issue: the large spaces are there because you are putting them there: \newif\ifstartedinmathmode \newcommand*{\ksp}{ % <==== here there is ...


2

Use \@ifundefined{KOMAClassName}{...}{...} since \@ifundefined calls \expandafter\ifx\csname #1 \endcsname (after a test), i.e. it constructs the command sequence. Here's the definition in latex.ltx. \def\@ifundefined#1{% \expandafter\ifx\csname#1\endcsname\relax \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi} But for ...


2

From another angle, the stringstrings package is very slow and is primarily intended for regular expressions. But if your problem is of that style, then it has some useful routines: \documentclass{article} \usepackage{stringstrings} \begin{document} \def\mystring{dcbadcbadcba} \findchars{\mystring}{a} a's found in string Position ...


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


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


2

By trying to solve this problem I've come up with a possibly interesting macro, so I want to share it here. This macro is called \vardef and allows us to define a macro which can receive a variable number of arguments (any number, not limited to 9 arguments) enclosed in curly brackets. Inside the definition of a \vardefined macro one can use the macro ...


2

Though I recommend to use the answer from @egreg here is a way to implement what you are looking for using \@ifnextchar. The idea is that \sigblock prepares everything until it comes to processing the lines beneath the signature field. Then \sigblock@ is invoked which will set the next grouped argument as a line beneath the signature field and starts a ...


1

Working from one of your attempts, and adding the following: bm package for a bolder < symbol conditionals for both p<0.01 and p<0.05 gives a final document of: \documentclass{article} \usepackage{pgfplotstable,tabularx,booktabs,bm} \begin{document} \noindent% \pgfplotstabletypeset[columns={var,p}, every head row/.style={before ...


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


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

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


1

Thanks to the cowardly downvoter without explaining the vote. \IfBeginWith uses this code (shown by \meaning\IfBeginWith) \long macro:->\@ifstar {\let \@xs@assign \@xs@expand@and@detokenize \@xs@IfBeginWith@@ }{\let \@xs@assign \@xs@expand@and@assign \@xs@IfBeginWith@@ i.e. it does expansion and detokenization of the input code \TokenIsIn, but \if... ...


1

You can use dimension : \documentclass[a4paper]{article} \usepackage{ifthen} \usepackage{numprint} \npthousandsep{,} \npdecimalsign{.} \nprounddigits{2} \newcommand{\dotnumber}{1200.00} \newcommand{\nodotnumber}{1200} \begin{document} \ifthenelse{\equal{\numprint{\dotnumber}}{\numprint{\nodotnumber}}}{true}{false}\\ \ifthenelse{\lengthtest{\dotnumber ...


1

Simple answer. I put a negative \hskip on each side of your math. \documentclass{article} % Ksp \newif\ifstartedinmathmode \newcommand*{\ksp}{ \relax\ifmmode\startedinmathmodetrue\else\startedinmathmodefalse\fi {\ifstartedinmathmode K_{sp}\else\hskip-1mm$K_{sp}$\hskip-1mm\fi} } \begin{document} \begin{enumerate} \item Determine the $K_{sp}$ of ...



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