I'm writing a document in LaTeX that I want to compile in two different versions, V1 and V2 (with two different formatting specifications). Sometimes I need to insert a bit of content into V1 that isn't in V2, and vice versa. To specify which version is being compiled, I have a variable called cond
, which I set to True
to flag the V1 formatting, and False
to flag the V2 formatting. Then, the following commands are specified:
% Display the argument if \cond is True
\newcommand{\IfCondTrue}[1]{\expandafter\ifstrequal\expandafter{\cond}{True}{#1}{}}
% Display the argument if \cond is False
\newcommand{\IfCondFalse}[1]{\expandafter\ifstrequal\expandafter{\cond}{True}{}{#1}}
Thus, to insert content into V1 that isn't in V2, I simply insert it into the command \IfCondTrue{...}
.
This works exactly as desired except for one issue; when the content that I'm inserting is paragraph text, eg. This is fake \IfCondTrue{text}.
. If cond
is set to False
, then the word text
won't display, as desired. Unfortunately, it will be replaced with an empty space. For example, suppose in V1 I want to have This is fake text.
and in V2 I want to have This is fake hooplah.
, then ideally I could write: This is fake \IfCondTrue{text}\IfCondFalse{hooplah}.
. Then, when V1 compiles, what I'll see is This is fake text .
(with a space between text
and .
.
How can I modify the above commands so that they won't display an empty space when their content is not displayed?
Thanks
\ignorespaces
then use\
if you need a space.This is fake\IfCondTrue{ text.}\IfCondTrue{hooplah. }
In this way, the commands automatically account for the spaces introduced by the other commands. Note particularly elegant but it's a bit convenient.\IfCondTrue{text}
and\IfCondFalse{hooplah}
in the example above, do you mean that isn't in your real code? (This is why it is always best to post a complete document so the problem can be reproduced)