3

I made a font for functional harmonic analysis in music which contains ligatures and other OpenType “magic”. TobiW at this thread on a german-speaking typography forum showed me how to use the font which contains ligatures like -5 and _5 and -~ in LuaLaTeX (by setting the \catcodes for ~ and _).

Now almost everything works but not several consectuive ligatures containing a - (hyphen) — only the last of them is rendered by LuaLaTeX. For example, -4-4-4 should give ⁴⁴⁴ but instead it gives -4-4⁴. In contrast, _4_4_4 gives ₄₄₄ as expected.

It’s almost certainly a ((Lua)La)TeX problem, Pango/Harfbuzz render the example correctly. TobiW suggested to turn off the TeX ligatures (like -- for –) and redefining \hyphenchar but neither helped. Any idea why the hyphen still is so special?

\documentclass{article}

\usepackage{fontspec}

\newcommand{\func}[1]{{%
\fontspec{Harmony}[RawFeature=-tlig]% turn off TeX ligatures
\hyphenchar\font=-1\relax% don’t use - for hyphenation
\catcode45=12\relax% 45=hyphen
\catcode95=12\relax% 95=underscore
\scantokens{#1\empty}% \scantokens makes catcode definitions apply to #1
}}


\begin{document}
\func{-4-4}
\func{_4_4}
\func{-- –}
\end{document}

Thanks in advance for any help!

PS, almost forgot: I have to use LuaLaTeX for another reason, so using XeLaTeX instead (if this would help) is not an option for me.

  • \hyphenchar does nothing in LuaTeX. – egreg Aug 7 '18 at 10:21
  • @egreg according to the docu, \hyphenchar=-1 does suppress hyphenation (that's its only use). – Ulrike Fischer Aug 7 '18 at 10:28
  • @UlrikeFischer I see no difference: with \hyphenchar\font=-1 there is still a feasible line break point after -. It may depend on the LuaTeX version I use (1.07). – egreg Aug 7 '18 at 10:42
  • I don't have the font and so can't test but you could try \prehyphenchar`\^^ad – Ulrike Fischer Aug 7 '18 at 10:54
  • Thanks for your answers! \prehyphenchar doesn’t work for me either. I made a minimal font (only containing three characters hyphen, a, A, and a single ligature substitution -a → A) for demonstration but I don’t know how to attach it to this question … – MalteM Aug 7 '18 at 11:39
3

In LuaTeX you have to use \exhyphenchar instead of \hyphenchar. Also the value is queried when the paragraph is finished and after a \hbox/\vbox group already ended, so you could use

\documentclass{article}

\usepackage{fontspec}
\newfontface\harmonyfont{Harmony}

\newcommand{\func}[1]{{%
  \leavevmode
  \exhyphenchar=-1
  \hbox{%
    \harmonyfont
    \catcode`\_=12
    \scantokens{#1}% \scantokens makes catcode definitions apply to #1
  }%
}}

\begin{document}
\func{-4-4}
\func{_4_4}
\end{document}
  • 1
    I would recommend not using \fontspec, but rather \newfontface in the preamble. – egreg Aug 7 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.