New answers tagged

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% Defined 3 arguments% `\long\def` allows for paragraphs % within the arguments of a control sequence ...


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}


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


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


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


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


1

Use a \Longstack. \documentclass{article} \documentclass{article} \usepackage{stackengine,lipsum,setspace} \setstackEOL{\cr} \def\sigblock#1#2#3% Defined 3 arguments% {\singlespacing{\vbox{\vskip.75in\noindent\hskip#1in% {\hbox to #2in{\leaders\hbox to 0.00625in{\hfil.\hfil}\hfill}}}% \par\noindent\hskip#1in\Longstack[l]{#3}}} \parindent 0pt ...


1

Here's a easy way with xparse and using an optional g argument, which allows to use an optional argument to be used with {...} group pair. \documentclass{article} \usepackage{setspace} \usepackage{xparse} \NewDocumentCommand{\sigblock}{mm+m+g}{% \IfValueTF{#4}{% \singlespacing{\vbox{\vskip.75in\noindent\hskip#1in% {\hbox to #2in{\leaders\hbox to ...


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


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


1

Here, I save the listing in a temporary \vbox, and only conditionally print it out. \documentclass{minimal} \usepackage{ifthen} \newcounter{ctr} \setcounter{ctr}{1} \usepackage{listing} \usepackage[framed]{matlab-prettifier} \lstnewenvironment{myMP}{% \lstset{style={Matlab-editor}}% }{} \begin{document} \setbox0=\vbox{% \begin{myMP} ...


1

The etoolbox package has \providebool: \documentclass{article} \usepackage{etoolbox} \newif\ifSomething \providebool{Something} \providebool{SomethingElse} \begin{document} \texttt{\meaning\Somethingtrue} \texttt{\meaning\SomethingElsetrue} \end{document}


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


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

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


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


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


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


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


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


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


0

Solved by this way: \ifdef{\placa}{\newcommand \sistelet[1]{\auxsistelet{#1}{\tipoveiculo}{\moto}}}{} \ifnumcomp{\nveics}{>}{1}{ \foreach \x in {b,...,\alphalph{\nveics}}{ \ifcsdef{placa\x}{\csgdef{sistelet\x}##1{\auxsistelet{##1}{tipoveiculo\x}{moto\x}}}{} } }{}


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



Top 50 recent answers are included