[Tex/LaTex] Command with or without parameter

definitionmacros

How to define a command

\def\hello{Hello world!}

that can be called with no parameter:

\hello

or with a parameter:

\hello{3}

but that won't be displayed anyway (3 shouldn't be displayed, it's an internal number I'll maybe use later, but for now, it should not be displayed)

Best Answer

As pointed out by Steven B. Segletes in a comment,

\newcommand\hello[1][]{Hello world!\gdef\savearg{#1}}

works and saves the optional argument. If the optional argument is not required, then

\newcommand\hello[1][]{Hello World}

is the solution.

Related Question