LuaLaTeX: Change kerning around "1" to simulate proportional figures
As you seem to want to adjust the spacing only if more numbers are involved, you could change the kernings between two numbers:
\documentclass{article}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX}
\directlua
{
fonts.handlers.otf.addfeature
{
name = "ktest",
type = "kern",
data =
{
["1"] = {
["1"] = -200 ,
["2"] = -200
},
},
}
}
\setmainfont{Arial}[RawFeature=+ktest]
\setsansfont{Arial} %to show the difference
\begin{document}
1111121212
\sffamily
1111121212
\end{document}
The code below using Arial rather than Helvetica produces the above.
The OP confirms that the code worked with teh Helvetica variant in the original question if
if(string.find(name,'HelveticaNeueLTStd'),
is used in place of
if(string.find(name,'arial')
If you switch \iffalse
to \iftrue
to use the modified font loader then you get the output below in which the typesetting of 1
has been changed in a subtle barely noticeable way.
\documentclass{article}
\usepackage{fontspec}
\iffalse
\directlua{
%
orig_define_font=luatexbase.remove_from_callback('define_font','luaotfload.define_font')
%
function x_define_font(name,size,id)
local thisfont=orig_define_font(name,size,id)
if(string.find(name,'arial') and type(thisfont)=='table') then
thisfont.characters[49].width=thisfont.characters[49].width-200000
thisfont.characters[49].commands = {
{'right',-100000},
{'special','pdf: 1 0 0 rg'},
{'char',49},
{'special','pdf: 0 g'},
{'right',-100000},
}
end
return thisfont
end
%
%
luatexbase.add_to_callback('define_font',x_define_font,'my_define_font')
%
}
\fi
\setmainfont{arial}
\begin{document}
abc 111 111 111 X
abc 123 111 222 X
abc 222 444 111 X
\end{document}
This doesn’t do it by adjusting the kerning, but if what you want are Helvetica-style proportional digits, an alternative approach is to substitute a font that has them, such as TeX Gyre Heros, and set the OpenType options to use them.
\documentclass[varwidth]{standalone}
\usepackage{fontspec}
\setsansfont{Arial}
\setmainfont{Arial}
\newfontfamily\pronums{TeX Gyre Heros}[Numbers={Lining,Proportional}, Scale=MatchUppercase]
\begin{document}
\fontsize{48}{48}
{\sffamily 111 222 333}
{\pronums 111 222 333}
\end{document}
If you want them in math mode, too, you can load that font for digits only in unicode-math
.