Tag Info

Hot answers tagged

19

The insertion of the “frozen \relax” is not documented in the TeXbook, where \relax appears 57 times, mostly in listings. No mention of this insertion is made in the discussion of conditionals. The insertion is documented in section 12.5.3 of TeX by Topic: Of course it's in “TeX the program”: module 510 describes the insertion in incomplete conditionals. ...


13

The evaluation is not lazy, revealed by scanning the .log when tracing the macro expansions: %\begingroup \tracingmacros1 \ifboolexpr{ bool{testA} or bool{testB} }{OK}{Something's wrong...} %\endgroup That is, a complete evaluation of bool{testA} is followed by an equivalent evaluation of bool{testB}, followed by an evaluation of or, to output ...


8

Main answer In general, patching commands when # is involved can't happen in the argument to another command. One can do some tricks with category codes, but another approach can be easier: \documentclass{beamer} \makeatletter \@ifclassloaded{beamer}{\@tempswatrue}{\@tempswafalse} \if@tempswa \usepackage{bookmark} \usepackage{etoolbox} ...


7

I use boolean metapost; if known color Wolfgang Amadeus Mozart: metapost:=true; else: metapost:=false; fi The explanation: under Metafont, color Wolfgang Amadeus Mozart will be an unknown numeric since color is not a Metafont keyword. But in MetaPost, Wolfgang Amadeus Mozart will be an unknown numeric and therefore not a color. Thus color Wolfgang ...


7

Let's look at \expandafter\expandafter\expandafter \def\@if\iffoo{true}{\let\iffoo=\iftrue}% recalling the definition of \@if: \def\@if#1#2{\csname\expandafter\if@\string#1#2\endcsname} The first \expandafter expands the third one, which in turn causes the expansion of \@if, which has two arguments; in this case they are #1<-\iffoo #2<-true ...


6

Here's a solution based on refcount and etoolbox. I made a new command called pagespan, which prints your output wherever placed: \documentclass{article} \usepackage{lipsum} \usepackage{etoolbox} \usepackage{refcount} \newcommand{\pagespan}[2]{% \ifnumequal{\getpagerefnumber{#1}}{\getpagerefnumber{#2}}{% \pageref{#1}% }% {% ...


6

The answer has been given by Werner. xintexpr knows about etoolbox booleans and toggles. Different syntaxes allow different levels of laziness: [sorry I got wrong the way "lazy" was to be interpreted; thus I switch to "silly"] silly: booleans are replaced by 1 or 0 depending on whether they evaluate to true or false, and then the logical or does not stop ...


6

Drop the use of groups inside the groupplot construction. I've added some indentation, and corrected the small type (missing } at the beginning of the tikzpicture environment): \documentclass{article} \usepackage{pgfplots} \usetikzlibrary{calc} \usepgfplotslibrary{groupplots} \def\a{3} \begin{document} \begin{tikzpicture} \begin{groupplot}[group ...


5

Grab the contents of the conditional environment using environ: \documentclass{article} \usepackage{empheq,environ} \NewEnviron{pdfORht}[3][]{% \ifdefined\HCode %htlatex \begin{#3} \BODY \end{#3} \else% pdflatex \begin{#2}[#1]{#3} \BODY \end{#2} \fi% } \begin{document} \begin{pdfORht}[box=\fbox]{empheq}{align*} ...


5

Using fancyhdr with scrbook is not recommended. However, here's a solution: issue the \thesection command within \markright. Note that \markright takes only one argument (whereas \markboth needs two). \documentclass{scrbook} \usepackage[english]{babel} \usepackage{lipsum} \usepackage{fancyhdr} \pagestyle{fancy} ...


5

I'd use etoolbox for this, rather than ifthen. \documentclass{article} \usepackage{etoolbox} \newtoggle{thing} \newcommand{\foo}[2]{% \iftoggle{#1} {% --#2--% do something if set, using #2 }% {% \fbox{#2}% do something else if not set, using #2 (default) }% } \begin{document} % thing is initially false \foo{thing}{baz} ...


5

Try: \documentclass[a4paper]{book} \begin{document} ~\newpage \ifodd\thepage I am an odd page\else I am an even page \fi ~\newpage \ifodd\thepage I am an odd page\else I am an even page \fi \end{document} EDIT: If you are using roman page numbering this will work: \documentclass[a4paper]{book} \begin{document} \pagenumbering{roman} ...


5

I just \def\infootnote to T or F. If you needed to branch on that basis, you could perform \if T\infootnote TRUE code\else FALSE code\fi. \documentclass{article} \let\svfootnote\footnote \renewcommand\footnote[2][\thefootnote]{% \stepcounter{footnote}% \gdef\infootnote{T}% \svfootnote[#1]{#2\gdef\infootnote{F}}% } \gdef\infootnote{F} \textheight 1in ...


4

You can (see daleif's comment) use the LaTeX kernel macro called \@ifclasswith to test whether or not the a5paper option was passed to memoir, and do different things accordingly. One potential downside of this approach is that using \@ifclasswith is only allowed in the preamble, not in the body of the document. ...


4

To finally give an comprehensive answer to my own question for future reference, the following will do what I initially wanted: First of all, there is no need to use the \zh{} token, as this example will work with using the name affix as described here by Audrey: http://tex.stackexchange.com/a/66825/47927 I didn’t use the titleaddonpart of Audrey’s ...


4

This is a straightforward application of \@ifnextchar: \documentclass{article} \usepackage{unicode-math} \setmainfont{TeX Gyre Pagella} \setmathfont{Asana Math} \makeatletter \newcommand{\timeintegral}{% ∫_{t_0}^{t_1} \@ifnextchar∫{\!\!\!}{}% } \makeatother \begin{document} \[ \timeintegral E \, dt = \timeintegral ∫_z ∫_φ f \,dφ\,dz\,dt \] ...


4

Generally speaking, rather than including "conditionals" in the title format to work out where in the document the title is used, you either (a) include macros in the format itself which will expand appropriately (e.g. \chaptertitlename which will be redefined once \appendix is given) or (b) redefine with a new \titleformat at the appropriate point in the ...


4

The problem is basically the same as in \ifnum and pgfmath: error I think. \z will not be an integer, so the comparison fails. You can make \z an integer by using \z=int(ceil(abs(sin(\y r)))). int makes it an integer. ceil and abs is necessary to avoid rounding to zero. \documentclass{article} \usepackage{tikz,ifthen} \begin{document} What I have now: ...


3

I've come up with a different idea so simple I might describe it as stupid; I just make two files, a .mf and a .mp, and let kpathsea do the rest (names subject to change pending your suggestions): % ismetapost.mf: Companion to ismetapost.mp % If we were MetaPost, we would have read the other file, so ... boolean is_metapost; is_metapost := false; % ...


3

Ok, I got it hacked this way: \usepackage{xifthen} % I wasn't able to do this with ifthenelse macro already used in the code replace lines 90 and 91 with the following code \ifthenelse{1=\pgfkeysvalueof{/tikz/zoomboxes xshift}} { \node at (image.north) [anchor=north,inner sep=0pt] ...


3

Checking for page numbering can also be done using a \label-\ref approach. Below I use the expandable \getpagerefnumber from refcount to condition on the page number: \documentclass{article} \usepackage{refcount}% http://ctan.org/pkg/refcount \newcounter{oddpagecheck} \makeatletter \newcommand{\ifoddpage}{% \ifoddpage{<odd>}{<even>} ...


3

Define a conditional \iffootnote and redefine \footnote so that it makes \iffootnote come out true inside its parameter, but false outside. For example: \documentclass{article} \newif\iffootnote \let\Footnote\footnote \renewcommand\footnote[1]{\begingroup\footnotetrue\Footnote{#1}\endgroup} \begin{document} foo\footnote{a\iffootnote yes\else no\fi} bar ...


2

There are different ways of defining conditionals. When you use or set the value of a conditional, you need to use the right syntax for the definition you've chosen. In addition to the etoolbox method demonstrated in egreg's answer (which I've never used), there are at least two other very common methods. Your problem is caused by trying to use the syntax ...


2

Try this: \documentclass[11pt,a4paper,sans]{moderncv} \usepackage{expl3,xparse} \ExplSyntaxOn \keys_define:nn { mil / resume } { start .tl_set:N = \l_mil_resume_start_tl, end .tl_set:N = \l_mil_resume_end_tl, degree .tl_set:N = \l_mil_resume_degree_tl, institution .tl_set:N = \l_mil_resume_institution_tl, city ...


2

You can't have minted environments as arguments to other commands: this is a limitation for every “verbatim” kind of things, so verbatim, lstlisting and minted. You can avoid the argument using a more basic syntax: \documentclass{article} \usepackage {minted} \usepackage {ifthen} \newboolean{printCode} \setboolean{printCode}{true} \begin{document} Text ...


1

It sounds to me what you're actually trying to do is write your own document class. So put the part of your current header that should be part of that class in MyClass.cls and make it look like this: \NeedsTeXFormat{LaTeX2e} \ProvidesClass{MyClass} \DeclareOption∗{\PassOptionsToClass\CurrentOption}{memoir}% } \LoadClass{memoir} \DeclareOption{a5paper}{% do ...


1

Counters can only contain integer numbers. If you want to deal with real numbers you have to play with lengths. The following MWE uses lengths instead of counters (the internal macro \strip@pt is used to strip pt when printing the length): \documentclass{scrartcl} \usepackage{pbox,calc} \makeatletter \newcommand*{\strippt}[1]{\strip@pt#1} \makeatother ...



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