# Tag Info

71

The short answer is you use \verb where you need to write a small piece of inline verbatim material that contains characters TeX treats (or rather, is currently treating) as special. \texttt is for when you just want typewriter font. \verb has some downsides, such as not working in moving arguments. In those cases, you're probably better off using \texttt ...

57

You may prefer the character from the tt font: \documentclass{article} \begin{document} \texttt{Samp\_Dist\_Corr} \verb|Samp_Dist_Corr| \texttt{Samp\char_Dist\char_Corr} Or probably better add \usepackage[T1]{fontenc} then all the above forms will use the character from the font. \end{document}

44

In LaTeX it is standard behavior that typewriter fonts do not do any hyphenation because it is typically used for code. Thus, the fonts used normally for \texttt all suppress hyphenation automatically. To change this, there are essentially three options: enable hyphenation for the fonts used by \texttt throughout the document define your own variant of ...

36

You can use \textunderscore also. \documentclass{article} % \begin{document} Samp\textunderscore Distt\textunderscore Corr \texttt{Samp\textunderscore Distt\textunderscore Corr} \end{document} Underscore is not merging at the bottom of D actually. It is very close to it.

35

Best package for the job is manuscript \documentclass{article} \usepackage{manuscript,lipsum} \begin{document} \lipsum[1-3] \end{document}

32

Load the url package and use its \path{...} command: \documentclass[twocolumn]{article} \usepackage{url} \begin{document} Here is a long path: \path{/usr/local/texlive/2010/texmf-dist/tex/latex/biblatex/biblatex.sty} \end{document}

29

The default was chosen by the package author, according to the common way of setting URLs. Using a monospaced font helps distinguishing them, and this is the main reason. However the font can be changed with \urlstyle that accepts one argument among tt rm sf same The default is equivalent to \urlstyle{tt}; with \urlstyle{rm} and \urlstyle{sf} the font ...

28

As Martin mentioned in the comment you need a font which provides such a combination. In the following example you can see that the font courier has this combination implemented instead of Computer Modern. \documentclass{article} \usepackage{listings} \begin{document} % Default Computer Modern font (no bold implemented) \renewcommand{\ttdefault}{cmtt} ...

26


25

Informally speaking, TeX break lines at spaces (and a few other positions in a word, called "discretionary break"). Discretionary break is not allowed in typewriter typesetting. If there is no space in \texttt{}, it cannot break. For your example, there is no help using \texttt instead of \verb. There are several ways to solve such kind of problem: Enable ...

24

Hyphenation and full justification is possible with typewriter text as well. Here's a command \justify for this purpose, shown with the example above: \documentclass{minimal} \usepackage{lipsum} \newcommand*\justify{% \fontdimen2\font=0.4em% interword space \fontdimen3\font=0.2em% interword stretch \fontdimen4\font=0.1em% interword shrink ...

22

