Hot answers tagged

81

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 (...


73

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} \end{document} Or probably better add \usepackage[T1]{fontenc} then all the above forms will use the character from the font.


48

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 \...


40

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

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}


35

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


30

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} \...


29

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 ...


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

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?


26

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 \...


26

Use the default basicstyle=\footnotesize\ttfamily,... or better with package microtype \usepackage[T1]{fontenc} \usepackage[scaled]{beramono} \newcommand\Small{\fontsize{9}{9.2}\selectfont} \newcommand*\LSTfont{\Small\ttfamily\SetTracking{encoding=*}{-60}\lsstyle} ... \begin{lstlisting}[basicstyle=\LSTfont,...] ... Which gives a better result.


23

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

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

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|".


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

The different is that \verb is an inline verbatim environment so that everything inside it is taken literally, even what would otherwise be considered a command. This also happens to use a monospace font because it is usually use to insert some codes (so that special characters don't pose any issue). On the other hand, \tt (and you really should be using \...


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 some ...


18

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}


17

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 ...


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} ...


17

I was looking to get the underscore character inside a word in any font, and Google brought me here, so here's the solution I found: {\_} word{\_}one{\_}two produces _ word_one_two


17

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 ...


17

Unfortunately the sig-alternate class uses a peculiar1 way to set the document fonts. In particular, the \texttt macro selects the font family aett (which belongs to a definitely obsolete package) at size 9pt, independent of context. So you have two problems. Use a boldface version of the Typewriter font. Increase the font size in section titles. ...


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

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: \...


15

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} \tikz{\node[...


15

There are the Latin Modern Fonts, from their README: The fonts are based on Donald E. Knuth's Computer Modern fonts in the PostScript Type 1 format In family lmtt, there are even three series: \documentclass{article} % \usepackage[T1]{fontenc} \usepackage{lmodern} \begin{document} \ttfamily \fontseries{l}\selectfont light \fontseries{m}\selectfont ...



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