3

In a previous question was answered how to escape curly braces within \texttt{}. On answer suggest using the fontenc package.

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

\begin{document}
  \(a + \underbrace{\mbox{\tt\{c\}}}_d\)
\end{document}

enter image description here

Another answer suggest using \string{. However, in this case I got an error. Sorry, I do not get why it was raising an error. Example bellow works fine.

\documentclass{article}

\begin{document}
  \(a + \underbrace{\mbox{\tt\string{c\string}}}_d\)
\end{document}

I now that in this case fontenc solves the problem. Thus, my question is how can I this without using fontenc. I do not see problems with fontenc is only curiosity.

  • What do you want to do? In a normal document, there is no error with your code and I don't need fontenc for it. Do you want to write it to some file? –  Oct 07 '14 at 14:28
  • 3
    what output do you expect from this? It is hard to guess. given \texttt\string the argument to \texttt is \string which will then generate an error. You don't need \mbox around \texttt so what do you want that is different to \underbrace{\texttt{\{c\}}}} – David Carlisle Oct 07 '14 at 14:33
  • I added the example that produces the error. I want to get the same result that I get with the code above with fontenc but without using it. – Daniel Hernández Oct 07 '14 at 14:35
  • No, your examples can not be run on their own, if you want to demonstrate an error please make a complete document that makes the error, the code I posted in the previous comment should not generate an error – David Carlisle Oct 07 '14 at 14:36
  • Thanks all. I see that my question was not clear enough. So, I will improve the question description. – Daniel Hernández Oct 07 '14 at 14:40

2 Answers2

4

The problem with \{ and \} is that, if the current font encoding is OT1, the braces will be taken from the symbol font.

You have two strategies:

\documentclass{article}

\begin{document}

$\underbrace{\texttt{\string{c\string}}}$

\end{document}

or the simpler

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

\begin{document}

$\underbrace{\texttt{\{c\}}}$

\end{document}

The output is the same (well mostly indistinguishable).

enter image description here

egreg
  • 1,121,712
3

Please always post complete documents not fragments. \{ produces a { It is hard to guess from your code fragments what output you want but if it is

enter image description here

Then you just need

\documentclass{article}

\usepackage[T1]{fontenc}

\begin{document}

$\underbrace{\texttt{\{c\}}}$

\end{document}
David Carlisle
  • 757,742