GeneralPrevent variable from being recalculated each appearance?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Pelican
Posts: 1
Joined: Sun Apr 19, 2015 4:17 am

Prevent variable from being recalculated each appearance?

Post by Pelican »

Whenever I define a macro, each time it is displayed, it seems to recalculate the macro. For example, if \printtime is a custom macro created with \def that displays the current time to then nearest millisecond, if I have \printtime several times on the document, it appears a different time on each appearance. How do I lock that, so it is calculated only at specific times> E.g. \printtime \printtime \recalculate \printime, would give the first time twice, then a new time after being recalculated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Prevent variable from being recalculated each appearance?

Post by Stefan Kottwitz »

Welcome to the forum!

You could evaluate it, such as by \edef, or save it into a box, and print that box several times. (\sbox and \usebox)

Stefan
LaTeX.org admin
Post Reply