Use of macro eases document preparation, further modification, uniformity maintenance, just to name a few of the enormous benefits we enjoy.

But does the use of a macro slow down the compilation process?

How does LaTeX handle the macros? In place replacements?

  • 2
    Usually no, but it depends on what the macro is doing, and other stuff – daleif Mar 14 '16 at 16:10
  • 1
    Macros that do writing stuff to files are slowing the down the process, but this depends on the amount of content to be written of course. (And this is basically not the fault of TeX macros but rather an OS issue then) – user31729 Mar 14 '16 at 16:12
  • 2
    It naturally depends on the macro. – Ulrike Fischer Mar 14 '16 at 16:30
  • 2
    The whole of LaTeX is macros. Only TeX has primitives. – user4686 Mar 14 '16 at 17:39
  • 1
    @Masroor imagine a macro that never ends. most macros that you will use are simple substitution macros there you will not see any difference when compiling. – daleif Mar 14 '16 at 18:24

Try the following input file expansion.tex:




and time the compilation with

time tex '\def\do{\7}\input expansion'

I get

real    0m0.532s
user    0m0.504s
sys     0m0.012s

You can easily figure out the number of macro expansions required. With \8 in place of \7 I get

real    0m4.340s
user    0m4.126s
sys     0m0.017s

Yes, it's of course an exponential growth; don't try with \0 ;-) With \6 I get

real    0m0.157s
user    0m0.142s
sys     0m0.012s

which shows that compiling a reasonable document is not slowed down by using macros.

Macros are, well, macros: when expansion of a macro is required, TeX does in place replacement of the macro with the tokens resulting from the replacement text currently stored in memory.


With ConTeXt, it is possible to get more fine-grained information about typesetting time. The macro is \testfeature


will execute the second argument n times and report the execution time on the terminal. Let's compare simple macro expansion:


This gives:

system          > starting feature test

\wait =
system          > 100000 feature tests done (0.060s)

\wait =
system          > starting feature test

\wait =
system          > 100000 feature tests done (0.066s)

\wait =

So, typesetting ABC 10^6 times took 0.060s while typesetting \ABC 10^6 times took 0.066s. So, the difference is 6ms for 10^6 or 6 nano seconds per expansion! I wouldn't worry about the speed of macro expansion :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.