Brownian motion

around the essentials…

 

Archive for 14 вересня 2009

My poetry…

Sorry, but this post is not available in English yet

(No Ratings Yet)

TeX: testing if string is empty

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).

(No Ratings Yet)

Recent Posts

Tags

Archives