Tag Info

Hot answers tagged

54

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


37

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}


34

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


32

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


26

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}


23

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

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


21

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


20

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


19

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


19

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


18

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


18

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


17

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


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

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.


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


14

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


14

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


14

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


14

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


14

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


13

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?


13

use \usepackage[T1]{fontenc} and it will be the same. Without the T1 fontencoding the \{ is taken from the OMS symbol font.


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


13

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}


12

The easiest (but not the most flexible) way is to use memoir with the ms option. Then you get something that look like a good, old typewriter manuscript. memoir also hard code the monospace font to be cmtt, se line 12643 in the memoir.cls. If you want another monospaced font, you need to change at least the lines: \renewcommand{\familydefault}{cmtt} ...


12

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


12

Bold-extra is not a package you load, it is a collection of fonts. But as this are metafont (bitmap) fonts I wouldn't recommend using them. Better switch either to the lmodern fonts, or use the luximono or the beramono-typewriter font: \documentclass[11pt]{article} \usepackage[T1]{fontenc} \usepackage{lmodern} %\usepackage{luximono} ...


12

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



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