User Tools

Site Tools


Single Optional Argument for a LaTeX Macro

I recently needed to create a new macro for a User manual. The macro was to output a defined character, but in a colour specified by the author. Therefore, I needed a macro that accepted a single optional argument.

After doing a lot of searching around, I could only find advice on two or more arguments. I needed this:

Print my symbol in black \specialsymbol please.
Print my symbol in red   \specialsymbol[red] please.
Print my symbol in blue  \specialsymbol[blue] please.

The macro is:

\textcolor{#1}{`}% backtick character contains the symbol in the "myfont" font.

And for extra niceness, if you want your macro to ensure text following the symbol does not butt up hard against it, change line three to:

\textcolor{#1}{`}\ %
latex_macro_single_optional_argument.txt ยท Last modified: 2019/12/09 21:58 by