There were many posts asking about breaking long string of text/digits (with no spaces) into justified lines. This post is one example. The mostly-agreed-upon solution seems to be adding a zero-width glue with a little stretch between every pair of characters within that string; maybe throw in an extra discretionary to insert/customize hyphens at line ends.
But none of the solutions I saw addressed kerning. Here’re two scenarios where I’d like to preserve kerning:
- Long string of digits (say, 100 digits of pi), set in proportional old-style figures. You see, font designers often kern between 7 (
seven.osf
) and 4 (four.osf
), among many other pairs. Example font: Source Serif 4. - Long string of kanas, set in a Japanese font with
palt
andkern
OpenType features turned on. You see, font designers often specify proportional alternate widths for フ and ォ, and also kern between them, among many other kanas and kana pairs. Example font: Source Han Serif. (Yes, I’m aware thatLuaTeX-ja
already implements this.)
Can kerning be preserved somehow? eTeX/XeTeX solutions preferred, but LuaTeX solutions also welcome.
% run with XeLaTeX or LuaLaTeX
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Source Serif 4}[Numbers={Proportional,OldStyle}]
\newcommand*\+{\hskip 0pt plus 1pt \relax}
\begin{document}
3.14159265358979323846264338327950288419716, figures kerned, cannot be wrapped.
3\+.\+1\+4\+1\+5\+9\+2\+6\+5\+3\+5\+8\+9\+7\+9\+3\+2\+3\+8\+4\+6\+2\+6\+4\+3\+3\+8\+3\+2\+7\+9\+5\+0\+2\+8\+8\+4\+1\+9\+7\+1\+6, can be wrapped, figures no longer kerned.
\end{document}