LaTeX Optional Arguments

Viewed 134751

How do you create a command with optional arguments in LaTeX? Something like:

\newcommand{\sec}[2][]{
    \section*{#1
        \ifsecondargument
            and #2
        \fi}
    }
}

Then, I can call it like

\sec{Hello}
%Output: Hello
\sec{Hello}{Hi}
%Output: Hello and Hi
6 Answers
Related