8

I try to define a macro in LaTeX. This macro should give a different output when I use condition true and false.

This does not work:

\documentclass{article}
\usepackage{lipsum}
\newif\ifABC
\ifABC
\newcommand{\abcdef}[1]{{Letters} #1}%
\else
\newcommand\abcdef[1]{}
\fi

\begin{document}
\ABCtrue
\abcdef{ABC}
\lipsum[2]

\end{document}%

How I should define conditional macro?

| improve this question | | | | |
  • I am very beginner in terms of macros in TeX. Thank you, @Ian, @egreg! – Ama Dec 4 '13 at 13:29
10

You need to check the conditional when the macro is executed, not when it is defined.

\documentclass{article}
\usepackage{lipsum}
\newif\ifABC
\newcommand{\abcdef}[1]{\ifABC{Letters} #1\fi}
\begin{document}
\ABCtrue
\abcdef{ABC}
\lipsum[2]
\end{document}%        
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.