11

I am using \texttt to write my code snippets in Courier font including \texttt{>>>}. If I compile, this is substituted to ». How can I prevent that from happening?

  • I am unable to escape with \texttt{\>\>\>}.

  • I do not want to use \ggg of the amssymb package since that looks slightly different.

  • If possible I would also like to avoid using \verb||.

Wrzlprmft
  • 759
User12547645
  • 233
  • 1
  • 5

2 Answers2

14

The addition of a group around the central > will prevent each from seeing the others, and therefore should prevent (for lack of a better word) the ligature from forming.

Note: See comments to this answer, which are very illuminating, which explains why this technique will work in pdflatex but not lualatex!

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\begin{document}
\texttt{>{>}> versus >>>}
\end{document}

enter image description here

  • 1
    This only works as long as >{>}> is not considered for hyphenation, which might or might not be the case. I think in \texttt it is actually safe, because by default LaTeX disables hyphenation for this family. Note that TeX merely considering the compound for hyphenation is already enough to break this mechanism, it doesn't have to be actually hyphenated. – Henri Menke Jul 30 '20 at 02:00
  • 1
    @HenriMenke I am not sure I understand your point. Are you saying for (other than texttt) that this answer could fail, or only that it could get hyphenated, or that, if hyphenated, it could fail? – Steven B. Segletes Jul 30 '20 at 10:34
  • 4
    When TeX hyphenates words, it breaks all ligatures, scans for hyphenation points and then reinserts the ligatures. At that point, however, the braces are no longer present because they don't create a node, so TeX will reinsert a previously suppressed ligature. For this it is sufficient that TeX considers the word for hyphenation, it doesn't actually have to hyphenate it. In \texttt this problem will not show up as long as hyphenation is disabled (the default). If you want to make really sure that TeX never ligatures this thing, you have to write >\kern0pt>\kern0pt>. – Henri Menke Jul 30 '20 at 11:59
  • 1
    @HenriMenke Thank you for that informative reply. But then why, in my MWE, if I change \texttt to \textit, and add enough leading verbiage to force a line break in the paragraph, does the problem not arise? – Steven B. Segletes Jul 30 '20 at 12:02
  • 4
    @StevenB.Segletes In addition to forcing a line break, you actually need a paragraph which gets hyphenated, otherwise TeX never runs the second line breaking pass where it considers word for hyphenation. I also think this only triggers in words which are considered for hyphenation in the sense that there is at least one potential hyphenation point identified in the word, so >>> should be safe. (Of course breaking ligatures like this doesn't work in LuaTeX at all) – Marcel Krüger Jul 30 '20 at 15:32
  • 1
    @StevenB.Segletes In pdflatex with T1 encoding, the \lccode of > is 0, so this doesn't happen for >> and >{>} can be used. The point that this method does not work in luatex, should be emphasised. – Andrew Swann Aug 05 '20 at 08:03
12

This happens when you use the T1 encoding.

You can disable the ligature that maps >> to » with microtype. I also removed the ligature from << to « for symmetry. The first line shows that the ligatures are not suppressed altogether, but only when using the monospaced font.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{courier}
\usepackage{microtype}

\DisableLigatures[<,>]{encoding=T1,family=tt*}

\begin{document}

<<This is quoted>>

\texttt{>>>}

\texttt{<<<}

\end{document}

enter image description here

egreg
  • 1,121,712