1

I am looking for \iftoggledefined{<toggle name>}{<true>}{<false>}. I checked the etoolbox documentation and did not see such a thing.

Based on Difference between \newbool and \newtoggle from etoolbox package, one could use \ifcsdef{etb@tgl@#1}, but if the etoolbox code was ever change this test would break. Thus, would prefer to use an offical macro if it exists.

Question:

Can I obtain the same output as the given MWE

ToggleA: Exists
ToggleB: Does Not Exist

without relying on the internal etb@tgl@#1 code of etoolbox.

Code:

\documentclass{article}
\usepackage{etoolbox}

\makeatletter \newcommand{\iftoggledefined}[3]{\ifcsdef{etb@tgl@#1}{#2}{#3}} \makeatother

\newtoggle{ToggleA}

\begin{document} ToggleA: \iftoggledefined{ToggleA}{Exists}{Does Not Exist}

ToggleB: \iftoggledefined{ToggleB}{Exists}{Does Not Exist} \end{document}

Peter Grill
  • 223,288

1 Answers1

1

Since \newtoggle checks \ifcsdef{etb@tgl@#1}, I believe this is a safe test.

There's no code in the package to check for a toggle to be defined (it's the same with \newif of the kernel or \newboolean of ifthen) and I'm not sure what it would be useful for.

Make a feature request, in the meantime use the code you proposed (and rethink to its usefulness).

egreg
  • 1,121,712