1

I read this answer, and this one about how to hyphenate \texttt text and handling special chars. However, it is not really doing what I intend.

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

produces

enter image description here

So apparently, \font=23 is not the codepoint of the character mentioned in this answer. So I figured I could simply \usepackage[T1]{fontenc}, but this un-typewrites the text:

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

This "hyphenates" correctly, but the font is wrong

enter image description here

How can I get both T1 font encoding with hyphenation and typewritten text?

  • In the first answer you linked, the codepoint is 45, not 23. – shadowtalker Sep 8 '15 at 16:07
  • @ssdecontrol I want to hyphenate without a hyphen char, while 45 would insert the - sign. – oarfish Sep 8 '15 at 16:13
  • if you don't want a hyphen, perhaps you might get help from answers here: How to wrap a word in line without hyphen? – barbara beeton Sep 8 '15 at 16:39
3

The character 23 in the T1 encoded fonts is the invisible compound word mark; there's no such character in OT1 encoded fonts, so you really need T1.

However, declaring a font family is not sufficient and indeed you get

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

which explains why the font is not monospaced. If you declare explicitly the font family, you need also to supply the whole font definitions, unless the font description file has already been loaded.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.