Enable hyphenation for monospaced font

Ulrike Fischer news3 at nililand.de
Fri Jul 30 23:30:11 CEST 2021


Am Fri, 30 Jul 2021 11:37:51 +0300 schrieb Teemu Likonen:

> I need need to enable hyphenation for monospaced font. I use fontspec
> package and Lualatex compiler. I currently do this with HyphenChar
> option:
> 
>     \usepackage{fontspec}
>     \setmonofont{libertinusmono-regular.otf}[HyphenChar=-]
> 
> This works but fontspec gives warning at the compile time:
> 
>     Package fontspec Warning: Ignored XeTeX-only feature: 'HyphenChar'.
> 
> Fontspec's manual says that HyphenChar is a Xetex-only feature except
> HyphenChar=None which also works with Luatex. So, my HyphenChar=-
> shouldn't work with Lualatex but it actually does.

It doesn't. It enables hyphenation but it doesn't set the
hyphenchar. You can see the difference if you use an unusual one and
the compare xelatex and lualatex:


\documentclass{article}
\usepackage{fontspec}
\setmonofont{libertinusmono-regular.otf}[HyphenChar=!]
\textwidth 1cm
\begin{document}
\ttfamily abc xxx!xxx!xxx!xxx something something

\end{document}



> What is the preferred, officially supported and documented way to enable
> hyphenation for monospaced font using fontspec and Lualatex?

I would reset the default font features before loading the monofont:

\defaultfontfeatures
 [\ttfamily]
 {WordSpace={1,0,0},
%  HyphenChar=None, % remove this
  PunctuationSpace=WordSpace}



-- 
Ulrike Fischer 
https://www.troubleshooting-tex.de/



More information about the texhax mailing list.