TeX has several «functions» for «conditional compilation», but there is no built-in for checking if «this string is equal to that». For example, now i need to check if some string (second parameter to my macro) is empty.
But this can be achieved by making two macros — «needed string» and «given string» — and comparing these:
\def\myMacro#1#2{% \def\reallyempty{}% \def\secondarg{#2}% #1% \ifx\secondarg\reallyempty {} \else { \textit{(#2)}} \fi% } |
Why one may need it? Let’s say i need to format some songbook, and want to format «author» and «arranger» (if any) in some specific way. Example above will print «author» and — if any — «arranger» in parentheses and italicized.
Using such a macro is very useful if you may decide to change this «specific format» — you need to change only this macro (throw out parentheses, insert blank line between fields etc).
You could use the following as well.
\ifx#2\relax%
\else%
{ \textit{(#2)}}%
\fi
:) :)
Thank you, this is great.