3

In math articles, sometimes there might be a lot of composed phrases like $R$-module, $r$-$K$-linear, etc., and in some cases it could be confusing whether a - is for hyphenation or is it just a normal - in the phrases.

It would seem inappropriate to completely suppress word break in these phrases (with \mbox, for example) since some of them might be quite long. For now I use the NON-BREAKING HYPHEN (U+02011) though to ensure that the breaking point is not at those - which are part of the phrases, so there is no risk that one shall misread them as a hyphen char. However, it is still strange to see something like $r$-$k$-li- at the end of a line.

In these cases, is it possible to make the hyphen char - in gray (for example as \textcolor{gray}{-}) or some other style, globally, so as to differ from the normal -?


At first this seems to me an easy question, but after searching around on this site it turns out that one seems to have very little control over the hyphen chars (pre-break, post-break and no-break, according to the question given below). Shouldn't we have full access to them and can change them to whatever we want?

I've checked in particular this question, but the solution seems to aim at changing the hyphen char only locally (not sure if I understood the usage of \discretionary correctly). Also, it seems that the treatment for hyphen char differs under different engines, thus if it is too much to ask for a universal way to achieve this, I hope that the solution (if exists) can at least work for LuaLaTeX.

Jinwen
  • 8,518
  • A different character can be used as hyphenation char with a command like \hyphenchar\tenrm="7B. Perhaps that is already sufficient for you? – Heiko Theißen Jul 02 '22 at 14:00
  • @HeikoTheißen Is it possible to change it to something like \textcolor{gray}{-}? I'm always getting Missing number, treated as zero. – Jinwen Jul 02 '22 at 14:10
  • No, you can only set a character number, no additional commands like \textcolor. – Heiko Theißen Jul 02 '22 at 14:11
  • @HeikoTheißen Thank you. And that is strange, by the way, since I thought that it would be very easy to accomplish what I asked for in this question, but it turns out that we don't seem to have much control to the hyphen chars (pre-break and post-break). – Jinwen Jul 02 '22 at 14:18
  • Searching through https://tex.stackexchange.com/q/173209/250119 these solutions all use token manipulation techniques, which is obviously unusable here. I also tried interchartoks approach in https://tex.stackexchange.com/a/620090/250119 but it seems to not work. – user202729 Jul 02 '22 at 15:11
  • I guess there's always the pre_output_filter callback to "manually" replace the hyphenations (if you set it to some unique unused character, it can be distinguished from the normal hyphens) with differently-colored characters, not sure if it can actually work however. – user202729 Jul 02 '22 at 15:16
  • On the other hand, some font definitely have colored characters somehow (emoji?) so maybe another approach is possible... – user202729 Jul 02 '22 at 15:17
  • Indeed LuaTeX can render colored characters in fonts. https://tex.stackexchange.com/questions/520182/is-there-any-tex-based-engine-capable-of-rendering-the-colored-font Maybe create a virtual font or something to add the colored-hyphen character in. – user202729 Jul 02 '22 at 15:19
  • @user202729 The virtual font approach seems promising, but it only works for pdfLaTeX, right? The font loading method seems to be incompatible with fontspec. – Jinwen Jul 02 '22 at 15:57
  • Looks so. It remains possible to "somehow" create a truetype font file that has colors though. – user202729 Jul 02 '22 at 16:05

0 Answers0