I want to put an entire document into monospace font for various reasons. This is nominally fairly easy; you can say \renewcommand{\familydefault}{\ttdefault}. However, there at least two problems with this approach (and possibly more). Thus, my question is really three separate ones:

So far, I'm having a problem with the spaces not working as they should; this seems to be fixed by \obeyspaces, but I am unsure of how well this really works. The only references to it I could find were on this site, and they didn't really explain that command well. Could you please provide a reference for this or at least explain what the command does and what its limitations are?

My other problem is that sometimes LaTeX generates symbols (such as smart quotes), and these do not obey the monotype spacing. LaTeX even seems to generate these when the symbols are in the font used. Is there any way of finding out when this happens, and preferrably of telling LaTeX to use existing characters when possible? Update: This is not a problem at all; see below.

I have found these by myself, but it seems quite likely that there are other problems as well. Are there other things I should look out for, like accented characters? Bold seems to work correctly (at least in the Courier font), but will all such formatting?

Update: In case it is relevant (which, now that I think of it, it almost certainly is), I am using XeTeX and fontspec. I would prefer to keep this setup, but would be open to not using fontspec or to using pdflatex instead.

Update 2: The "smart quotes" problem was actually a problem with spaces after punctuation. I turned on French spacing, but this just emphasizes the need for part three of my question.

If you want the whole document set in monospace with spaces and newlines preserved, LaTeX seems the wrong tool for the job.
–
rdhsSep 9 '12 at 6:40

I never said I want newlines preserved, as I do not in fact want that. If it seems like my question implies that, then please tell me where and I'll revise the question. The thing is, I do want other features of LaTeX, like various kinds of lists, smart quotes, references, links, index, glossary, text formatting, larger sections, etc. Most of these I could get in a traditional word processor, but given my expected usage, LaTeX seems like a better tool. Additionally, although I am not currently planning to use it, the document will be updated regularly and may require math mode in the future.
–
Daniel HSep 9 '12 at 6:51

2

May I ask why you want everything monospaced? Monospace is fine for source code, but IMHO makes your eyes bleed if you have to read several pages. If you really like it I think it's fine, but most likely not if others are to read it.
–
Tom BombadilSep 9 '12 at 8:36

I don't use French; I just mentioned the \frenchspacingcommand because it removes excess space after punctuation. That excess space wasn't an exact multiple of the character width.
–
Daniel HSep 9 '12 at 18:01

I will look into the Memoir package, though (I meant to put this in the first comment, but by the time I realized I hadn't, five minutes had passed.)
–
Daniel HSep 9 '12 at 18:11

Memoir doesn't seem to be playing nicely with xelatex or fontspec; I keep getting errors mentioning "cmtt" insteald of "lmtt", and the document is in a proportional font. I'm going to investigate further.
–
Daniel HSep 10 '12 at 23:54

The problem appears to be with fontspec;it works fine when that package is not included (but only in Computer Modern, of course); as CM is not an option due to lack of bold support in CMTT, I'll try it with PDFLaTeX
–
Daniel HSep 11 '12 at 0:01

In both PDFLaTeX and XeLaTeX, memoir seems to resist all attempts to change the font. I'll see if it provides its own functionality for doing so, but I doubt I'll have much success. If I need some sort of magic configuration options to make memoir allow me to change the font, could you please put them in your answer?
–
Daniel HSep 11 '12 at 0:10

(which is a miniature example of how TeX does justification stretching or shrinking interword spaces) results in the message

Underfull \hbox (badness 10000)

because there's no stretching in the spaces when \ttfamily is in force.

The situation is completely different in XeTeX, since the monospaced fonts I checked do allow for interword space stretching and shrinking: Latin Modern Mono, TeX Gyre Cursor, Courier. Let's make a comparison at the standard 10pt size

TeX Gyre Cursor: 6pt plus 3pt minus 2pt

Latin Modern Mono: 5.25pt plus 2.625pt minus 1.75pt

Courier: 6.00096pt plus 3.00047pt minus 2.00032pt

CMU Typewriter Text: 5.25pt plus 2.625pt minus 1.75pt

The data tell the normal width of the interword space and the amount of stretching and shrinking available.

Let's do a comparison, compiling the following document first with pdflatex and then with xelatex

(The different size is due to how the images have been produced, they are just the same size in print.)

We can notice a big difference. In the first case the engine isn't able to do proper justification, in the second image the text appears justified and hyphenated.

Conclusion

If you need to reproduce a document prepared with a typewriter, the setup

\documentclass{article}
\usepackage{fontspec}
\usepackage{ragged2e}
\setmainfont[Ligatures=TeX]{Latin Modern Mono}% choose another one if you prefer
\begin{document}
% Uncomment the following line for standard spaces after periods
%\frenchspacing
% Uncomment the following line for ragged right setup
%\setlength{\RaggedRightRightskip}{0pt plus 4em}\RaggedRight

Wouldn't it be more authentic to a typewriter not to use Ligatures=TeX? Or are there reasons to use them anyway?
–
clemensSep 9 '12 at 13:39

@cgnieder Possibly. That's only in order to make input of dashes easier, but in a fixed width font one should use only a hyphen. Maybe for ¡ and ¿, depending on the keyboard facilities.
–
egregSep 9 '12 at 13:41

This has at least the problem of the extra spaces after the period (see especially the alignment of the is pretium on the third line and aliquet on the fourth.
–
Daniel HSep 9 '12 at 18:07

@DanielH It depends on the typewriting school; I'll add the result from applying \RaggedRight and \frenchspacing
–
egregSep 9 '12 at 19:32