16

Consider the following MWE:

\documentclass{article}    
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
a << b
\end{document}

When compiling, the two "<" characters get replaced by a single "opening french quote" character (sorry, don't know its name).

Is there a way to avoid this behaviour (besides using math mode) ?

Edit: I know I can get around with a $<<$ b or (as suggested in comments) with a {<}< b, or with verbatim mode. My question can be rephrased as:

Is there a way to tell Latex NOT to do these automatic character replacements?

Edit2: Use case: I am putting up some course text documents on OSes, and appending to a file gets written a >> b.

  • Do you want to suppress the ligature always or only in some cases? – Ulrike Fischer Sep 15 '16 at 14:35
  • 2
    Well, a {<}< b certainly would get around the ligature. – Steven B. Segletes Sep 15 '16 at 14:39
  • 1
    Well, considering that both Ulrike and I weren't sure whether you were looking for a one-off or a global solution, perhaps you should edit your question to clarify exactly what you are looking for. Remember, we don't necessarily have a sense of your experience level with LaTeX. – Steven B. Segletes Sep 15 '16 at 14:46
  • 1
    looks like you are looking for some verbatim rendering, hence try \verb@a <<b@ or in a verbatim environment. – user4686 Sep 15 '16 at 14:51
  • 1
    What's the semantics/purpose of << here? – Heiko Oberdiek Sep 15 '16 at 19:23
19

If you want it globally you can use microtype:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\DisableLigatures[<]{encoding = T1}
\begin{document}
a << b
\end{document}

enter image description here

  • Thanks, never used that package, just learned something today! – kebs Sep 15 '16 at 14:55
  • 5
    Since the user (@kebs) says (s)he has never used the microtype packages, I think it would be useful to add a notice to clarify that loading it affects the typesetting well beyond the sheer fact of making it possible to suppress ligatures. – GuM Sep 15 '16 at 23:31
  • @GustavoMezzetti: I still hope that users at least skim a few pages of the documentation before using an unknown package. – Ulrike Fischer Sep 16 '16 at 7:04
  • 4
    Your hope is waaaay too optimistic ;-) – Massimo Ortolano Sep 16 '16 at 11:27
  • 1
    @MassimoOrtolano: Then they deserve what they get. – Ulrike Fischer Sep 16 '16 at 11:31
19

For locally disabling the ligature you have several methods:

\documentclass{article}    
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
a << b

a <{}< b

a {<}< b

a <\/< b

a <\textcompwordmark< b

\end{document}

I'd prefer the one with \/, because it's engine independent; the same example (but with fontspec) in LuaTeX

\documentclass{article}    

\usepackage{fontspec}

\begin{document}
a << b

a <{}< b

a {<}< b

a <\/< b

a <\textcompwordmark< b

\end{document}

would give

enter image description here

because LuaTeX ignores braces when doing ligatures.

Of course, the best thing is to define a personal command, so you can modify the rendering without chasing the document for <\/<:

\newcommand\textll{<\/<}

and

a \textll{} b

When somebody will tell you that some negative kerning must be applied between the less than symbols, you'll be happy of having preferred an abstract method.

Side note: this assumes the OT1 encoding is not used; with it the input << would not produce a ligature, but ¡¡ (two reverse exclamation marks); the ligature << for a left guillemet is only active in the T1 encoding (and possibly LY1) and, with fontspec and (Xe|Lua)LaTeX, for fonts loaded with the Ligatures=TeX option.

  • you might comment (re engine independence) that with original knuth tex, the < would be rendered as an upside down exclamation point. the \/ doesn't overcome that. probably irrelevant for most people these days, but there are still some "holdouts". – barbara beeton Sep 15 '16 at 15:00
  • Thanks for answer. Solution 4 & 5 is indeed what I want. And defining a new command does seem a good option. – kebs Sep 15 '16 at 15:05
  • Another engine-independent method worth mentioning is the insertion of an explicit kern, e.g., \kern0pt. – Mico Sep 15 '16 at 19:32
  • @Mico Yes, \/ is indeed an explicit kern. – egreg Sep 15 '16 at 19:38
  • 1
    @barbarabeeton the engine isn't really the issue there (you'd get Spanish punctuation by default in (say) xelatex as well, it's the font (and font encoding) that matter so anything using computer modern will do that. – David Carlisle Sep 15 '16 at 20:07
12

In the comments it was specified that this is actually bash source code. So LaTeX should know that it is bash source code. This can be done be using, e.g., the listings package:

\documentclass{article}    
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}
As listing:
\begin{lstlisting}[language=bash]
a << b
\end{lstlisting}

Inline:
\lstinline[language=bash]{a << b}
or
\lstinline[language=bash]/a << b/
\end{document}
  • True, and I do use the listings package in many occasions! But listings produces a separate text block, and the idea here is to have it "inline". Thanks for answering, but the question is about the general case. – kebs Sep 16 '16 at 15:27
  • And no, not only bash typesetting as use case. It's the same syntax with the Windows shell. – kebs Sep 16 '16 at 15:34
  • You can use inline-listings. See the last lines of the answer. And for Windows shell source code the answer is the same ;) – gerw Sep 17 '16 at 18:45
  • Ah, ok, I'll check the "inline" listings mode, never used it that way, thanks. – kebs Sep 17 '16 at 21:20
  • 1
    It works if you do not use {} as delimiters, e.g., \begin{tabular}{c} \lstinline[language=bash]|a << b| \end{tabular}. – gerw Dec 8 '16 at 16:39
6

For the case of math type setting:

\documentclass{article}
\begin{document}
\[ a \ll b \]
\end{document}

Result

And with amssymb:

\documentclass{article}
\usepackage{amssymb}
\begin{document}
\[ a < b \ll c \lll d \]
\end{document}

Result with amssymb

  • Mmmh, Thanks, but those are not two separate characters. – kebs Sep 16 '16 at 15:28
  • @kebs The question misses the context. In mathematics, it's one symbol, meaning "much less than". a << b looks pretty like math to me. But, I have written a comment, asking about the purpose and semantics of the symbol(s). – Heiko Oberdiek Sep 16 '16 at 19:02
  • Oh, whoops, I misread Edit 1. That's my bad. – Nic Hartley Sep 16 '16 at 21:09
  • @HeikoOberdiek Right, thats why I clarified the use case (as a comment first, then as edit2. – kebs Sep 17 '16 at 7:46

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.