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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10361
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