8
\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{frame}[fragile]{Angle Brackets}
\newcommand{\bbb}{\protect\textless\protect\textless\protect\textless}
\begin{semiverbatim}
Wrong:
a <<< b

Right:
a \bbb b
\end{semiverbatim}

\end{frame}
\end{document}

angle brackets

Why is this happening at all? In the beamer documentation it only says that \, {, and } are handled specially.

Also, I can't say that I like my solution very much. I'd rather be able to use <<< as is. Is my solution the only way to go here?

letmaik
  • 1,947
  • Why is it happening? This is the work of \usepackage[T1]{fontenc} - remove it. – Werner Jun 15 '13 at 16:23
  • Hm, you're right, but isn't it good practice to use T1 so that people can copy-paste properly? – letmaik Jun 15 '13 at 16:26
  • If good practice leads to this or other problems, then it might not be good practice. It may be your use-case which is problematic. If you wish to keep that functionality, then some intervention is required... – Werner Jun 15 '13 at 16:38
  • In my case I actually need fontenc because I use the luximono font which requires it. – letmaik Jun 15 '13 at 18:18

2 Answers2

5

If the question is "how to prevent", an additional grouping will be enough:

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\begin{document}
\begin{frame}[fragile]{Angle Brackets}
\newcommand{\bbb}{\protect\textless\protect\textless\protect\textless}%} % corrected
\begin{semiverbatim}
Wrong:
a <{<}< b % here - PS

Right:
a \bbb b
\end{semiverbatim}

\end{frame}
\end{document}

enter image description here

4

You can modify the definition of semiverbatim.

\documentclass{beamer}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}

\makeatletter
\def\semiverbatim{%
  \trivlist\item\relax
  \if@minipage\else
    \vskip\parskip
  \fi
  \leftskip\@totalleftmargin
  \rightskip\z@skip
  \parindent\z@
  \parfillskip\@flushglue
  \parskip\z@skip
  \@@par
  \@tempswafalse
  \def\par{%
    \if@tempswa
      \leavevmode\null\@@par\penalty\interlinepenalty
    \else
      \@tempswatrue
      \ifhmode
        \@@par\penalty\interlinepenalty
      \fi
    \fi}%
   \obeylines
   \def\verbatim@nolig@list{\do\<\do\>}%
   \verbatim@font\@noligs\catcode`\<=\active \catcode`\>=\active
   \let\org@prime'%
   \everymath\expandafter{\the\everymath\catcode`\'=12 \let'\org@prime}%
   \everydisplay\expandafter{\the\everydisplay\catcode`\'=12 \let'\org@prime}%
   \def\dospecials{\do\ \do\$\do\&\do\#\do\^\do\_\do\%\do\~\do\`\do\,\do\'\do\-}%
   \let\do\@makeother\dospecials
   \def\\{\char`\\}%
   \def\{{\char`\{}%
   \def\}{\char`\}}%
   \frenchspacing\@vobeyspaces
   \everypar\expandafter{\the\everypar\unpenalty}%
}
\makeatother

\begin{document}
\begin{frame}[fragile]{Angle Brackets}
\newcommand{\bbb}{\protect\textless\protect\textless\protect\textless}
\begin{semiverbatim}
Wrong:
a <<< b

Right:
a \bbb b
\end{semiverbatim}

\end{frame}
\end{document}

Maybe other characters need to be activated. I only disabled the << and >> ligatures.

Unfortunately a simpler patch is not possible, but this redefinition of semiverbatim is very faithful to the original one.

egreg
  • 1,121,712