I write a software that generates LaTeX code. For various reasons, I'd like to know the width of the largest character, relatively to the current font settings.
As a developer, I wrote a Perl script that produces a LaTeX document (let us call it "output.tex"). This LaTeX document ("output.tex"), once processed through LuaLaTeX produces a files that contain the width (and other dimensions) of all characters (let use call it "output.dim").
Please note that if you are interested in the Perl script, you can find it here (this is the file "char.pl").
The file "output.tex" looks like :
Please note that I don't show here all the content of the file. I removed some lines. You can get the full file on this permanent link.
\documentclass{article}
\usepackage[a4paper]{geometry}
\renewcommand{\normalsize}{\fontsize{10pt}{12pt}\selectfont}
\usepackage{newfile}
\newoutputstream{dimensions}
\openoutputfile{\jobname.dim}{dimensions}
\setlength{\parindent}{0pt}
\setlength{\fboxsep}{0px}
\begin{document}
\newsavebox{\boxaaaa}
\savebox{\boxaaaa}{\framebox{a}}
\addtostream{dimensions}{a: \the\wd\boxaaaa, \the\ht\boxaaaa, \the\dp\boxaaaa}
\newsavebox{\boxbaaa}
\savebox{\boxbaaa}{\framebox{b}}
\addtostream{dimensions}{b: \the\wd\boxbaaa, \the\ht\boxbaaa, \the\dp\boxbaaa}
\newsavebox{\boxcaaa}
\savebox{\boxcaaa}{\framebox{c}}
\addtostream{dimensions}{c: \the\wd\boxcaaa, \the\ht\boxcaaa, \the\dp\boxcaaa}
% More lines...
\newsavebox{\boxzzka}
\savebox{\boxzzka}{\framebox{8}}
\addtostream{dimensions}{8: \the\wd\boxzzka, \the\ht\boxzzka, \the\dp\boxzzka}
\newsavebox{\boxzzla}
\savebox{\boxzzla}{\framebox{9}}
\addtostream{dimensions}{9: \the\wd\boxzzla, \the\ht\boxzzla, \the\dp\boxzzla}
\end{document}
The file "output.dim" looks like :
Please note that I don't show here all the content of the file. I removed some lines. You can get the full file on this permanent link.
a: 5.8pt, 4.70554pt, 0.4pt
b: 6.35556pt, 7.34444pt, 0.4pt
c: 5.24443pt, 4.70554pt, 0.4pt
...
8: 5.8pt, 6.84444pt, 0.4pt
9: 5.8pt, 6.84444pt, 0.4pt
OK. So, using the content of the generated file "output.dim", I can get the dimensions of all characters for the given font settings. And, thus, I can get the maximum width of a character (a simple script would do the job).
This solution works... however, it is not elegant. You have to execute (Perl) scripts to get dimensions, and then you can produce a LaTeX document (through other scripts). Besides, all the calculations on dimensions should be handled by LaTeX.
Do you have a more elegant solution to get the width of the widest character, relatively to the current font settings ?
Thanks.

\the\fontcharwd\font`\wto get the width of the w. But beside this it really depends on what you mean by "char". – Ulrike Fischer Jul 16 '18 at 09:53