# \isdefempty not working for multiple macros

I am still learning tex. The following example allows me to check if a variable exists, and if it does then prints some text in the PDF. This works great. However, when I add in a href, this appears whether the variable exists or not. Driving me nuts as I cant find anything online even close to what im trying to do. Is it even possible?

\ifdefempty{\na}{}{\Sexpr{cve_descr_na}}\ is displaying a variable I have in R. This works well. However, \ifdefempty{\ds}{}{\Sexpr{cve_descr_ds}{\href{\Sexpr{url_ds_1}}{here }}}\ displays "here" even if ds is null.

\documentclass[11pt,a4paper, titlepage]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz,fancyvrb}
\usepackage{helvet}%font
\usepackage{color}
\usepackage[hidelinks]{hyperref}
\usepackage{etoolbox}
\def\ds{cve_descr_ds}
\def\ui{cve_descr_ui}
\renewcommand{\familydefault}{\sfdefault}%sets fonts across document
\title{}
\date{}
\begin{document}
\fcolorbox{white}{green!65}{%
\parbox{17cm}{
\textbf{Your Cyber Vunerabilities}\\
\small
\ifdefempty{\na}{}{\Sexpr{cve_descr_na}}\\
\ifdefempty{\spf}{}{\Sexpr{cve_descr_spf}}\\
\ifdefempty{\ds}{}{\Sexpr{cve_descr_ds}{\href{\Sexpr{url_ds_1}}{here }}}\\
\ifdefempty{\ui}{}{\Sexpr{cve_descr_ui}{\href{\Sexpr{url_ui_1}}{here,}}}\\
}
}
\end{document}


Here is the resultant sweave; \documentclass[11pt,a4paper, titlepage]{article} \usepackage[margin=0.5in]{geometry} \usepackage{tikz,Sweave,fancyvrb} \usepackage{helvet}%font \usepackage{color} \usepackage[hidelinks]{hyperref} \usepackage{etoolbox} \def\ds{cve_descr_ds} \def\ui{cve_descr_ui}

\renewcommand{\familydefault}{\sfdefault}%sets fonts across document
\title{}
\date{}
\begin{document}
\input{HC-concordance}
\fcolorbox{white}{blue!65}{%
\parbox{5cm}{
\begin{center}
\textbf{About You}\\
\small
The Lakes
\\
Your business ranks in the highest 25 percent
\end{center}
}
}
\fcolorbox{white}{green!65}{%
\parbox{13cm}{
\textbf{Your Cyber Vunerabilities}\\
\small
\ifdefempty{\ds}{}{they can find more details{\href{}{here, }}}\\
\ifdefempty{\ui}{}{they can find more details {\href{https://nvd.nist.gov/vuln/detail/CVE-2016-6329}{here, }}}

}

\end{document}

• (1) welcome, (2) please make your example compilable. I'm not sure whether R or Sweave is relevant for this, so perhaps don't add them. Note that since Sweave is not on CTAN not every latex user have access to that package. – daleif Dec 8 '17 at 14:48
• Besides you are missing the } for \fcolorbox. We need to know what \Sexpr is doing, and it might not be compatible with hyperref expansion. – daleif Dec 8 '17 at 14:53
• Ah ok , thanks! I missed the } in a poor copy and paste! Ill update my post. – Siobhan Dec 8 '17 at 14:56
• But … \ds isn't empty in your document! – Harald Hanche-Olsen Dec 8 '17 at 15:10
• this is where im a complete newbie im afraid. \def\ds{cve_descr_ds} is picking up variable cve_descry_ds from R script. In the example im running, in one R script loop it is null and another it is populated. the tex code returns cve_descr_ds when it exists and does nothing if it doesn't. However, when it doesn't exist I still get the "here". – Siobhan Dec 8 '17 at 15:16