% \CheckSum{138}
% \iffalse
%% Copyright (C) 2002 Matej Cepl
%% $Id: manuscript.dtx,v 1.6 2005/09/02 12:08:35 matej Exp $
%% This program may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.2
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of LaTeX
%% version 1999/12/01 or later.
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%<*package>
\NeedsTeXFormat{LaTeX2e}[1996/06/01]
\ProvidesPackage{manuscript}
%</package>
%<*!package>
\ProvidesFile {manuscript.dtx}
%</!package>
   [2015/01/19 1.7 emulate typesetting of typewriter]
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\RecordChanges
\CodelineIndex
\begin{document}
   \DocInput{manuscript.dtx}
\end{document}
%</driver>
%<*!driver>
% \fi

% \DoNotIndex{\@empty,\@ifundefined,\AtBeginDocument,\def,\else}
% \DoNotIndex{\ExecuteOptions,\fi,\huge,\hyphenpenalty,\ifMS@ps}
% \DoNotIndex{\LARGE,\let,\MS@psfalse,\MS@pstrue,\MS@maketitle}
% \DoNotIndex{\newif,\ProcessOptions,\relax,\renewcommand,\RequirePackage}
% \DoNotIndex{\typearea,\usefont}
% \DoNotIndex{\MS@quote,\MS@questquote,\MS@next,\MS@dblq,\MS@sglq}
% \changes{1.0}{2002 May 20}{Initial version}
% \changes{1.2}{2002 May 22}{\cs{fileversion} and \cs{filedate}
% which does not seem to work at all being replaced by \cs{RCS}
% command from \texttt{rcs} package.}
% \changes{1.4}{2002 May 23}{With help of Stepan Kasal (stepan at
% matsrv dot mat dot cas dot cz) I have managed to get
% \cs{fileversion} working, so I have get rid off rcs.sty again.}
% \changes{1.5}{2003 June 26}{Something happened to all |fi|.}
% \changes{1.7}{2015 Januar 19}{New upload to CTAN and fix \TeX{} logo}
% \GetFileInfo{manuscript.dtx}
% \title{\bfseries \texttt{Manuscript}---A Package Emulating
% Typewriter ``Typesetting''}
% \author{Mat\v{e}j Cepl, \texttt{matej at ceplovi dot cz}}
% \date{This document describes package \texttt{manuscript}\\
%       version \fileversion, from \filedate}
% \maketitle
% \MakeShortVerb{\|}
%
% \changes{1.5}{2003 June 26}{Whole this section was
% substantially rewritten---coming from defensive to the
% offensive |:-)|.}
% \section{Purpose}
% Purpose of this package is to emulate appearance of the
% document written on classical typewriter as much as possible.
% So far, whenever backward requirement of some institutions
% (especially universities) to provide paper or thesis in the
% layout developed in times before personal computers emerges on
% any \TeX{}-related public forum, it is met with strong (and
% sometimes even angry) resistance and many advise how to
% overcome resistance of the institution. I totally agree with
% the basic premise of this attempt (of course, \TeX\ was created
% for making ``masterpieces of typography'' not to emulate
% typewriters).
%
% \changes{1.6}{2011 January 27}{Some typos corrected.}
% Having said that, this package goes exactly in the opposite
% direction than these people advise. Instead of trying to avoid
% typewriter-driven layout, it tries to emulate it as much as
% possible. Of course, the most important motivation for such
% package is challenge and curiosity how far I can get
% using just \TeX\ tools in this endeavor. However, there are
% also some real reasons why this package might be useful. First
% of all there are situations when the directives of backward
% layout are non-negotiable (e.\,g.,~in commercial setting or
% with too stiff university). Moreover, my conciliatory character
% leads me more to honor other cultures (and although very
% short-lived and feeble, there \emph{was} a typographical
% culture of typewriters) rather then rejecting them. Actually,
% during work on this package my appreciation of strict
% puritanical simplicity of typewriters just grew
% (and of course, it is obvious that in some aspects typesetting
% documents with this package would create documents of the
% quality never possible with a real typewriter---just \TeX{}'s
% optimal line breaking with few divided words makes a lot of
% difference).
%
% If you like it, enjoy!  If not, sorry, just use another
% package.
%
% Another objective was to secure compatibility both with
% classical |article|-like packages as well as with packages from
% |Koma-script| family.
%
% \StopEventually{\PrintIndex\PrintChanges}
%
% \section{The Coding}
%
% \begin{macro}{MS@ps}
% The first of all we need to create new condition |MS@ps| to
% control package options---whether font Courier should be used
% (if true) or |cmtt|. We cannot use |ifthen| package as it
% redefines catcodes and conflicts with the redefinition of
% quotes for |cmtt| font (see below).
%    \begin{macrocode}
\newif\ifMS@ps
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DeclareOption}
% \begin{macro}{\ExecuteOptions}
% \begin{macro}{\ProcessOptions}
% Declare the options by setting |MS@ps| variable. The options
% |cm| and |cr| set use of font |cmtt| or Courier, respectively.
% We want to use Courier as default option.
%    \begin{macrocode}
\DeclareOption{cm}{\MS@psfalse}
\DeclareOption{cr}{\MS@pstrue}
\ExecuteOptions{cr}
\ProcessOptions\relax
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% We need to read some additional packages which are needed for
% good working of the package: |setspace| because whole document
% should be doublespaced (except for footnotes etc.), |fontenc|
% because we should be able to print all European characters (it
% could be redefined in the document itself \emph{after} loading
% |manuscript| package, and |ragged2e| because of linebreaking
% and ragged justification.
%    \begin{macrocode}
\RequirePackage{setspace}
\RequirePackage[T1]{fontenc}
\RequirePackage[NewCommands]{ragged2e}
\RequirePackage{soul}
%    \end{macrocode}
%
% \begin{macro}{\rmdefault}
% \changes{1.5}{2003 June 26}{With CM-Super we need not \cs{ae}
% package anymore.}
% We need to set up the default font for Roman characters based
% on the boolean variable |MS@ps|.
%    \begin{macrocode}
\ifMS@ps
   \renewcommand{\rmdefault}{pcr}
\else
   \renewcommand{\rmdefault}{cmtt}
\fi
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\descfont}
% \begin{macro}{\sectfont}
% \changes{1.4}{2002 May 25}{Courier is better, so that this hack
% is better to be used only for \texttt{cmtt} font.}
%
% There is no bold in |cmtt|, so that I redefine also some
% fonts---usefull only for koma-script package, because I do not
% care too much for |article| |:-)|.
%    \begin{macrocode}
\@ifundefined{scr@parskip}{}{%
   \renewcommand*{\descfont}{\scshape}
   \renewcommand*{\sectfont}{\large\scshape} }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\MS@q*}
