# How to type “<<test>>” in ttfamily?

I'm trying to produce <<test>> text in \ttfamily, but it looks like:

«test»


Which is not what I'm looking for. When I'm trying $<<$test$>>$ the result is not correct as well because the symbols are not in \ttfamily.

This is full example:

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\texttt{<<test>>}
\end{document}

-
\documentclass{article}\begin{document}\texttt{<<Hello>>}\end{document} works fine, you're probably loading some other package which changes the << to «. –  Juan A. Navarro Feb 24 '11 at 10:42
@Juan you're right, I altered my question –  yegor256 Feb 24 '11 at 11:00
You are trying to avoid \verb|<<test>>|, aren't you? It will not work well inside macro arguments. –  Martin Scharrer Feb 24 '11 at 11:04
@Martin sorry, I didn't understand what do you mean. Could you please correct my sample in order to make it working? –  yegor256 Feb 24 '11 at 11:13
@yegor256: No, your post is fine. You can use \verb to write the <</>> as verbatim in \ttfamily. So \verb|<<test \macro>>| will produce <<test \macro>>. If you want to avoid the content being typeset verbatim use: \verb|<<|\texttt{test}\verb|>>|. As said this doesn't work inside macro arguments etc. –  Martin Scharrer Feb 24 '11 at 11:19

To avoid the combination of two < or > to « and » place a {} between them:

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\texttt{<{}<test>{}>}
\end{document}


They are combined using the ligatures mechanism. So disabling this one e.g using microtype s \DisableLigatures would also work, but isn't recommended because it reduces the overall typeset quality.

You could also use \verb to typeset the <</>> verbatim. (There is also the shortvrb macro which allows you to make this shorter.)

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\verb|<<|\texttt{test}\verb|>>|
\end{document}


If the content is only text without macros etc. you can use one \verb:

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\verb|<<test>>|
\end{document}


Using shortvrb:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{shortvrb}
\MakeShortVerb\|
\begin{document}
|<<|\texttt{test}|>>|
|<<test>>|
\end{document}

-

What you are seeing is a ligature: In T1-encoding TeX replaces the << by the doublequote like it replace two dashes -- by an endash. You can avoid it with different methods (the last is drastic):

\documentclass{article}

\usepackage[T1]{fontenc}
\begin{document}
\texttt{<{}<test>{}>}

\verb+<<test>>+

{\fontencoding{OT1}\texttt{<<test>>}}

\ttfamily \pdfnoligatures\font <<test>> --
\end{document}

-

I would say that using \verb was undesirable anywhere; it's not just that it doesn't work in command arguments (in the absence of cprotect.sty, that is).

I would use one of the commands that define a robust command as expanding to a verbatim string:

\usepackage{verbdef}
...
\verbdef\llt|<<|
\verbdef\ggt|>>|
...
\texttt{\llt{}test\ggt}


(there are other packages that do this, but verbdef is the one I could remember)

-
+1 for pointing out verbdef, sounds like it could be really useful in plenty situations. –  Juan A. Navarro Feb 24 '11 at 11:49
\texttt{\llt test\ggt} will work as well. Macros eat the spaces after them. –  Martin Scharrer Feb 24 '11 at 11:53
\texttt{\char\<\char\<test\char\>\char\>}