12

I have the problem that both the original Helvetica and the Neue Helevetica font families by Linotype, in their OpenType versions, seem to not have proportional figures, only tabular figures, where each figure is monospaced. I tried switching to proportional figures with fontspec but it doesn't change the appearance a bit.

I need the proportional figures for paragraph text where tabular figures look weird. I find this situation pretty baffling, given that it seems to be a professional and well-known font. The tabular figures are most visible with the "1", which has too much space around it.

I found a possible solution inside LuaLaTeX with this answer: https://tex.stackexchange.com/a/323718/75284 but per David Carlisle's comment this approach would break numeric uses in other LaTeX commands. He mentions virtual fonts, how would one define a new virtual font and apply the needed kerning pairs?

Best would be a solution where one could define both generic kerning (left AND right) and define kerning pairs for fine tuning.

Please substitute Helvetica with a different font in your system if you don't have it.

% -*- program: lualatex  -*- 

\documentclass{article}
\usepackage{fontspec}

\defaultfontfeatures{Ligatures=TeX}

\setmainfont{HelveticaNeueLTStd-Roman}


\begin{document}
\obeylines

11111
88888

10 11 12 13 14 15 16 17 18 19 1.
01 11 21 31 41 51 61 71 81 91 .1

Desired output: 1\kern-.15em{1}

\end{document}

screenshot

edit: follow-up question ragarding setting up both sides of a character to be kerned in LuaLaTeX: LuaLaTeX: fonts.handlers.otf.addfeature kerning pairs with unexpected behaviour

7
  • 1
    I don't think you want to do it via the input buffer callback as you will break numeric uses such a \includegraphics[width=10pt]... you should be able to use luatex's virtual font feature to define a font that has less space around the 1 May 18, 2017 at 20:48
  • @David Carlisle: I rewrite my question because of the mentioned issues with numeric uses in other commands. I didn't foresee that.
    – lblb
    May 18, 2017 at 20:53
  • 1
    "professional and well-known font" but definitely not for tabular data or any kind of number crunching display. original 11 is pretty balanced.
    – percusse
    May 18, 2017 at 20:54
  • @percusse: You find the spaced-out 11 to be balanced? In my view these tabular figures look pretty weird in normal running text, and that's my use case here.
    – lblb
    May 18, 2017 at 20:57
  • 1
    Your 11 looks cramped if used in any other context. These are paragraph typesetting fonts not tabulating data fonts. You are not doing justice to them by using in these situations i.stack.imgur.com/biqQT.png
    – percusse
    May 18, 2017 at 21:11

3 Answers 3

12

enter image description here

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.

enter image description here

\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}
12
  • 2
    Could you please indent the Lua code? Right now it is rather hard to read. May 18, 2017 at 23:04
  • @HenriMenke done May 19, 2017 at 6:41
  • @David Charlisle: Your code gives me an error: TeX capacity exceeded, sorry [max level recursion of virtual fonts=100] \end{document} when changing it to \iftrue.
    – lblb
    May 21, 2017 at 18:08
  • ... and when changing it to use Helvetica: if(string.find(name,'HelveticaNeueLTStd-Roman') it compiles again, but without any change in color or kerning. I have TeX Live 2016.
    – lblb
    May 21, 2017 at 18:14
  • hm that's odd it works for me with texlive 2017 pretest. I don't see why you should be getting deeply nested virtual fonts. May 21, 2017 at 18:22
12

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}

enter image description here

8
  • 1
    that's probably a better idea than mine, although the virtual font way presumably allows you to do more if you really need the ones to be red May 18, 2017 at 22:00
  • 1
    @DavidCarlisle: yes, your code is certainly more powerful. But I'm not sure if it scales well. E.g. what happen if you want to make in Times New Roman all A green and in the mono-font the punctuation blue? May 18, 2017 at 22:10
  • 3
    ... the details are left to the reader. May 18, 2017 at 22:11
  • 4
    I asked on the context list: currently it is not possible to add a "Single adjustment positioning" which would do it, but Hans will add it to the fontloader. It then depends on the luaotfload maintainer when it will be available with lualatex (unless you find a way to add the needed code manually). May 19, 2017 at 9:28
  • 1
    @UlrikeFischer And where might that be? The reference manual (luatex.org/svn/trunk/manual/luatex.pdf) describes how to invoke \directlua and friends, but doesn't seem to discuss what Lua APIs are provided.
    – Matt Kline
    Jan 22, 2018 at 19:49
4

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}

Output

If you want them in math mode, too, you can load that font for digits only in unicode-math.

2
  • This is almost certainly the best idea (+1) even if it doesn't involve exposing the black arts of lua font setup:-) May 21, 2017 at 18:23
  • Huh, looks like I wrote Numbers=Proportional when I meant Tabular.
    – Davislor
    Jul 31, 2018 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .