Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Welcome to TeX.SX! –  egreg Dec 4 '13 at 12:05
    
I am very beginner in terms of macros in TeX. Thank you, @Ian, @egreg! –  Ama Dec 4 '13 at 13:29

1 Answer 1

up vote 10 down vote accepted

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}%        
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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