# Tag Info

## Hot answers tagged typewriter

36

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

29

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

20

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

19


19

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

18

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

17

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

16

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}

16

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

14

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

13

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

13

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

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

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

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

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

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

11

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

11

As Will Robertson says, the rendering of the caret depends on the font. Here I give three examples: Computer Modern Typewriter in OT1 encoding Computer Modern Typewriter in T1 encoding Inconsolata In all three the first caret is obtained with \textasciicircum and the second one with \^{}. In the first row the two carets are the same, in the second row ...

11

By design, the + in Computer Modern has its horizontal bar slightly above what we would consider the visual center; this "fools" TiKZ's algorithm for centering an object on the node coordinates. \documentclass[border=1]{standalone} \newcommand{\ttplus}{% \raisebox{-.15ex}[\dimexpr\height-.15ex\relax][0pt]{\ttfamily+}} \usepackage{tikz} \begin{document} ...

11

Just to add to egreg's fine answer. Why it moves up? TikZ will center the enclosing box, as is obvious from the image below: TeX aligns the letters symbols at their baseline in text mode and at a centerline, if they are in maths mode. Kerning is a partial solution as egreg, showed. Having the + in math is a better solution. It is not just a font issue, ...

11

You could redefine \texttt to take an optional argument that allows you to switch colour if necessary, and if not, stick to some default colour. In the minimal example below, \texttt[<color>]{<stuff>} has been redefined to take an optional <color> (default is black). \documentclass{article} \usepackage{xcolor}% ...

11

It seems that the "Lithuanian package" invoked by the L7x option doesn't set correctly the default typewriter type family: the following way to set up the document should work. \usepackage[L7x]{fontenc} \usepackage[utf8]{inputenc} \usepackage[lithuanian]{babel} \renewcommand{\ttdefault}{lmtt}

11

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

11

You can use \verb|operator^=| to print text verbatim. Or with the listings package you can use \lstinline|^=| to set verbatim text. If you do this a lot, you can use the command \lstMakeShortInline| to allow you to just type |^=| to set these things. You need to pick a character that won't appear inside your verbatim text. That is, you couldn't do ...

11

Monospaced fonts in the "old TeX world" usually don't allow for stretching and shrinking spaces. Here's the beginning of cmtt10.pl, which is the human readable version of the metric file cmtt10.tfm: (FAMILY CMTT) (FACE O 352) (CODINGSCHEME TEX TYPEWRITER TEXT) (DESIGNSIZE R 10.0) (COMMENT DESIGNSIZE IS IN POINTS) (COMMENT OTHER SIZES ARE MULTIPLES OF ...

11

Inconsolata fits well with Linux Libertine, and has a bold face: \documentclass{scrartcl} \usepackage{fontspec} \usepackage{xunicode} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Linux Libertine O} \setmonofont{Inconsolata} \begin{document} This is a test with \texttt{some \textbf{bold} typewriter text}. \end{document}

10

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

10

If it doesn't occur very often or you can use search and replace you can add a negative space by yourself to compensate for it: \documentclass{article} \begin{document} Normal margin here. Normal margin here. Normal margin here. Normal margin here. Normal margin here. Normal margin here. Normal margin here. Abcdefgh abcdefgh abcdefgh abcdefgh abcdefgh ...

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