% \begin{macro}{``}
% \begin{macro}{'}
% This is the most obscure part of the package.\footnote{I have
% recieved substantial help with the deep \TeX\ work from
% Ond\v{r}ej ``Koala'' V\'acha. Thank you.} There are no problems
% with |Courier| font, but |cmtt| does not have some characters
% needed for normal writing---especially quotes. We have to
% change catcode of , and ` characters and redefine couples of
% these characters to be printed in |cmss| font in the Old
% Knuth's coding OT1.
%
% Moreover, and it was the bug in the previous version, we have
% to distinguish between single quote and double quote, where
% each of them should be printed as different character. Now, it
% is getting to be really messy |:-)|.
%
% \changes{1.5}{2003 June 26}{CM-Super fonts work even without
% this kludge.}
% \changes{1.4}{2002 May 22}{There is really no need to use
% \cs{gdef}, when \cs{def} is sufficient.}
% \changes{1.2}{2002 May 22}{Macro \cs{`} is protected.
% Unbelieavable construction in the \cs{change} changed to use
% \cs{cs} macro.}
% \changes{1.1}{2002/05/21}{Whole group of
% \cs{MS@*} macros in this section was added. The previous
% version did not allow use of single apostrophe.}
%    \begin{macrocode}
\iffalse
   \catcode96=13
   \def``{{\usefont{OT1}{cmss}{m}{n}\symbol{92}}}
   \catcode39=13
   \def'{\protect\MS@quote}
   \def\MS@quote{\futurelet \nextchar \MS@questquote}
   \def\MS@questquote{\ifx `\nextchar \let\MS@next=\MS@dblq
      \else \let\MS@next=\MS@sglq
      \fi \MS@next}
   \def\MS@dblq{{\usefont{OT1}{cmss}{m}{n}\symbol{125}}}
   \def\MS@sglq{{\usefont{OT1}{cmss}{m}{n}\symbol{39}}}
\fi
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\sfdefault}
% \begin{macro}{\ttdefault}
% Of course, in typewritter there are no different fonts for
% sans-serif characters and there is no distinction between
% normal and |tt| characters, thus both of these are set to be
% same as roman characters.
%    \begin{macrocode}
\renewcommand{\sfdefault}{\rmdefault}
\renewcommand{\ttdefault}{\rmdefault}
%    \end{macrocode}
% \end{macro}
% \end{macro}

% \begin{macro}{typearea}
% Of course, typewritter should follow classical ``one inch on
% all sides'' margins (later, variant supporting European
% equivalent on A4 paper may be added). The best is to use
% special package |fullpage|. However, that does not work well
% with |koma-script| family of packages, there we have to
% distinguish between the two and use macro |\typearea| native of
% |koma-script|.
%    \begin{macrocode}
\@ifundefined{typearea}
   {\RequirePackage{fullpage}}
   {\typearea[0pt]{13}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\textbf}
% \begin{macro}{\bfseries}
% \begin{macro}{\emph}
% \begin{macro}{\em}
% Italic characters are not enough distinctive in |cmtt| font, so
% we shall redefine macro |\emph| to be same as in the
% typewritter age---underlining characters.
% \changes{1.5}{2003 June 26}{It is handy redefine |em| as
% well---thanks to Petr Ol\v{s}\'ak for this. Also redefine
% bold to small caps.}
%    \begin{macrocode}
\renewcommand{\textbf}[1]{\textsc{#1}}
\def\bfseries{\scshape}

\AtBeginDocument{%
   \setul{0.3ex}{0.15ex}
   \renewcommand{\emph}[1]{\ul{#1}}
   \def\em{\egroup \expandafter \ul \expandafter{\iffalse}\fi}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}

% \begin{macro}{\spaceskip}
% There are some additional characteristics which should be
% set-up emulating behavior of typewritter: footnotes should be
% set in the normal-size font, document should be double-spaced,
% ragged right. Space between characters have to be set via
% |\spaceskip|---it is zero on default for |tt| fonts.
%    \begin{macrocode}
\let\footnotesize\@empty
\doublespacing
\AtBeginDocument{%
   \raggedright
   \parindent 1em
   \spaceskip .333333 em plus .333333 em minus .111111 em }
%    \end{macrocode}
% \end{macro}
%

% \begin{macro}{\thefootnote}
% \begin{macro}{\@makefnmark}
% \begin{macro}{\@makefntext}
% If the idea of the whole package is to emulate typewriter
% style, then we have to do something about footnotes. There is
% obviously nothing like superscripted footnote mark on
% typewriters. Moreover, I have also changed indentation of the
% body of footnote.
%
% \changes{1.5}{2003 June 26}{Whole redefinition of footnotes
% added.}
%    \begin{macrocode}
\def\thefootnote{\@arabic\c@footnote/}
\def\@makefnmark%
   {\hbox{\normalfont\@thefnmark}}
\renewcommand\@makefntext[1]{%
    \leftskip 1.8em \noindent
    \llap{\normalfont\@thefnmark\ }#1}%
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\@maketitle}
% \changes{1.5}{2003 June 26}{When \cs{titlepage} option is on,
% we need not singlespacing.}
% The standard titlehead of the document is really ugly when
% doublespaced. Therefore we should redefine |\@maketitle| macro.
% However, the trick below (creation of new macro which envelopes
% the original macro) is better, because it is compatible both
% with standard |article|-like classes and |koma-script| family.
% Redefinition of |\huge| is a kind of ugly hack, but it should
% be enough robust and simple to be OK.
%    \begin{macrocode}
\let\MS@maketitle=\@maketitle
  \if@titlepage
      \def\@maketitle{%
         \hyphenpenalty=5000
         \let\huge\LARGE
         \MS@maketitle }
  \else
      \def\@maketitle{%
         \singlespacing
         \hyphenpenalty=5000
         \let\huge\LARGE
         \MS@maketitle }
   \fi
%    \end{macrocode}
% \end{macro}
%
% That's all folks! |:-)|
% \Finale
%\iffalse
%</!driver>
%\fi