带有特殊字符的打字机连字

带有特殊字符的打字机连字

我读这个答案, 和这个关于如何对\texttt文本进行连字符处理以及处理特殊字符。但是,它并没有真正实现我的意图。

\documentclass{scrreprt}
\usepackage{classicthesis,lipsum} % classicthesis to make it closer to my actual document

\DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=23}
\lccode`\:`\:

\begin{document}
This is a meaningless line of text \texttt{and:this:is:meaninglessly:typewritten:text}.
This line is equally meaningless, but also also also also also also contains a \texttt{somewhatlongishwordwhichshouldbehyphenated}
\end{document}

生产

在此处输入图片描述

显然,\font=23不是所提到的字符的代码点在这个答案中。所以我想我可以简单地这样做\usepackage[T1]{fontenc},但这会取消输入文本:

\documentclass{scrreprt}
\usepackage{classicthesis,lipsum}
\usepackage[T1]{fontenc}

\DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=23}
\lccode`\:`\:

\begin{document}
This is a meaningless line of text \texttt{and:this:is:meaninglessly:typewritten:text}.
This line is equally meaningless, but also also also also also also also also contains a \texttt{somewhatlongishwordwhichshouldbehyphenated}
\end{document}

这正确地“连字符”,但字体是错误的

在此处输入图片描述

如何才能获得带有连字符的 T1 字体编码和打字文本?

答案1

T1 编码字体中的字符 23 是不可见的复合字标;OT1 编码字体中没有这样的字符,因此您确实需要 T1。

然而,声明一个字体系列是不够的,事实上你会得到

LaTeX Font Warning: Font shape `T1/cmtt/m/n' undefined
(Font)              using `T1/cmr/m/n' instead on input line 8.

这解释了为什么字体不是等宽的。如果您明确声明了字体系列,则还需要提供整个字体定义,除非字体描述文件已经加载。

\documentclass{scrreprt}
\usepackage{classicthesis,lipsum}
\usepackage[T1]{fontenc}

\lccode`\:=`\:

\AtBeginDocument{%
  % load the .fd file for \ttfamily
  \sbox0{\fontsize{10}{12}%
  % set the hyphenchar for the current font
  \ttfamily\hyphenchar\font=23 }%
  % set the hyphenchar for every other font in the family
  \DeclareFontFamily{\encodingdefault}{\ttdefault}{\hyphenchar\font=23 }%
}

\begin{document}

This is a meaningless line of text \texttt{and:this:is:meaninglessly:typewritten:text}.
This line is equally meaningless, but also also also also also also also also contains 
a \texttt{somewhatlongishwordwhichshouldbehyphenated}

\end{document}

在此处输入图片描述

相关内容