\documentclass{article}
\title{}
\author{}
\date{}
\begin{document}
\newcommand{\mybold}[2]{\ifnum #1=1 \textbf{#2} \else{#2} \fi}
\mybold{1}{This should be bold}
\mybold{0}{This should NOT be bold}
\end{document}
In this code, the command mybold accepts a number and text. If the number is 1 the text is emphasized and if not it doesn't. It works as expected.
\documentclass{article}
\title{}
\author{}
\date{}
\begin{document}
\newcommand{\mybold}[2]{\ifnum #1=1 \textbf\fi{#2}}
\mybold{1}{This should be bold}
\mybold{0}{This should NOT be bold}
\end{document}
I tried shortening the first code by putting #2 behind the if condition. However, I get too many }'s error. How do I get the second code to work?
\def\mybold#1{\ifnum #1=1 \expandafter\textbf\fi}– wipet Jan 20 '23 at 21:08