# Tag Info

2

A possible way is to use the table counter \ifnum\value{table} > 0 \listoftables \fi wouldn't work alone since the number of tables isn't known at that stage of processing. With the totcounter package one could register the total number of tables (which is written to the .aux file (so it's known in the second run finally). However, since the table ...

1

Another method, which is especially helpful if one needs to have more control over the items alignment, is the array construct. \documentclass{article} \usepackage{amsmath} \begin{document} $$X=\left\{ \begin{array}{@{}ll@{}} 0, & \text{if}\ a=1 \\ 1, & \text{otherwise} \end{array}\right.$$ ...

0

Iverson bracket can also be used: $x=[a=1]$.

2

You asked for a "better" method. I find the method using the package ifthen (thanks to David Carlisle :-)) quite easy to read and to adapt. Take a look: \ifthenelse{\NOT \boolean{foo}}{\dostuff}{} (no idea about efficiency, though) The empty braces at the end {} are the empty else option. You can leave them out and write simply \ifthenelse{\NOT ...

2


4


1

\iftoggle (from etoolbox) actually has the following syntax: \iftoggle{<toggle>}{<true>}{<false>} It already provides an "if-else" statement. In your usage, the <true> clause executes \todo[color=green]{{[}COR.{]} #1}{} while the <false> clause executes \linebreak So, a proper grouping of elements within your macro ...

5

You lose expandability, of course, but this is the “easy” way: \documentclass %{book} {article} \makeatletter \begingroup \@ifundefined{chapter}{\endgroup}{\endgroup\renewcommand\chapter[1]{turtles}} \makeatother \usepackage{kantlipsum} \begin{document} \chapter{a} \kant[1-10] \end{document} The method with \ifdef from etoolbox may give wrong results ...

9

The simplest is to use the e-TeX \ifdefined macro instead: \documentclass{article} \ifdefined\chapter\renewcommand\chapter[1]{turtles}\fi \usepackage{kantlipsum} \begin{document} \chapter{a} \kant[1-10] \end{document} This won't work if you have other conditionals inside it (thus the source of your larger problem) in which case Werner's solution using ...

6

The command \newif is 'outer' in plain TeX: it cannot appear inside any other macro. However, \csname newif\endcsname can appear, so you can do \csname newif\expandafter\endcsname\csname ifgre@scale@#1\endcsname and all will be well. This is not LuaTeX-specific: it's a general feature of working with plain.

2

Elements on diagonals have either odd or even sum of indexes, so you can use \ifodd; schematically: \ifodd\numexpr\Row+\Column\relax do domething for elements on diagonals with odd sum of indexes \else do domething for elements on diagonals with even sum of indexes \fi In the question it's not clear if tkz-berge is really needed so I opted for a ...

1

The \ifx is working in your code. If you don't provide the MWE where the error occurs than we cannot guessing anything. But your code includes many LaTeX misunderstandings. I rewrite your result to TeX primitives in order to more clear understand what happened. (1) When name is nonempty, then the result is: \indent NAME\hfil\break \vadjust{\vskip1.5 pt ...

4

The simple minded method from my other answer avoids nesting. Here we don't have TeX like \if..\fi but suitable wrappers, so we need to modify a bit the definitions. \long\def\DoThis #1#2\OrThat #3{#1} \long\def\OrThat #1{#1}% \@firstofone \ifdefstring{\foo}{bar}{\DoThis{do something}}{}% \ifdefstring{\foo}{baz}{\DoThis{do something else}}{}% ...

8

If \foo expands to a simple string, which survives a \csname, the following method can be used, which does not need LaTeX3: \documentclass{article} \makeatletter \@namedef{foo@bar}{% \typeout{\noexpand\foo is bar}% % <do something> } \@namedef{foo@baz}{% \typeout{\noexpand\foo is baz}% % <do something> } \@namedef{foo@abc}{% ...

3

It's quite easy with xparse and expl3: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\xifstring}{mO{}m} { \str_case:onF { #1 } { #3 } { #2 } } \ExplSyntaxOff \begin{document} \newcommand{\foo}{abc} \xifstring{\foo}[No match] { {abc}{String is abc'} {def}{String is def'} {ghi}{String is `ghi'} } ...

5

The best solution I can think of is expl3’s \str_case:nnTF. Here I generate a variant to take one token instead of a test string and compares to expansion of that token to the list. If no match is found in the list an appropriate message is output. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \cs_generate_variant:Nn \str_case:nnF { VnF } ...

2

A verbatim or lstlisting command cannot go in the argument to another command. You can keep your interface with \newtoggle and \iftoggle, provided you do something a bit different when verbatim or lstlisting is involved. \documentclass{article} \usepackage{etoolbox} \newtoggle{tog1} \newcommand{\verbatimtoggle}[1]{% TT\fi ...

4

verbatim content is currently being supplied as an argument to \iftoggle{<toggle>}{<true>}{<false>} - either in the <true> or the <false> clause. You can't have verbatim content as the argument of a macro as the argument being read fixes the category codes, which verbatim wants to change. One suggestion is to use traditional ...

2

Update Improved version (older version at the end) The spacings etc. can't be automated straightforwardly. Some manual adaption is needed for each slide file. \documentclass[a5paper]{article} \usepackage{pdfpages} \usepackage{pgffor} \usepackage{xparse} \usepackage{blindtext} \newlength\slidetextdistance \setlength{\slidetextdistance}{0.48\textheight} ...

4

The keys +, - and 0 are not sufficient, because typically you need to jump up levels when a chapter finishes. The \level macro has a mandatory argument; it can be +, -, = or an integer (between –1 and 5, extremes included). I find using +, - or = error prone, unless your editor allows you to fold at \level. However, it's easy to use the absolute level. ...

2

Here is a very elementary implementation that doesn't include error checking (but can be added) and a slight interface change - an optional argument rather than a mandatory one for switching the relative level of the sectional unit. \documentclass{book} \newcounter{cursecdepth} \setcounter{cursecdepth}{-1} \makeatletter \@namedef{seclevel@0}{\part} ...

Top 50 recent answers are included