3

I am working with \newcommand and \ifdefined. I have an issue with the below code as it produces an error and I don't know what is wrong:

\documentclass[a4paper,11pt,english]{report}

\usepackage{longtable}
 \usepackage{multirow}
 \usepackage{graphicx}
 \usepackage[table,xcdraw]{xcolor}

\begin{document}

\newcommand{\FailedReq}{
Nour
}

\newcommand{\ReqOpenIssues}{}

%\newcommand{\NoOpenIssues}{}

\newcommand{\OpenIssues}[1]{\ifcsname#1OpenIssues\endcsname \Failed#1 \else \ifdefined\NoOpenIssues NA \fi \fi 
}

\OpenIssues{Req}

\end{document}

Any help ?

2
  • the error is undefined command \Failed you have that command in the definition but have not defined it, what do you want it to do? 14 hours ago
  • oh did you want to execute \FailedReq ? you need \csname Failed#1\endcsname` 14 hours ago
3

It's exactly the same problem as in your previous question where you tried

\ifdefined\#1OpenIssues

in the hope that \#1OpenIssues becomes \ReqOpenIssues when the argument of the macro is Req.

Sorry, but TeX works with tokens that are formed at definition time. In that replacement text the tokens are

\ifdefined•\#•1•O•p•e•n•I•s•s•u•e•s

(the bullet just separates tokens for clarity). In particular that part of the replacement text never has #•1 which marks the place for the argument substitution.

Similarly here

\Failed#1

is three tokens

\Failed•#•1

and the argument replacement yields

\Failed•R•e•q

(four tokens).

The primitive \ifcsname forms a control sequence name with the tokens up to the matching \endcsname; then it tests whether that control sequence is defined.

For the problem at hand you have to use the corresponding primitive that forms the control sequence and executes it, so

\csname Failed#1\endcsname

See What exactly do \csname and \endcsname do?

5

if #1 is req then \Failed#1 is the same as \Failed req and gives an error that \Failed is undefined.

You intended to execute \FailedReq so to generate that command name you should replace \Failed#1 by \csname Failed#1\endcsname

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.