# How to use the standard - (hyphen) as the \hyp{} command from the hyphenat package?

I found this answer on http://www.oipapio.com/question-79176

\documentclass[10pt,a5paper,twoside]{article}
\usepackage{hyphenat}

\cs_new:Npn \hyphenfix_emdash:c {---}
\cs_new:Npn \hyphenfix_endash:c {--}

\catcode\-=\active

\cs_new_protected:Npn -{
\futurelet\hyphenfix_nexttok\hyphenfix_i:w
}

\cs_new:Npn \hyphenfix_i:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
%discard the next - token
}{
% from package hyphenat
\hyp
}
}

\cs_new:Npn \hyphenfix_ii:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
}{
\hyphenfix_endash:c
}
}

\begin{document}

\section{Show font}

Tests.

Encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding.

Encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding.

\end{document}


It should allow me to use - as \hyp{} and two -- as one -, but when compiling it throws this error:

Package: hyphenat 2009/09/02 v2.3c hyphenation utilities
\langwohyphens=\language77
LaTeX Info: Redefining \_ on input line 43.
)test1.tex:4: Undefined control sequence
Here is how much of TeX's memory you used:
232 strings out of 493314


This feature would be very welcomed because, in my language, I use a lot of - (hyphens) and it is horrible to keep typing (and remembering to type) \hyp{} everywhere.

Related questions:

# Update

I managed to get it working after adding the expl3 package. I thought it was not required. Full example:

\documentclass[10pt,a5paper,twoside]{article}
\usepackage{hyphenat}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new:Npn \hyphenfix_emdash:c {---}
\cs_new:Npn \hyphenfix_endash:c {--}

\catcode\-=\active

\cs_new_protected:Npn -{
\futurelet\hyphenfix_nexttok\hyphenfix_i:w
}

\cs_new:Npn \hyphenfix_i:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
%discard the next - token
}{
% from package hyphenat
\hyp
}
}

\cs_new:Npn \hyphenfix_ii:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
}{
\hyphenfix_endash:c
}
}
\ExplSyntaxOff

\begin{document}

\section{Show font}

Tests.

Encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding.

Encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding\hyp{}encoding.

\end{document}


Now, by curiosity. Why I do not see much people using this trick everywhere else?

Does this command is breaking something in latex? Then, is it unadvised to use it?

In german we use a shortcut provided by babel "= to input such hyphens. You could activate such a shortcut too, see the babel documentation.

I would never in a document activate the hyphen and use code like yours. It can explode it much too many places. Just to show two uncomment the lines marked with "error":

\documentclass[10pt,a5paper,twoside]{article}
\usepackage{hyphenat}
\usepackage[ngerman]{babel}
\usepackage{expl3}
\usepackage{tikz}
\ExplSyntaxOn
\cs_new:Npn \hyphenfix_emdash:c {---}
\cs_new:Npn \hyphenfix_endash:c {--}

\catcode\-=\active

\cs_new_protected:Npn -{
\futurelet\hyphenfix_nexttok\hyphenfix_i:w
}

\cs_new:Npn \hyphenfix_i:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
%discard the next - token
}{
% from package hyphenat
\hyp
}
}

\cs_new:Npn \hyphenfix_ii:w {
\cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
}{
\hyphenfix_endash:c
}
}
\ExplSyntaxOff

\begin{document}

\section{Show font}

Tests.

Encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding-encoding.

Encoding"=encoding"=encoding"=encoding"=encoding"=encoding"=encoding"=encoding"=encoding"=encoding.

\newlength\mylength
%\setlength\mylength{-1cm} %error

%\tikz\draw(0,0)--(1,1);   %error

\end{document}

• Thank you for this! Until now I have been using the hyphenat package. But this is much easier :) I actually found out yesterday, that there is a \hyphen{} command, which does basically the same as \hyp{}` but without needing the hyphenat package. I could not find out which ressource this command is delivered from. Does anybody know? – The Shadow Sep 6 '19 at 7:29