Hot answers tagged

9

You can happily put a brace group inside a primitive conditional, but it has no special syntactic meaning. Instead, it simply forms a group in the same way it would outside of a conditional. Thus when \if@myswitch{ \renewcommand{\myquietcommand}[1]{{}} }\fi is expanded, and assuming \if@myswitch is true, we end up with { \renewcommand{\...


5

When you disable the teacherversion mode the \startmode command tries to gobble everything until \stopmode which doesn’t work when you embed them into other commands. What you have to is to create first your teacheronly environment to ensure the commands exist and put the setups the enable margin rule in a separate mode block. \definemode[teacherversion][...


4

One way forward -- hopefully feasible for you -- is to switch to either LuaLaTeX or XeLaTeX and to load the fontspec package. All you will need to change in the document is (a) comment out (or delete) the instructions \usepackage[utf8]{inputenc} and \usepackage[T1]{fontenc} in the preamble and (b) add the instruction \usepackage{fontspec}. Of course, the ...


4

If I read correctly your question, you want that the trailing optional argument is printed before the superscript. \tl_if_blank:VTF is the wrong function, because the V means a variable is expected; {\gobble}{#2}{\originalcite{#1}} is meaningless; m+o means that the last (optional) argument is “long”, that is, it accepts \par in it; it should be read as m +...


4

Upon seeing \MakeAutoQuote or \MakeAutoQuote*, csquotes defines \csq@string@<number> for both arguments in a suitable way. The <number> represents the decimal ASCII codes of the UTF-8 representation of the character, separated by periods if multibyte. However, the package already provides the infrastructure for the conversion. \begin{...


4

One of the great mysteries of LaTeX is {\ifnum0=`}\fi to be paired with its sibling \ifnum0=`{\fi} but one can also find \iftrue{\else}\fi \iffalse{\else}\fi These are perfectly legal TeX constructs. Both {\ifnum0=`}\fi and \iftrue{\else}\fi contribute, when expanded, an open brace. The TeXnical reason for {\ifnum0=`}\fi is rather complex; I'll ...


3

Place \global prior to the \endencounteredtrue. As it is in your MWE, since it is issued inside the \[...\] environment, the value of \ifendencountered is lost upon exit, unless it is saved globally. You might also consider changing the #2\\ to #2\par\noindent, which I did not do here. \documentclass{article} \newcommand{\currentLabel}{\nosuchcommand} \...


3

\ifbool is macro, as such \verb is not possible inside its arguments. The standard \newif way is much easier, I think (and it works), since there's no argument involved: \documentclass[11pt]{scrbook}% \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{} %\usepackage{etoolbox} %\newbool{private} %\setbool{private}{true} \newif\ifprivate \privatetrue \...


3

If you are willing to use the etoolbox package, you can replace your \if with a bool. \documentclass[10pt,presentation]{beamer} \usepackage{etoolbox} \newbool{exercise} \booltrue{exercise} \boolfalse{exercise} \begin{document} \section{Some Section} \begin{frame}{Some Slide} \ifbool{exercise}{% What is the answer to everything? \begin{enumerate} ...


3

It's the usual problem of a conditional straddling two columns. There's a simpler solution: print “subject to” only if not already printed. \documentclass{article} \usepackage{amsmath} \newif\ifsubjectto \newcommand{\optimizationproblem}[3]{% \global\subjecttotrue \begin{array}{ll} \text{#1} & #2 #3 \end{array}% } \newcommand{\constraint}[1]{% ...


3

You want to do \global\endencounteredtrue only in the “typesetting phase”, not in the measuring one. For this you can use \ifmeasuring@. You also need \ltx@label if you want it to work in align. \documentclass{amsart} \newcommand{\currentLabel}{\nosuchcommand} \newcounter{exampleends} \newif\ifendencountered \makeatletter \newcommand{\exampleendhere}{% ...


3

This takes a * anywhere to mean red, not just at the end. \documentclass{article} \usepackage{color} \usepackage{array} {\catcode`\*=\active \gdef\zz#1{% \mathcode`\*="8000 \gdef\foo{}% \def*{\gdef\foo{\color{red}}}% \setbox0\hbox\bgroup$} } \def\zzz{$\egroup\foo{\box0}} \begin{document} Not colored here: $-12$, But colored within the tabular \begin{...


2

I assume that the * is used only in cells containing numbers; then in the special environments any run of minus signs, digits and period followed by a * is prefixed by \color{red} and the * is removed. \documentclass{article} \usepackage{color} \usepackage{array} \usepackage{tabularx} \usepackage{siunitx} \usepackage{xparse,environ,l3regex} \ExplSyntaxOn \...


2

You can also use the collcell package which allows you to examine tabular/array cell contents and perform any desired operations on them: Notes: All math content should allways be typeset in math mode. There is a difference in -12(wrond) and $-12$ (correct). Thus I use the array instead of tabular. If you have mixed content then you can encode the ...


2

You are comparing \@junk with A and of course “false” is returned. This is because \ifstrequal performs no expansion. So you need to expand \@junk before the comparison takes place. \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{beamerthememwe} \def\junk#1{\def\@junk{#1}} \junk{A} \RequirePackage{etoolbox} \RequirePackage{xcolor} \definecolor{foreground}{RGB}{...


2

You can't have all the rest of the stuff to the \\ before the \else when the antecedent of the conditional is false because TeX assumes that the end of the conditional will never terminate. You can work around this by doing something like the following \documentclass{article} \usepackage{amsmath} \newcounter{opc} \newcommand{\optimizationproblem}[3] {% \...


2

A possible solution (if I understand the question right): \documentclass{article} \usepackage{filecontents} \begin{filecontents}{\jobname.bib} @article{greenwade93, author = "George D. Greenwade", title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})", year = "1993", journal = "TUGBoat", volume = "14", number = "3"...


2

Change the iftoggle condition to: \begin{tasks}(\iftoggle{twocolumn}{2}{1}) MWE: \documentclass{article} \usepackage{lipsum} \usepackage{tasks} \usepackage{etoolbox} \begin{document} \newtoggle{twocolumn} \togglefalse{twocolumn} The toggle is false: % Task 3 \begin{tasks}(\iftoggle{twocolumn}{2}{1}) \task one \task two \task ...


2

This is similar to what LaTeX does for \fontsize: \documentclass{article} \makeatletter \newcommand{\dimenorfactor}[3]{% \afterassignment\dim@or@factor\skip@=#1pt@{#2}{#3}% } \def\dim@or@factor#1@#2#3{% \if\relax\detokenize{#1}\relax#3\else#2\fi } \makeatother \begin{document} \newlength{\testdim}\setlength{\testdim}{4pt} \newcommand\test[1]{% \...


1

OK. Since nobody seems to be biting, I did a little more investigation and came up with the following for csquotes.cfg. \AtEndPreamble{% \DeleteQuotes \MakeAutoQuote{‘}{’}% \MakeAutoQuote*{“}{”}% } \endinput However, this means that I cannot override my defaults in the preamble of a particular document because it works by zapping the existing ...


1

\foreach executes every cycle in a group; so when you do the first cycle in the first \foreach, what's actually done is \begingroup \csdef{isProblemShow1}{0} \endgroup and the definition is forgotten as soon as \endgroup is executed. In the second loop you do \begingroup Problem 1\quad is \csuse{isProblemShow1} \par \endgroup \begingroup Problem 2\quad ...


1

If you know in advance what is to be typeset in verbatim, the verbbox environment can help. \documentclass[11pt]{scrbook}% \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{} \usepackage{etoolbox} \newbool{private} \setbool{private}{true} \usepackage{verbatimbox} \begin{document} \begin{myverbbox}{\caseA}t&st\end{myverbbox} \begin{myverbbox}{\caseB}Mi#...


1

Since table cells are treated as TeX groups, toggling a conditional defined with \newif remains local in the group, i.e. \lighttrue will stick to that cell and the next cell (or row) is unaware of the change. In order to activate the change globally a \global\lighttrue or \global\lightfalse must be applied. \documentclass{article} \usepackage{calc} \...


1

RunarTrollet has pointed me in the right direction. /.is if does really exactly what it states in the manual, and only that. There are two reasonable things you might expect that it doesn't do: When executing drawit/.is if=drawit, it doesn't store the current value of the key in the TeX-if. (So you have to initialise the value afterwards!) When executing ...



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