更新

更新

我发现这个答案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 {--}

\cs_new:Npn \hyphenfix_discardnext:NN #1#2{#1}


\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
        \hyphenfix_discardnext:NN{\futurelet\hyphenfix_nexttok\hyphenfix_ii:w}
    }{
        % from package hyphenat
        \hyp
    }
}

\cs_new:Npn \hyphenfix_ii:w {
    \cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
        \hyphenfix_discardnext:NN{\hyphenfix_emdash:c}
    }{
        \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}

它应该允许我使用-as\hyp{}和 two --as one -,但是在编译时会引发此错误:

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

这个功能会非常受欢迎,因为在我的语言中,我使用了很多-(连字符),而且到处打字(并记住打字)是很可怕的\hyp{}

相关问题:

  1. 对已包含连字符的单词进行充分连字符连接
  2. Hyphenat 不将带连字符的单词连字符
  3. 如何将减号复制为连字符?
  4. 扩展标题中包含 \hyp{} 的缩写词时出现问题
  5. 连字问题

更新

添加包后,我设法让它工作了expl3。我认为它不是必需的。完整示例:

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

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

\cs_new:Npn \hyphenfix_discardnext:NN #1#2{#1}


\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
        \hyphenfix_discardnext:NN{\futurelet\hyphenfix_nexttok\hyphenfix_ii:w}
    }{
        % from package hyphenat
        \hyp
    }
}

\cs_new:Npn \hyphenfix_ii:w {
    \cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
        \hyphenfix_discardnext:NN{\hyphenfix_emdash:c}
    }{
        \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}

在此处输入图片描述


现在,出于好奇。为什么我在其他地方没看到很多人使用这个技巧?

此命令是否会破坏 Latex 中的某些内容?那么,是否不建议使用它?

答案1

在德语中,我们使用 babel 提供的快捷方式"=来输入此类连字符。您也可以激活此类快捷方式,请参阅 babel 文档。

我永远不会在文档中激活连字符并使用像您这样的代码。它可能会在许多地方爆炸。仅显示两个取消注释标记为“错误”的行:

\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 {--}

\cs_new:Npn \hyphenfix_discardnext:NN #1#2{#1}


\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
        \hyphenfix_discardnext:NN{\futurelet\hyphenfix_nexttok\hyphenfix_ii:w}
    }{
        % from package hyphenat
        \hyp
    }
}

\cs_new:Npn \hyphenfix_ii:w {
    \cs_if_eq:NNTF{\hyphenfix_nexttok}{-}{
        \hyphenfix_discardnext:NN{\hyphenfix_emdash:c}
    }{
        \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}

相关内容