This applies to any one using lualatex and encounters the dreaded error
sorry [number of destination names (dest_names_size)=131072]
Which happens due to large document which has many destination names in it.
Notice that changing dest_names_size in texmf.cnf has no effect on the above as
lualatex uses sup_dest_names_size for the limit of destination names and not
dest_names_size which is used it seems by pdflatex only. Thanks to Marcel Krüger for
this hint and pointing this out.
The solution I did is to download lualatex sources from https://github.com/TeX-Live/luatex https://gitlab.lisn.upsaclay.fr/texlive/luatex (note, as of August 2024, use this new link, the github one is old). Click on code botton above and download the zip file.
Now extract the ZIP file into a temporary folder. The exact file to download from above is the zip file
wget https://github.com/TeX-Live/luatex/archive/refs/heads/trunk.zip to
download the zip file directly to some TMP folder and then extract the zip file. This will
create new folder called luatex-trunk.
The above name of the zip file can change. For example, in June 2025, this was the name of the zip file
wget https://gitlab.lisn.upsaclay.fr/texlive/luatex/-/archive/master/luatex-master.zip
Best is to right click and copy the link directly.
Now edit the file pdfdest.h in the source tree inside. It is located in
>pwd /home/me/TMP/luatex-trunk/source/texk/web2c/luatexdir/pdf >ls -lrt pdfdest.h -rw-r--r-- 1 me me 2167 May 27 18:12 pdfdest.h
There you will find the following lines
# define inf_dest_names_size 1000 /* min size of the destination names table for PDF output */ # define sup_dest_names_size 131072 /* max size of the destination names table for
I changed sup_dest_names_size which is now \(2^{17}\) to \(2^{18}=262144\). Saved the file.
Now at the top level folder where you extracted lualatex, there is a file called
build.sh
>pwd /home/me/TMP/luatex-trunk >ls -l build.sh -rwxr-xr-x 1 me me 11900 May 27 18:12 build.sh
Edit the above file and change BUILDLUAHB=FALSE to BUILDLUAHB=TRUE This is
so it builds luahbtex in addition to luatex. Also make sure to uncomment the
lines
#export CFLAGS="-D_FORTIFY_SOURCE=2 -O3" #export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
By removing the # from the front to now look like this.
export CFLAGS="-D_FORTIFY_SOURCE=2 -O3" export CXXFLAGS="-D_FORTIFY_SOURCE=2 -O3"
This is important, else the generated binaries will run very slow.
Now type ./build.sh
When done there will be two binaries luahbtex and luatex in folder
>pwd /home/me/TMP/luatex-trunk/build/texk/web2c -rwxr-xr-x 1 me me 7960728 Jul 7 20:42 luatex -rwxr-xr-x 1 me me 9376072 Jul 7 20:42 luahbtex
This completes the first phase. The second phase is to copy the above files (as root) from the above folder to your texLive installation.
On my system linux ubuntu I became root and copied the above 2 files to
/usr/local/texlive/2022/bin/x86_64-linux/ overwriting the original files (made a
backup copy before doing this just in case)
Now the final step is to rebuild texmf files using the command
sudo -E env "PATH=$PATH" fmtutil-sys --all
Make sure to run it as above using root! as shown above. Do not do
#DO NOT DO THIS, USE THE ABOVE INSTEAD sudo fmtutil-sys --all
As this might fail if root does not know where your TL path is and this can cause problems. (This happened to me).
That is all. Now lualatex will have its destination names set at 262144 instead of 131072 hardcoded into the source code.
Future versions of Lualatex should really make this parameter available to users to modify without having to do this each time but I asked the lualatex mailing list to do this and was just ignored.
https://www.mail-archive.com/luatex@tug.org/msg07512.html
I guess no body cares about generating large documents so it does not affect others.
May be in the future this can be changed using /usr/local/texlive/2022/texmf.cnf
Note: During doing this, I was getting an error
>lualatex foo.tex This is LuaHBTeX, Version 1.13.2 (TeX Live 2021) restricted system commands enabled. (Fatal format file error; I'm stymied)>
If you get such an error, It turned out there was a hidden folder called $HOME/.texlive2022
in my home folder. Simply deleting this folder and trying again the texmf command above
solved this problem.
It seems newer versions of TL creates this hidden folder which I never knew about.
Now your document can have up to 262144 destination names available instead of the current low value.