Tag Info

Hot answers tagged conditionals

10

Package xcolor can extract the color definition in a macro: \extractcolorspec{<color>}{<macro>}. This can be used to define a test to compare the current color . with red: \documentclass[a4paper,12pt]{article} \usepackage[T1]{fontenc} \usepackage[svgnames]{xcolor} \usepackage[scaled=0.84]{beramono} \makeatletter \newcommand{\MyChange}[1]{% ...

8

You can test macro-to-macro using \ifx. That is, \ifx<csA><csB><true>\else<false>\fi will test whether the definition of <csA> matches that of <csB> and execute <true>, or <false> otherwise: \documentclass{article} \makeatletter \newcommand{\@emptymacro}{}% Used to test against an empty macro ...

6

The \jobname primitive is a TeX string, so all characters have category code 12 (other) not 11 (letter) (with the exception of any spaces, which are category code 10 (space)). Slightly confusingly, xstring is carrying out a token-based comparison here not a string one! Assuming e-TeX is available you can fix your code easily \documentclass{article} ...

6

That is an interesting question indeed. I am always very wary of automatic solutions, they do exactly what they are told and are not intelligent. And one always has to check if everything went exactly as planned manually anyway. With Biber we can do regex checks on fields. Regex allows to check for Cyrillic characters. Here we check the title field (the ...

5

You can use the fact that a color's definition is kept in the macro \csname\string\color@<colorname>\endcsname and you can inspect the current color with . for <colorname>, as explained in http://tex.stackexchange.com/a/36163/4427 \documentclass[a4paper,12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} ...

4

Two problems: You are using three conditionals but have only two closing \fi's. Use of the conditionals should be performed in the traditional way: \if.. <true> \else <false> \fi Note there is not grouping of the <true> and/or <false> clause. That's the main problem in your case, as definitions are then made local to that ...

4

I just realized there is another easy solution. The xstring package has starred versions of its comparison commands that do not take category codes into account. All that is necessary to make the file work is to replace \IfStrEq by \IfStrEq*.

4

All the file input tests use \input@path as well as the standard TEXINPUTS variable, personally I find it easier to just set TEXINPUTS rather than use \input@path (\graphicspath just sets a version of \input@path used locally during the scope of \includegraphics) However if you want to use the macro directory list for all such operations, replace ...

4

This is most definitely not a complete answer but you could try adding the babel=other option when loading biblatex and supplying the Russian-language entries with something like hyphenation = russian. Whether there is a way of automating this latter operation is still an open question.

3

You can also give the langid field in addition to setting autolang to a sensible value. Unfortunately, the mapping to the language is a bit picky and does not work with XeLaTeX (an utf8 aware engine) out of the box. \begin{filecontents}{\jobname.bib} @online{someotherentry, url={texwelt.de}, urldate={2015-05-11}, author={a ...

3

I would approach this problem using a key-value interface to do most of the heavy lifting. The advantages of this method are that you can define new schemes anywhere, and a single document can use more than one scheme if desired (respecting grouping/scope). There are several keyval packages, and the code can get even more fancy than what I show below, but ...

3

As is explained in page 1 from comment documentation, you can define as much as commentable environments as you want, just include \includecomment{name of environment} or \excludecomment{name of environment} to select or unselect corresponding lines in your document. With them you can declare environments for any color combination \begin{orange} %orange ...

3

The standard TeX code for given task is: \def\something#1{\def\internal{#1}% \ifx\internal\empty the parameter is empty.\else it is nonempty.\fi } The problem of this code (above) is that the macro \something isn't expandable because it includes \def assignment. If you need expandable macro with the same test then you need to choose the token never ...

3

You need to perform a string comparison with the expansion of \@currenvir against itemize. \ifthenelse with the \equal operator does this, but you're short a magic \makeatletter...\makeatother wrapper (see What do \makeatletter and \makeatother do?). Consider the post Why is the ifthen package obsolete?, I've used the e-TeX \pdfstrcmp to perform a string ...

3

You shouldn't use @ in command names, when using ConTeXt; but you should be aware of the fact that ConTeXt uses Unicode math, so the standard math code of the hyphen cannot be accessed to with \mathcode. \begingroup \catcode\"=12 \catcode\=12 % added a safe setting for the backquote \gdef\newmcodes{\mathcode\'39\mathcode\*42\mathcode\."613A ...

2

since you want only a word or so omitted, i think an ordinary command is better than an environment. here's one possibility. \documentclass{article} \newif\ifmycmd \newcommand{\FlagText}[1]{% \ifhmode\unskip\fi \ifmycmd \else \space #1\fi } \begin{document} Here is some text \FlagText{with some words} to be ignored. \FlagText{Start} a new ...

2

The definition text of \insertauthor is not empty, which is quite obvious, because the macro is meant to do something with data that should already have been given. From beamerbasetitle.sty, line 149 and following: % The \author command % % \def\author{\@dblarg\beamer@author} \long\def\beamer@author[#1]#2{% ...

2


2

You don't need the test for numeric, in my opinion. I suggest a different syntax: \der[<function>]{<variable>}[<order>] with two optional arguments; if you omit the first, you get the operator, otherwise the derivative; the second argument is the order of derivation. With xparse it's easy to do it; the first optional argument has empty ...

2

\bool_if:NT \l_sectioning_numbered_bool { \thesection.\ } \bool_if:NTF \l_sectioning_lowercase_bool { \tl_lower_case:n } { \tl_upper_case:n } { #1 } In that case, I think that would be enough. May be clearer is \bool_if:NT \l_sectioning_numbered_bool { \thesection.\ } \bool_if:NTF \l_sectioning_lowercase_bool { \tl_lower_case:n { #1 } } { ...

1

This is a quick solution with the cntperchap package (I am quite familar with its author ;-)) The key is to register counters which should be tracked on a per chapter base, here it is the section counter. Then use the \GetStoredCounterValue[chapter number]{section} macro to get the number of sections in the relevant chapter. This does not print the number ...

1

The following example remembers the section count in the .aux file. A counter abs@chapter is used to identify the chapter. Thus also starred or unnumbered chapters are supported. \section is redefined to write a line in the .aux file, which increases the number of sections for the current chapter. Also starred \section commands are supported. In the next ...

1

The syntax is wrong: you're probably used to C or something like that. TeX conditionals are always in the format \if<name><test> <true text> \else <false text> \fi with no braces around the two cases. Well, braces can be used, but they will group the tokens inside them, which usually is not wanted. In general loading a package ...

1


1

There are a couple of errors in your code. First: you define \sidenote with an optional argument, but do nothing with it. Second: you don't understand clearly what the optional argument to \marginnnote does. What you have to do is to locally enable \reversemarginpar, not to use the optional argument to \marginnote. Here's a working version. ...

1

I'm putting this as an answer despite it's brevity. Sometimes the least convoluted thing is the best thing, and the most extensible thing. I would just create a set of files, one for each scheme. In each file define the colors you want. Then just include a line in your file \input{colorschemepurple.tex}

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