8

Am I missing something, or is it simply not possible to underline text within a verbatim environment?

\begin{verbatim}
  I want to underline the following word: word
\end{verbatim}

I guess I could ask the same question with regard to bold or italic print, but in those cases I can see that this is not what you can do with an ordinary typewriter. But any typewriter has an underscore and I can use it to underscore text. Can the verbatim environment not do that?

  • 3
    verbatim isn't designed to emulate a typewriter so much as literally show the input source. So you could of course do another line with ` ------` but if you want a typeset underline you need to escape back out of verbatim, possible with verbatim but easier to use the listings package which has a built in mechanism to allow escapes to TeX commands such as \underline or of course simply \texttt{I want to underline the following word: \underline{word}} – David Carlisle May 30 '13 at 12:09
  • Is it just text you need to typeset, or will it be special characters like \`, $, &, etc.? – Steven B. Segletes May 30 '13 at 12:22
  • This sounds like you want formatting of keywords? It could be done using the listings package – clemens May 30 '13 at 12:24
  • The aim is to typeset examples from transcripts that were transcribed according to the Jeffersson notation (liso.ucsb.edu/liso_archives/Jefferson/Transcript.pdf) or similar notations. Or rather, a simplified version, which does not include special characters but unterlining. The point is that these transcripts already exist as pdfs so that copying and pasting them into a verbatim environment seems like the easiest option. – Christoph Jun 2 '13 at 18:17
6

Apart from the suggestions made in the comments, you might also consider fancyvrb. For example, you can write something like

\documentclass{article}
\usepackage{fancyvrb}
\pagestyle{empty}
\begin{document}

\begin{Verbatim}[commandchars=+\[\]]
    The +underline[quick brown fox] jumped over the lazy dog.
\end{Verbatim}

\end{document}

enter image description here

  • 1
    This did the job, thanks. However, it's not an ideal solution since I need quite a lot of characters to underline a single word (or even letter). So if anyone has a more efficient solution (someting like: The _quick brown fox_ jumped over the lazy dog), please post it! – Christoph Jun 2 '13 at 18:39
  • @Christoph did you find any efficient solution to this problem? – Czechnology Nov 22 '14 at 23:14
  • Have a look at tex.stackexchange.com/questions/39898/… It uses the listings package, but that has functionality to enable this sort of markdown-esque formatting. – Rikki Feb 1 '17 at 22:25

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.