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}
\renewcommand{\rmdefault}{cmtt}
\renewcommand{\sfdefault}{cmtt}
\renewcommand{\bfdefault}{m}
\renewcommand{\itdefault}{n}
\renewcommand{\sldefault}{n}
\renewcommand{\scdefault}{n}
Changing to scaled luximono
:
\usepackage[scaled=0.85]{luximono}
\input{glyphtounicode}
\pdfgentounicode=1
\renewcommand{\familydefault}{ul9}
\renewcommand{\rmdefault}{ul9}
\renewcommand{\sfdefault}{ul9}
\renewcommand{\bfdefault}{m}
\renewcommand{\itdefault}{n}
\renewcommand{\sldefault}{n}
\renewcommand{\scdefault}{n}
I also recommend the package csquotes to ensure correct quoting marks.
EDIT: I forgot that you preferred XeLaTeX
and it sems that memoir
and the ms
-option does not work with XeLaTeX
.
Here is a new (near) MWE:
\documentclass[english,ms,11pt]{memoir}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenx}
\usepackage{lmodern}
% Comment the line above and uncomment the following
% ten line to change monotype font.
%\usepackage[scaled=0.85]{luximono}
%\input{glyphtounicode}
%\pdfgentounicode=1
%\renewcommand{\familydefault}{ul9}
%\renewcommand{\rmdefault}{ul9}
%\renewcommand{\sfdefault}{ul9}
%\renewcommand{\bfdefault}{m}
%\renewcommand{\itdefault}{n}
%\renewcommand{\sldefault}{n}
%\renewcommand{\scdefault}{n}
\usepackage[autostyle=true]{csquotes}
\usepackage{lipsum,kantlipsum}
\begin{document}
\lipsum[2]
\end{document}
Computer Modern

Scaled Luximono

(it seems this works everywhere apart from acrobat reader)
This is based on the example by @DavidCarlisle.
The cmtt
visible space character seems to be labelled differently in different cmtt
variants. For cm-super (which is loaded here when I use \usepackage[T1]{fontenc}
), the respective character is named uni2423
which seems to cause problems with evince
when copying that character.
So I rigorously defined everything which looks like space to a non-break space.
You might want to restrict this to verbatim ;-)
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\input{glyphtounicode}
\pdfglyphtounicode{visiblespace}{A0}
\pdfglyphtounicode{blank}{A0}
\pdfglyphtounicode{visualspace}{A0}
\pdfglyphtounicode{uni2423}{A0}
\pdfgentounicode=1
\begin{document}\showoutput
\makeatletter
\def\@xobeysp{\textcolor{white}{\char32}}
\makeatother
\begin{verbatim}
def myfunction(x):
return x
\end{verbatim}
\end{document}
I am inclined to consider the fact that apparently no (consecutive or beginning-of-line) spaces can be copied from Acrobat a bug.
Or is this specified anywhere?
At least it's completely the same with official Adobe documents like the PDF Reference.
So I consider this answer valid no matter what :-)
Best Answer
amsmath
defines\colon
as\nobreak \muskip 2mu\mathpunct{}\nonscript\mkern-\thinmuskip{:}\mskip 6mu plus1mu\relax
. So how about the following?