Define a command (or similar) that makes a conditional expression reusable

conditionalsifthenelse

I'm struggling with the correct use of conditional expressions with ifthenelse at the moment. I would like to define a command (or similar) that represents a certain conditional expression in order to use it in different locations of the document.

Lets say I have two booleans

\newboolean{bA}
\newboolean{bB}

And then I want to test the following condition in multiple locations

\boolean{bA} \or \boolean{bB}

I tried to define a command for that

\newcommand{\any}{\boolean{bA} \or \boolean{bB}}

but it didn't work as I expected. Instead, the engine reported Extra \or.

I tried different approaches like

\newboolean{bAny}
\setboolean{\boolean{bA} \or \boolean{bB}}

which did not work and

\newboolean{bAny}
\ifthenelse{\boolean{bA} \or \boolean{bB}}{
    \setboolean{bAny}{true}
}{
    \setboolean{bAny}{false}
}

which did work for me, but this solution is only suitable if the result of the expression does not change throughout the document. This is given in my case but it may not be in others.

I am wondering how I may define a command that makes the conditional expression reusable. I am certain that it should be possible but I don't know enough Tex and Latex to figure it out myself.

Here is a minimal working example

\documentclass{article}

\usepackage{ifthen}

\newboolean{bA}
\newboolean{bB}

% This works
%\newcommand{\any}{\boolean{bA}}
% This does not
\newcommand{\any}{\boolean{bA} \or \boolean{bB}}

\begin{document}
    \setboolean{bA}{true}
    \setboolean{bB}{false}
    
    \ifthenelse{\any}{%
        Hi
    }{%
        there
    }
    %
    \setboolean{bA}{false}
    %
    \ifthenelse{\any}{%
        how
    }{%
        are you?
    }
\end{document}

Chosen Solution

In the end I opted to use Marijn's solution because it is simple and I was able to fully understand it.

\newcommand{\ifAny}[1]{%
    \ifthenelse{\boolean{bA} \OR \boolean{bB}}{%
        #1%
    }{}%
}

egreg's solution is elaborated and works as I originally asked for. It allows to write

\newcommand{\any}{\boolean{bA} || \boolean{bB}}

and to use it as a single condition or as a part of more complex conditional expressions. It is however much more complicated and may confuse my future self.

Best Answer

Alternatively, put the \ifthenelse in the command definition:

\documentclass{article}

\usepackage{ifthen}

\newboolean{bA}
\newboolean{bB}

\newcommand{\ifthenany}[2]{\ifthenelse{\boolean{bA} \or \boolean{bB}}{#1}{#2}}

\begin{document}
    \setboolean{bA}{true}
    \setboolean{bB}{false}
    
    \ifthenany{%
        Hi
    }{%
        there
    }
    %
    \setboolean{bA}{false}
    %
    \ifthenany{%
        how
    }{%
        are you?
    }
\end{document}