[pdftex] Parametrized btex/etex-blocks?

Magnus Lie Hetland magnus at hetland.org
Mon Nov 25 18:10:09 CET 2002


I've noticed that when I write MetaPost code where I need several
labels typeset with LaTeX, my code seems to become a bit repetitive...
What I need is a way to parametrize my btex/etex blocks -- or so I
think...

For example, let's say I write something like

  def foo(expr p, n)=
      label(btex $2^n$ etex, p);
  enddef;

Of course, here n will be typeset as the letter 'n'. What I'd like is
a way to substitute the value of the parameter n into the tex text.
Since btex/etex blocks are processed with a preprocessor this sounds a
bit impossible -- but since I'm not 100% sure, I thought I'd ask.

An alternative is, I guess, to do something like:

  verbatimtex \newcommand{\foo}[1]{$2^{#1}$} etex
  def foo(expr p, l)=
      label(l, p);
  enddef;

And then call it with

  foo((100, 100), btex \foo{3} etex);

or something...? This seems to work fine, but it would be nice to be
able to abstract away the btex/etex stuff inside the macros... Also,
it would be nice to be able to calculate things that to into the
btex/etex blocks.

Is something like this possible? (An alternative would, of course, be
to use a preprocessor, possibly in a different language...) I assume
that the possibilities are severely limitid if the preprocessing has
to take place before any interpretation has taken place...

-- 
Magnus Lie Hetland        Practical Python          The Anygui Project
http://hetland.org        http://ppython.com        http://anygui.org



More information about the pdftex mailing list