Tag Info

2

Usually this is realized in the form \foo{Unique} and \foo[One]{Two} which is clearer than an optional argument in braces. The classical LaTeX way to do this is \newcommand{\foo}{\@dblarg\name@foo} \def\name@foo[#1]#2{Whatever we want to do with #1 and #2} So calling \foo{X} will result in Whatever we want to do with X and X whereas calling ...

3

Here's a xparse solution using the g specifier as a possible optional 2nd (!!!) argument, the g specifier allows for {} delimited optional arguments, but in my point of view, [] would be a clearer way. \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\xparsecmd}{mg}{% \IfValueTF{#2}{% optional #1 and #2 }{% Only #1 and #1 }% ...

3

This syntax relies on the fact that one will use braces to enclose arguments (otherwise the question is ambiguous since any subsequent token can be interpreted as a second argument). \documentclass{article} \makeatletter \def\mycommand#1{\@ifnextchar\bgroup{\mycommandhelp{#1}}{\mycommandhelp{#1}{#1}}} \makeatother \def\mycommandhelp#1#2{Mycommands ...

3

Instead of opening the environment, use the true/false arguments to define a macro: \documentclass{article} \usepackage{ifthen} \newenvironment{selectlist}[1] {% \ifthenelse{\equal{#1}{itemize}} {\def\selectedlist{itemize}} {\def\selectedlist{enumerate}}% \begin{\selectedlist}% } {\end{\selectedlist}} \begin{document} ...

2


4

Add \makeatletter \def\@classoptionslist{draft} \makeatother before the \documentclass line (while canceling out the explicit 'draft' option from your class declaration) in the main.tex to make sure that the draft option is active also in your subfile text.tex. The following one-liner is equivalent: ...

0

I solved the issue as follows, The inner theme file contains the following code, \setbeamertemplate{section page}{ \global\boolfalse{SHOW_LINE_IN_FOOTER} \ifbool{DIVIDER_IS_YELLOW}{% \begin{tikzpicture}[remember picture, overlay] \node at (current page.center) { \includegraphics[width=\paperwidth]{yellow_divider.pdf} }; ...

2

As you ask for a modular solution, a simple but safer approach, without deal with complex conditional or string comparisons, is maintain each set of questions in separate files (said A.tex, B.tex, C.tex... each with a single line of text as "This is the version A", etc. ) Then you can insert the A.tex subdocument in the main document with \include{A} and ...

4

Here is an example of what you could use with the requirements you specify: \documentclass{article} \usepackage{environ} % Conditions: % 1) If \generateversion is absent and there is no \begin{version}: do as usual; % - Met by default, as text will be set as usual. % 2) If \generateversion is absent and there is at least one \begin{version}: take only one ...

4

I had the same problem than you, I resolve it but I use Makefile. I think this is the prettiest solution because you don’t need to modify your document just before compiling. For example, this is the code I use for compiling “offensive version of document” (In my publications, I could use swearwords but in nooffensive version they didn’t appear). Makefile ...

5

In the example below, you do have to generate \ifvone, etcetera, but only have to turn on the one(s) that you want. \documentclass{book} \newif\ifvone \newif\ifvtwo \newif\ifvthree \vtwotrue \begin{document} \ifvone v1 true \fi \ifvtwo v2 true \fi \ifvthree v3 true \fi \end{document}

4

As Heiko pointed out in his comment, \textbf is eating \else as argument, and \textit takes \fi. You thus need \expandafter in order to tell TeX to wait and finish the if-statement before expanding \textbf and \textit. You should then use \ifnum1=1\relax\expandafter\textbf\else\expandafter\textit\fi{Foo} or \ifnum1=1 ...

3


2

Some macros are robust, while others are fragile. Robust macros protect themselves from expansion under certain conditions while fragile commands do not, and this is the cause of your current problem. Specific to your case, \small is not robust, and when used inside an expanded definition runs into problems. Instead, use \makeatletter ...

4

Simple LaTeX with the kernel command \in@: \documentclass{article} \makeatletter \newcommand*{\IfStringInList}[2]{% \in@{,#1,}{,#2,}% \ifin@ \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi } \makeatother \begin{document} \IfStringInList{Paul}{George,John,Paul,Ringo}{Beat it}{Roll it} \end{document} Manual solution without ...

1

Another way... EDITED to allow blank fields (A,,B) \documentclass{article} \usepackage{ifthen} \newcommand\IfStringInList[4]{\stringsearch#1:#2,\relax\relax% \if T\found#3\else#4\fi} \def\stringsearch#1:#2,#3\relax{\ifthenelse{\equal{#1}{#2}}{\def\found{T}}{% \if\relax#3\relax\def\found{F}\else\stringsearch #1:#3\relax\fi}} \begin{document} ...

3

expl3 has this ready for use: \clist_if_in:nnTF {<clist>} {<item>} {<true>} {<false>}: \documentclass{article} \usepackage{expl3,xparse} \ExplSyntaxOn \NewDocumentCommand \IfStringInList {mmmm} { \clist_if_in:nnTF {#2} {#1} {#3} {#4} } \ExplSyntaxOff \begin{document} \IfStringInList{Paul}{George,John,Paul,Ringo}{Beat it}{Roll it}% ...

1

Here's a LuaLaTeX-based solution. It sets up a macro called \IfStringInList and implements it via a call to the Lua function string.find to set up "true" and "false" branches. Observe that both the target string and the search string can be quite general; in particular, the target string need not be a comma-separated collection of strings. % !TEX ...

3

The xtring package provides such command: \documentclass{article} \usepackage{xstring} \newcommand\IfStringInList[2]{\IfSubStr{,#2,}{,#1,}} \begin{document} \IfStringInList{Paul}{George,John,Paul,Ringo}{True}{False} \IfStringInList{Joe}{George,John,Paul,Ringo}{True}{False} \IfStringInList{ul,Ri}{George,John,Paul,Ringo}{True}{False} \end{document}

3

The reason is already explained by Joseph Wright's answer, that the second \index call is inside the argument of another macro. Then the the index entry text is not read verbatim and macros are expanded. Due to LaTeX's protection mechanism, the robust macro \textit is expanded by \protected@write to \protect\textit␣. The space at the end is part of the macro ...

2

The \index command reads its argument in a verbatim-like manner. That means that it cannot be used inside the argument to other commands, at least not if you want it to continue to work correctly. If you look at the .idx file you have you'll find \indexentry{myterm@\textit{myterm}}{1} \indexentry{myterm@\textit {myterm}}{1} where the entry with the ...

3

When TeX is given the input \ifx\\\\A\else B\fi it compares \\ with \\ and determines that they are equal; so it removes the conditional and the test tokens, leaving A\else B\fi This executes A (which will usually be some code) and then expands \else; the expansion of \else consists in going up to the matching \fi, removing everything it finds in ...

2

Here is another solution based on the file name. Create a file Master.tex and two symbolic links to it: Version5.tex and Version6.tex. When compiling one of these, a switch versionV is set to true if Version5 is being compiled and set to false otherwise. I have used the more low level \newif to create a switch and \ifversionV to branch based on its value. ...

4

As mentioned in my comment, the question Passing parameters to a document allready points in a right direction. File Master.tex \documentclass{scrbook} \usepackage{etoolbox} \usepackage{xstring} \newtoggle{version5} \IfStrEq{\jobname}{\detokenize{Version5}}{\toggletrue{version5}}{\togglefalse{version5}} \iftoggle{version5} { \title{Version 5 ...

4

This uses the shell-escape features (\immediate\write18) and writes \togglefalse{version5} or \toggletrue{version5} to a file called foo.cfg This foo.cfg is read by foo.tex. The compilation is done in a subshell, the rename can be done with the --jobname= option of the pdflatex binary (or xelatex etc. \documentclass{article} \newwrite\foocfg% Get a ...

Top 50 recent answers are included