# How can I retrieve the number of currently defined macros?

The following will max-out TeX's memory:

% arara: pdftex
\nonstopmode
\input expl3-generic \relax \ExplSyntaxOn

\int_zero:N \l_tmpa_int
\int_while_do:nn { \l_tmpa_int < 490000 }
{
\cs_new:cn { temp \int_use:N \l_tmpa_int : } { nothing }
\int_show:N \l_tmpa_int
\int_incr:N \l_tmpa_int
}
hi
\bye


giving the error

! TeX capacity exceeded, sorry [number of strings=494671].


after 489008 definitions. (I'm assuming the remaining ≈5k definitions are from the kernels and formats.)

I assume this number is available in a configuration file somewhere (for the 'wizards' who build TeX), but how can I get this number of strings= dynamically from within TeX itself?

sh-3.2$cat temp-file--8751S9O.tex hi \bye sh-3.2$ tex temp-file--8751S9O.tex >/dev/null
sh-3.2$cat temp-file--8751S9O.log This is TeX, Version 3.14159265 (TeX Live 2015) (preloaded format=tex 2015.5.24) 26 JUL 2015 09:34 **temp-file--8751S9O.tex (./temp-file--8751S9O.tex [1] ) Output written on temp-file--8751S9O.dvi (1 page, 208 bytes). sh-3.2$

• after the \input line, set "hello world", then \bye, and check the stats in the log. Jul 26, 2015 at 14:31
• @barbarabeeton I get no such stats in the log file :( see edit Jul 26, 2015 at 14:34
• forgot you will need \tracingstats=2; the report occurs when the job ends. i suggested doing it once with an essentially empty file, so you'd have a baseline. (on the system i usually use, this is set as default, so i made a rash assumption.) Jul 26, 2015 at 15:09
• these days you don't need to rebuild tex it's settable in the texmf.cnf file, but you can not get that information from TeX luatex is different, but uses dynamic allocation anyway so you don't run out until you run out of real memory. Jul 26, 2015 at 15:14
• @SeanAllred I guess they're preempted by the format. And no, the information cannot be accessed from a TeX run. Jul 26, 2015 at 15:48

If I run pdftex on

\tracingstats=1 \bye


the log file will report

Here is how much of TeX's memory you used:
2 strings out of 494671
95 string characters out of 6148970
14212 words of memory out of 5000000
1670 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
1i,0n,0p,1b,6s stack positions out of 5000i,500n,10000p,200000b,80000s


If I run it on

\tracingstats=1 \input expl3-generic \relax \ExplSyntaxOn \bye


I get

Here is how much of TeX's memory you used:
6750 strings out of 494671
132558 string characters out of 6148970
103191 words of memory out of 5000000
8405 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
22i,0n,31p,10374b,291s stack positions out of 5000i,500n,10000p,200000b,80000s


Thus you have an idea of how much load expl3 puts on memory, by comparing the empty file with the one with \input expl3-generic.

Running your test file with the only addition of \tracingstats=1 at the beginning, I get the error

! TeX capacity exceeded, sorry [number of strings=494671].


and the log file shows

Here is how much of TeX's memory you used:
494671 strings out of 494671
5388582 string characters out of 6148970
4493699 words of memory out of 5000000
496323 multiletter control sequences out of 15000+600000
14794 words of font info for 50 fonts, out of 8000000 for 9000
1420 hyphenation exceptions out of 8191
23i,0n,31p,10361b,291s stack positions out of 5000i,500n,10000p,200000b,80000s


Memory would be exhausted earlier if the replacement text in the \cs_new:cn instruction is longer.

The information about memory is not available during a TeX run. This limitation is not in LuaTeX, see section 4.13 of the manual about the status library.