[texhax] conditional macros

Barry Dale barryd at mtechIT.com
Thu Apr 29 05:07:31 CEST 2004


Even better. Works a treat. Thanks again.

-- 
Barry Dale
Technical Writer
M-Tech Information Technology Inc.
http://mtechIT.com http://psynch.com http://idsynch.com
--------------------------------------------

On Thu, 29 Apr 2004, Ross Moore wrote:

> Hi Barry,
>
> On 29/04/2004, at 11:59 AM, Barry Dale wrote:
>
> > Of course...
> >   Thanks :-)
>
> You're welcome.
>
> But of course I didn't tell the whole story.
>
> >> e.g.
> >>    \newcommand{\FigureOne}{... whatever you want ....
> >>      \renewcommand{\FigureOne}{}}
>
>    This only works if the first usage of \FigureOne
> occurs at the outer paragraphing level.
>
> Most likely you will have various environments,
> perhaps even floats: figures, tables, etc.
> or  minipages, in which you might use \FigureOne .
> In this case, the \renewcommand re-definition will
> be lost as you exit that environment (grouping-level).
>
>
> Thus a better solution is to use TeX's \gdef :
>
> \newcommand{\FigureOne}{... whatever you want ....
>     \gdef\FigureOne{}}
>
> This makes a `global' redefinition that should then
> work in all normal situations...
>
>
>   ... but *do not* use such self-redefining macros
> within any moveable arguments:
>    section-names, figure-captions, index-entries, etc.
> where stuff gets written into auxiliary files, to be
> re-read at a different time in the processing.
> Can you imagine the sort of things that might then occur?
>
>
> Best of luck with this,
>
> 	Ross
>
>
> >
> > --
> > Barry Dale
> > Technical Writer
> > M-Tech Information Technology Inc.
> > http://mtechIT.com http://psynch.com http://idsynch.com
> > --------------------------------------------
> >
> > On Thu, 29 Apr 2004, Ross Moore wrote:
> >
> >>
> >> On 29/04/2004, at 10:27 AM, Barry Dale wrote:
> >>
> >>> I seem to recall a discussion on this list recently about printing
> >>> terms in text in bold the first time they are used in a document,
> >>> then
> >>> in normal font after that. I think the solution involved ifthen
> >>> commands.
> >>>
> >>> I have a similar situation. I use macros to insert boilerplate
> >>> responses to submitted questionaires. The macros can include
> >>> graphics,
> >>> and can be used more than once. I would like the graphics to be
> >>> used only once (to save space and avoid multiple labels).
> >>>
> >>> Is there a way to check if a macro has already been used, and
> >>> treat it differently on subsequent uses?
> >>
> >> Yes, this is easy to do.
> >> Just make the macro redefine itself after the first usage.
> >>
> >>>
> >>> In other words, the macro  \AnswerOne may be defined as:
> >>>   \AnswerOne{%
> >>>     text
> >>>     text
> >>>     \FigureOne{}
> >>>     }%
> >>>
> >>> so that \FigureOne is expanded the first time but empty on subsequent
> >>> uses.
> >>
> >> e.g.
> >>    \newcommand{\FigureOne}{... whatever you want ....
> >>      \renewcommand{\FigureOne}{}}
> >>
> >>>
> >>> I'm familiar with basic LaTeX, but I'm not a programmer, so the
> >>> ifthen documentation is a little daunting. Sorry if it seems obvious.
> >>
> >>
> >> Easy, but not completely obvious.  :-)
> >>
> >> Hope this helps,
> >>
> >> 	Ross Moore
> >>
> ------------------------------------------------------------------------
> Ross Moore                                         ross at maths.mq.edu.au
> Mathematics Department                             office: E7A-419
> Macquarie University                               tel: +61 +2 9850 8955
> Sydney, Australia                                  fax: +61 +2 9850 8114
> ------------------------------------------------------------------------
>



More information about the texhax mailing list