# Making hyphens in text slightly longer and thinner

Even though I would think that this is a duplicate, I was not able to find any answer to a rather simple question. I am concerned about the appearance of various hyphens or dashes. In this discussion, it is suggested that one has to type, say, Robertson-Walker metric as Robertson--Walker, i.e. with an en-dash, whereas semi-simple group would come with a hyphen, i.e. just semi-simple. But what worries me is that, apart from the fact that the hyphen is very short, it's also thicker than the en-dash.

I'd like to have the hyphen being typeset like an en-dash, just a bit shorter, i.e. as in the middle but not bottom example of this list (the top entry is just the en-dash):

Here is the MWE to play with.

\documentclass{article}
\pagestyle{empty}
\begin{document}
Robertson--Walker metric\dots looks fine but IMHO semi-simple Lie group doen't look
too good. Is there any way to make \verb|semi-simple| being typeset as
semi\raisebox{2pt}{\rule{4pt}{0.2pt}}simple?

Comparison: \begin{tabular}{l}
A--B \\ A\raisebox{2pt}{\rule{4pt}{0.2pt}}B \\ A-B
\end{tabular}
\end{document}


QUESTION: Is there a (simple or semi-simple) way of achieving this?

NOTE: I am not interested in proposals that would mess up the minus signs in equations or do other harm, and I'd also like to avoid having to type some LaTeX commands instead of the hyphens. In the ideal case, only the appearance of - would change.

• luatex a possibility? Apr 2, 2018 at 21:43
• well your choices are a virtual font (easier in luatex as you can make it on-the-fly within the tex document) or make - active to add the modified character, making it active you can try to make it safe again in math mode etc, but hard to do in general but if it only has to be safe enough to work in the one document that's probably what I'd do.... Unless you want automatically inserted hyphens also to b eaffected? in which case you need a virtual font. Apr 2, 2018 at 21:48
• @DavidCarlisle Would you mind posting a "safe-enough non-luatex" proposal as an answer? Or would it be possible to make the en-dashes and em-dashes a bit shorter and introduce something longer that can be typeset as ----, say?
– user121799
Apr 2, 2018 at 21:54
• @HenriMenke Most people don't read the journal anyway, and I want my arXiv paper to look good.
– user121799
Apr 2, 2018 at 21:55
• @PeterWilson All I want is to make the hyphen have the same line width as en-dash and em-dash, and make it slightly longer.
– user121799
Apr 3, 2018 at 19:11

You can use the pre_linebreak_filter to walk the hlist, search for disc nodes and replace their pre, post, and replace fields with rules if they contain the hyphen. This leaves the hyphen invariant in math mode and in non-discretionary contexts.

It is true that as of today arXiv does not accept LuaTeX but there are ways around that: https://www.monperrus.net/martin/how-to-use-lualatex-arxiv

\documentclass{article}
\usepackage{luacode}
\begin{luacode*}

local pt = 2^16

local r = node.new("rule")
r.width  = 4*pt
r.height = 2.2*pt
r.depth  = -2*pt

end

if n.id == node.id("disc") then
for _,v in pairs({"pre","post","replace"}) do
if is_hyphen(n[v]) then
n[v] = node.copy(r)
end
end
end
end
end

longhyphen,
"longhyphen")

\end{luacode*}

\begin{document}

Robertson--Walker

semi-simple

$a - b$

no disc-

-disc

\end{document}


• This is a very nice answer! However, I'd like to wait with lualatex until it is supported by the arXiv. Do you think there is a way that does not rely on lualatex?
– user121799
May 4, 2018 at 3:28

Another option, apart from the robust and preferable LuaTeX-solution, is to mess with the catcodes.

The hyphen is now an active character. In math mode it simply expands to a minus, but in text mode it swallows the next two tokens, examines them whether they are hyphens and either inserts the rule to replace a single hyphen or it expands to the appropriate number of original hyphens to form the dash ligatures.

This fails horribly in case of e.g.

-\begin{environement}


One could maybe make it brace-group-aware, but then, why would I do that?

No refunds!

\documentclass{article}

\chardef\textminus=\-
\mathchardef\mathminus=\mathcode\-

\begingroup
\makeatletter
\catcode-=13
\protected\long\gdef\longhyphen#1#2{%
\ifx#1-\relax
\textminus\textminus
\ifx#2-\relax
\textminus
\else
#2%
\fi
\else
\raisebox{2pt}{\rule{4pt}{0.2pt}}#1#2%
\fi
}
\protected\gdef-{%
\ifmmode
\expandafter\mathminus
\else
\expandafter\longhyphen
\fi
}
\endgroup

\begin{document}

Robertson---Walker

Robertson--Walker

semi-simple

$a - b$

\catcode-=13

Robertson---Walker

Robertson--Walker

semi-simple

$a - b$

\end{document}


• Thanks again. But I think this is too dangerous, as explained here. I was too optimistic probably, was thinking one could just take the hyphen from another font without making it active.
– user121799
May 4, 2018 at 3:36
• @marmot Well, the only solution I can think of is then to define a macro \longhyphen and peform a search-and-replace throughout the document, taking care to not replace hyphens in math mode. May 4, 2018 at 6:16

Another possibility, that has not been explored yet it using a virtual font. To this end we follow the How to create a virtual font? tutorial to create our instance.

First copy the base font (I use cmr10) to the current directory and convert it to a property list.

cp kpsewhich cmr10.tfm .
tftopl cmr10.tfm > cmlh10.vpl


I chose the filename cmlh10 where lh stands for “long hyphen”. Open the file cmlh10.vpl and add the following line at the very top.

(MAPFONT D 0 (FONTNAME cmr10))


Then find the line starting with (CHARACTER O 55 and replace the character entry with the following

(CHARACTER O 55
(CHARWD R 0.500002)
(CHARHT R 0.430555)
(CHARIC R 0.027779)
(MAP
(SELECTFONT D 0)
(SETCHAR O 173)
)
)


The slots 55 and 173 are both in octal. The slot 55 holds the hyphen, slot 173 the endash, i.e. we are mapping the hyphen to endash. Another alternative would be to draw a custom rule instead of just mapping endash to hyphen.

(CHARACTER O 55
(CHARWD R 0.4)
(CHARHT R 0.28)
(MAP
(MOVEUP R 0.255)
(SETRULE R 0.025 R 0.4)
)
)


Assemble the virtual font using

vptovf cmlh10.vpl


In you TeX document replace cmr10 with cmlh10 in the NFSS font loading.

\DeclareFontShape{OT1}{cmr}{m}{n}{
<-6>    cmr5
<6-7>   cmr6
<7-8>   cmr7
<8-9>   cmr8
<9-10>  cmr9
<10-12> cmlh10
<12-17> cmr12
<17->   cmr17
}{}
\documentclass{article}
\pagestyle{empty}
\begin{document}

Robertson--Walker

semi-simple

$a - b$

no disc-

-disc

\end{document}


In the screenshot I mapped the endash to hyphen.

• Thanks a lot! (Do you think it will work on the arXiv? If so, what does one have to do to make it work there?)
– user121799
Aug 12, 2019 at 3:44
• @user121799 That should work on arXiv, but of course you have to bundle the cmlh10.tfm with your document. Aug 12, 2019 at 3:49