2

Hi all I wrote a simple code at which I created simple variables and some If condition. The output however was not desired

Here is the code:

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

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

\begin{document}

%\newcommand{\ReqOpenIssues}{}

\newcommand{\NoOpenIssues}{}

\newcommand{\OpenIssues}[1]{\ifdefined\#1OpenIssues REQ \else \ifdefined\NoOpenIssues NA \fi \fi 
}

\OpenIssues{Req}

\end{document}

The desired output is NA But this is the output:

enter image description here

Any help?

1
  • 1
    \ifdefined\# is always true as \# is a standard latex command. Commented Nov 2, 2021 at 16:47

1 Answer 1

3

If you wish to build up the macro name using #1 plus some additional text, you need to use \ifcsname.

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

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

\begin{document}


\newcommand{\NoOpenIssues}{}

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

\OpenIssues{Req}

\newcommand{\ReqOpenIssues}{}

\OpenIssues{Req}

\end{document}

enter image description here

See also Using \ifdefined on \csname macros

1
  • Your answer worked! Thanks. However I modified a part of the code that produced an error, here is the modification: \newcommand{\FailedReq}{Nour} \newcommand{\ReqOpenIssues}{} \newcommand{\OpenIssues}[1]{\ifcsname#1OpenIssues\endcsname \Failed#1 \else \ifdefined\NoOpenIssues NA \fi \fi } \OpenIssues{Req}
    – Nour
    Commented Nov 2, 2021 at 20:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .