3

The word category gets automatically hyphenated as cate-gory by latex, but with the prefix $\infty$-, it doesn't. It still works by manually writing $\infty$-cate\-gory, but putting \hyphenation{$\infty$-cate-gory} in the preamble apparently gets ignored by lualatex, and gives an error message with pdflatex.

Is there a way to automate the hyphenation of words with math prefixes like $\infty$-category?

EDIT:

Here is something that works that I found on the arxiv. But it forces me to write something else instead of the usual hyphen, and I would prefer a solution where I can just write an ordinary hyphen.

\documentclass{article}

\usepackage[shortcuts]{extdash}
\newcommand\oo[1]{$\infty$\=/}

\begin{document}

This is a sufficiently long line of text with many words 
and ending in \oo-category.

Or without the newcommand:

This is a sufficiently long line of text with many words 
and ending in $\infty$\=/category.

\end{document}
3
  • Quick fix: $\infty$-cate\-gory where \- is a “soft hyphen”. For longer words where you don't want to specify each single possible break point with \- the babel package can provide a shorthand for the actual hyphen that still would allow other break points. In some language, this is "=, i.e. $\infty$"=category (with the right settings). Commented Jun 9, 2023 at 1:07
  • Take a look at the comments on the question tex.stackexchange.com/q/636471 defining \hyph. (I'm looking for a better example.) The usage would then be $\infty$\hyph category. Commented Jun 9, 2023 at 1:12
  • Thanks! Yes, I already have a solution where I replace the hyphen with another symbol, using the extdash package and \=/ as described above. But I would like something where I can just write a hyphen as usual and get the correct hyphenation.
    – user313032
    Commented Jun 9, 2023 at 1:16

1 Answer 1

1

Not really an answer, and I am afraid it might not help you, but too long for a comment, and it might help someone else.

I wonder if there is a simple and clean way to do this in pdftex or luatex. In luametatex, a more flexible hyphenation setup is implemented. One can use \hyphenationmode (see the luametatex manual) to set it up (or use the defaults that seem to work well). In lang-ini.mkxl, in a ConTeXt distribution, one can find something like

\permanent \integerdef \completehyphenationcode \numexpr
    \normalhyphenationcode            % \discretionary
  + \automatichyphenationcode         % -
  + \explicithyphenationcode          % \-
  + \syllablehyphenationcode          % pattern driven
  + \uppercasehyphenationcode         % replaces \uchyph
  + \compoundhyphenationcode          % replaces \compoundhyphenmode
  % \strictstarthyphenationcode       % replaces \hyphenationbounds (strict = original tex)
  % \strictendhyphenationcode         % replaces \hyphenationbounds (strict = original tex)
  + \automaticpenaltyhyphenationcode  % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
  + \explicitpenaltyhyphenationcode   % replaces \hyphenpenaltymode (otherwise use \exhyphenpenalty)
  + \permitgluehyphenationcode        % turn glue into kern in \discretionary
  + \permitallhyphenationcode         % okay, let's be even more tolerant
  + \permitmathreplacehyphenationcode % and again we're more permissive
  + \forcehandlerhyphenationcode      % kick in the handler (could be an option)
  + \feedbackcompoundhyphenationcode  % feedback compound snippets
  + \ignoreboundshyphenationcode      % just in case we have hyphens at the edges
  + \collapsehyphenationcode          % collapse -- and ---
\relax

\permanent \integerdef \partialhyphenationcode \numexpr
    \ignoreboundshyphenationcode      % just in case we have hyphens at the edges
% + \explicithyphenationcode          % \-
  + \collapsehyphenationcode          % collapse -- and ---
\relax

\permanent\protected\def\dohyphens {\hyphenationmode\completehyphenationcode}
\permanent\protected\def\nohyphens {\hyphenationmode\partialhyphenationcode}

Hyphenations are on by default, but following the code above, we can switch them off by \nohyphens. Of course, one can have a more granular setup as well by setting the different bits (one can switch one with \bitwiseflip).

Here is a small example where we change the hyphenation setting locally (to prohibit the wanted hyphenation, therefore in red):

\starttext
% \showhyphens{category}
\typ{\showhyphens{category}}

\typ{languages       > hyphenation > show: cat[-||]e[-||]gory}
\blank

\hsize 1.4cm
\blackrule[width=\hsize]\par
$\infty$-category

\blank

\hsize 7cm
\blackrule[width=\hsize]\par
Oh, it's like that, it's like that {\red\nohyphens$\infty$-category.}
Yeah, it's like that, it's like that $\infty$-category. Woah-oh-oh, oh-oh-oh.
\stoptext

hyphenating or not hyphenating

You must log in to answer this question.

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