[metapost] test for empty text?

Nicola nvitacolonna at gmail.com
Wed May 29 14:08:11 CEST 2013


In article <005601ce5b9e$be063000$3a129000$@cfraizer.com>,
 Colin Fraizer <metapost at cfraizer.com> wrote:

> Perhaps I am missing something really obvious:
> 
>  
> 
> -          Is there a way to test if the replacement text of a macro is
> empty?

In my experimental library Metappeal 
(http://users.dimi.uniud.it/~nicola.vitacolonna/home/content/metappeal), 
I have used this hack (the code is in mtpl_lang.mp):

% Vardef: emptytext?
% Returns:
% True if the given text argument consists of no tokens, false otherwise.
vardef emptytext?(text t) =
   mtpl_emptytext? mtpl_aceedabfadfcada1fdb4 t mtpl_aabobfcbadbde759
enddef;

% Auxiliary macro
vardef mtpl_emptytext?@# text t =
   (str @# = "mtpl_aceedabfadfcada1fdb4mtpl_aabobfcbadbde759")
enddef;


where those mtpl_* symbols are supposed not to occur anywhere else in 
your program.

Dan's idea seems more elegant, though.

Nicola



More information about the metapost mailing list