I have seen Force hyphenation for a word beginning with a digit, but I do not think the solution there applies in my case.
So, I use pandoc to write Markdown, and to export to PDF via Latex. I have the following Markdown document, test.md:
---
author: John Doe
date: \today
---
The mimsy borogoves when outgrabeing STM32CubeProgrammer
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere mauris justo, vitae molestie tortor mollis ut. Donec nec dolor consectetur, porttitor augue et, feugiat odio. Aenean quis sem tortor. Sed finibus justo sit amet massa consectetur malesuada. Quisque enim lacus, commodo in varius a, congue id nisl. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Pellentesque auctor est vitae neque finibus dapibus. In vitae nisl in arcu fringilla faucibus non ac urna. Duis ut semper velit. Fusce turpis diam, elementum in libero fringilla, posuere sodales dolor. Quisque pellentesque, ipsum ac cursus ullamcorper, nibh nisi dictum ligula, sed pretium purus nunc eget dolor. Maecenas nec magna ullamcorper, suscipit erat et, mattis risus. Sed vehicula purus eu dictum varius.
The .tex output that pandoc generates based on this Markdown is a bit more complicated, but can be reduced to this, let's call it test.tex:
\documentclass[]{article}
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\author{John Doe}
\date{\today}
\begin{document}
\hypertarget{the-mimsy-borogoves-when-outgrabeing-stm32cubeprogrammer}{%
\section{The mimsy borogoves when outgrabeing
STM32CubeProgrammer}\label{the-mimsy-borogoves-when-outgrabeing-stm32cubeprogrammer}}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere
mauris justo, vitae molestie tortor mollis ut. Donec nec dolor
consectetur, porttitor augue et, feugiat odio. Aenean quis sem tortor.
Sed finibus justo sit amet massa consectetur malesuada. Quisque enim
lacus, commodo in varius a, congue id nisl. Orci varius natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Pellentesque habitant morbi tristique senectus et netus et malesuada
fames ac turpis egestas. Pellentesque auctor est vitae neque finibus
dapibus. In vitae nisl in arcu fringilla faucibus non ac urna. Duis ut
semper velit. Fusce turpis diam, elementum in libero fringilla, posuere
sodales dolor. Quisque pellentesque, ipsum ac cursus ullamcorper, nibh
nisi dictum ligula, sed pretium purus nunc eget dolor. Maecenas nec
magna ullamcorper, suscipit erat et, mattis risus. Sed vehicula purus eu
dictum varius.
\end{document}
The result of doing pdflatex test.tex then looks like this:
Clearly the "STM32CubeProgrammer" is too long, and breaks the margins; Latex could have hyphenated it, but it does not know it.
So I tried adding in the preamble:
\hyphenation{STM32-Cube-Pro-gram-mer}
... however, that fails with:
! Not a letter.
l.5 \hyphenation{STM3
2-Cube-Pro-gram-mer}
?
Yes, indeed, 3 is not a letter ... and apparently "\hyphenation doesn't take numbers (Define global hyphenation for words containing numbers)"
So the thing is:
- Since this heading should also end up in TOC, and is in pandoc Markdown (and it might end up in other formats), I would not like to add (La)TeX specific commands like
\discretionary{-)(as suggested in hyphenation next to a parenthesis) in the heading itself
Thus, the best solution for me, would be to define a hyphenation for the "STM32CubeProgrammer" globally, and the let LaTeX take care of it (hyphenate when appropriate, in heading, or header/footer, or TOC) -- but I cannot use \hyphenation since it does not parse numbers.
So, my question is - is there anything else I could do in the Latex preamble, so that Latex treats "STM32CubeProgrammer" as a hyphenate-able word? I thought, if digits "break" hyphenation search, maybe Latex sees the portion after the 32 as a new word input for hyphenation, so I tried \hyphenation{Cube-Pro-gram-mer}, but that had no effect.
Maybe there is something that can be done, by temporarily changing the catcodes of 3 and 2, just so \hyphenation passes? Unfortunately, I do not know enough about the internals of Latex and catcodes, to be able to solve this myself ...