Inconsolata might be a choice. There is also a package for TeX support. It is a font "designed for code listings and the like, in print," posing itself as a better alternative since many other fonts are designed for screen and not for the high resolutions in print. \documentclass{article} \usepackage{inconsolata} \begin{document} \texttt{This is ...

22

A fairly elementary way of stripping special meaning from things is to \detokenize them: \documentclass{article} \begin{document} \texttt{\detokenize{Samp_Dist_Corr}} \texttt{\detokenize{a@b\c_d&e~f g}} \end{document} Note how a space is inserted after a "control sequence". See What are the exact semantics of \detokenize?

21

Use the upquote package; even if the package documentation doesn't mention alltt, it works also with it: \documentclass{article} \usepackage{alltt} \usepackage{upquote} \usepackage{color} \usepackage{fullpage} \begin{document} \begin{center} \LARGE hello.py \end{center} \begin{alltt} {\color{red}print} 'hello world' \end{alltt} \end{document} Notice ...

21

You are missing a \ttfamily in the basicstyle. If this doesn't give you the size you want try \scriptsize or even \tiny instead of \footnotesize. You don't need to add the same size for the numberstyle again because basicstyle is used for everything by default. \documentclass{article} \usepackage{listings} \lstset{language=C, numberstyle=\footnotesize, ...

19

Sometimes using \verb|...| is better. For example if you copy paste a piece of code like __start: in a \texttt{} environment you might get an error as symbol "_" is not inside a math environment. And then you have to rewrite the code like this: "\texttt{\_\_start}". But why would you do this when you can just use:"\verb|__start|".

18

An alternative is the memoir class with the option ms. By default, the emphasis is simply ignored in this way, but adding the ulem package the text with emphasis is underlined. You can also add the xcolor package to introduce some red text. At least at the end of typerwritter era was usual the two-color ink ribbons, and therefore was usual highlight ...

17

From the Latex Font Catalogue: typewriter fonts, which are not all typewriter fonts, but I think they are all monospaced.

17

A different option is to use the Latin Modern fonts, that sport a fully featured boldface typewriter font. They have also another feature, because they can use a lighter version for the medium weight: \usepackage[lighttt]{lmodern} Let's compare a couple of examples: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{lmodern} \begin{document} ...

16

I like Inconsolata like Khaled does. It's monospaced and it supports several encodings including T1, OT1 and LY1. Just load inconsolata.sty, you could additionally specify a scaling option [scaled=factor]. Here's an example how the font looks like, taken from my blog: Links: Inconsolata Homepage Inconsolata on CTAN documentation by Karl Berry ...

16

\verb and verbatim assume the font has these characters in their ascii positions and locally makes the characters be catcode 12 (like punctuation) with no special defintion. \textbackslash (and friends) is defined to be a encoding-specific command and (to fake an air of sanity over the original TeX encodings) LaTeX assumes that OT1 encoding is the encoding ...

15

The Open Type Version of Libertine has also a typewriter version. However, for pdflatex you can use the Bera Mono: \documentclass{scrartcl} \usepackage[T1]{fontenc} \usepackage{libertine} \usepackage[scaled=0.83]{beramono} \begin{document} This is a test with \texttt{some \textbf{bold} typewriter text}. \end{document} If you want Bera Mono for LuaTeX ...

15

I suggest Latin Modern Mono Light family. In Plain TeX: \font\tt=rm-lmtl10 \font\itt=rm-lmtlo10 \font\btt=rm-lmtk10 \font\bitt=rm-lmtko10 \tt Hello\par \itt Hello\par \btt Hello\par \bitt Hello\par \bye In LaTeX, it is lmtt family in OT1 font encoding. See ot1lmtt.fd for more information. Latin Modern fonts are available in Type1 and OpenType. ...

15

The "kerned" appearance comes from the default settings of package listings. Default settings with basicstyle=\ttfamily Package listings uses columns=fixed as default. It provides the best vertical alignment, as you can see the code in a mono-spaced font in an source code editor. The settings means, the character are placed in boxes of width 0.6em: ...

14

You can add \everymath{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}} to the document preamble (or the part of the document where you need this) and \everydisplay{\mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}} if you need display math as well. In then in addition you may need to force the initialisation by putting \setbox0\hbox{\$ ...

14

It can be scaled using a package option \usepackage[ttscale=.875]{libertine} (you need to play with the value a bit, this is just an initial guess): \documentclass[border=5mm]{standalone} \usepackage[T1]{fontenc} \usepackage[ttscale=.875]{libertine} \begin{document} some text \texttt{monospaced} and normal text \end{document}

14

The TUGboat article linked by Barbara Beeton provides an in-depth study of the ambiguous-zero problem. In LaTeX's default typeface, Computer Modern, the zero in the typewriter font is narrow and round, as opposed to a squarish capital "Oh". But you may have your pick of other monospaced typefaces. The LaTeX Font Catalog provides a list of all the ...

13

This is a solution: \documentclass{article} \usepackage{letltxmacro} \LetLtxMacro{\oldtexttt}{\texttt} \def\oldapostrophe{'} \catcode`\'=\active \makeatletter \def\active@text@prime{\oldapostrophe} % this trick was done by egreg in another answer of mine \def\pr@m@s{% \ifx'\@let@token \expandafter\pr@@@s \else \ifx^\@let@token ...

13

For some reason I can't really well understand, in a \node the parameters \spaceskip and \xspaceskip are set to non zero values; when \spaceskip is non zero, TeX uses it for the interword space instead of the default stored in the current font information. Try the following example \documentclass{standalone} \usepackage{tikz} \begin{document} ...

13

My humble attempt with the xstring package: \documentclass{article} \usepackage{tikz} \usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture} \setlength\PreviewBorder{0pt} \usepackage{xstring} \def\mytext{Hello world} \StrLen{\mytext}[\mylen] \begin{document} \foreach \t in {0,...,\mylen}{% \begin{tikzpicture}[scale=1] ...

Only top voted, non community-wiki answers of a minimum length are eligible