1

How can I get LaTeX to make its output look like it was printed with the draft mode of a 9-pin dot matrix printer, such as the classic Epson FX-80? The upper part of the following illustration, taken from the book Computer Structure and Logic, gives some idea of what I am talking about:

Sample dot matrix printer output with the characteristics described below.

Basically what this means is that:

  1. Each character should be typeset as a matrix of dots.
  2. The dots should be obviously separate, but possibly somewhat overlapping due to ink bleed.
  3. The borders of the dots should be somewhat fuzzy rather than completely crisp.
  4. Even in their centres, the dots should not be completely black.
  5. There should be some slight, irregular variation in the position and darkness of the dots. (Unlike with a typewritter, this variation should not be unique to each letter type.)

I don't particularly care about graphics, math mode, or non-ASCII characters, though it would also be nice if the following text-mode styles were supported:

  • fake italics (i.e., slanted text)
  • fake super- and subscripts (i.e., squashed, vertically offset characters)
  • underline
  • fake boldface (i.e., slightly offset double-struck text)

I am aware that there exist fonts, such as FX Matrix, that simulate dot matrix output. However, these don't produce the variation in colour, dot size, dot position, etc. that you observe with authentic dot matrix printer output.

(This question was inspired by a previous one on simulating old typewritten texts.)

Psychonaut
  • 3,142
  • I would search for a true type font which emulates a 9 pin dot matrix. There is also metafont (a separate but related program to TeX). – John Kormylo Jul 05 '22 at 14:54

1 Answers1

2

Because the OP indicates the desirability of special textural features to the dot strikes, such as fading, the only option will be to build it up from scratch.

Here I show how that might be done.

First, you need to design your dot via \dmdot. I used the accepted answer at Customise fading in TikZ to design a dot strike that fades with opacity toward its outer fringe. Obviously the design can be changed to suit.

Then, once you are happy with the dot, you have to design the layout of each letter as a matrix of dots. I define two letters only as an example: "R" and "y", which are defined in \dotR and \doty. Because the space is active for these definitions, a leading space in any given dot row must be prepended with a {} to enable proper digestion of the data.

The matrix for any given letter is set with the macro \dotletter{<letter>}. However, to ease the input requirements, I have set up a token cycle environment \dotmatrix...\enddotmatrix which takes each letter of the environment and applies \dotletter to it. Thus, the user input for this example is \dotmatrix RyR\enddotmatrix.

The parameters that govern the dotsize, vertical dot gap, horizontal dot kern, the vertical subbaseline, and the letter sidebearing are defined, for example, with

\newcommand\dmdotsize{.025}
\newcommand\dmdotgap{1pt}
\newcommand\dmdotkern{.7pt}
\newcommand\dmdotbase{-2pt}
\newcommand\dmsidebearing{1.5pt}

These parameters can be tuned, as shown in the MWE for the 2nd case. The MWE shows a large version of the dot, so that one can see the fading that is applied by \dmdot.

\documentclass{article}
\usepackage{stackengine,tikz,tokcycle}
\usetikzlibrary{fadings} 
\pgfdeclareradialshading{tikzfadeSid}{\pgfpointorigin}{%
  color(0pt)=(pgftransparent!0); color(12.5bp)=(pgftransparent!0);
  color(25bp)=(pgftransparent!50); 
  color(37.5bp)=(pgftransparent!95); 
  color(50bp)=(pgftransparent!100)}%
\pgfdeclarefading{custom fade out}{\pgfuseshading{tikzfadeSid}}%
\newcommand\dmdot[1][\dmdotsize]{%
\begin{tikzpicture}
\fill[black,opacity=0.9,path fading=custom fade out, draw=none] (0,0) 
circle[radius=#1];
\end{tikzpicture}
}
\newcommand\dmdotsize{.025}
\newcommand\dmdotgap{1pt}
\newcommand\dmdotkern{.7pt}
\newcommand\dmdotbase{-2pt}
\newcommand\dmsidebearing{1.5pt}

\setstackEOL{\} \setstackgap{L}{\dmdotgap} \renewcommand\stackalignment{l}

\bgroup \catcode`.=\active \gdef.{\makebox[\dmdotkern]{\dmdot}} \catcode32=\active% \gdef {\kern\dmdotkern}% \gdef\dotR{. . .\. .\. .\. . .\. .\. .\. .\\}% \gdef\doty{. .\. .\. .\{} . . .\{} .\{} . ..}% \egroup \newcommand\dotletter[1]{\kern\dmsidebearing \raisebox{\dmdotbase}{\expandafter\Longstack\expandafter{% \csname dot#1\endcsname}}} \xtokcycleenvironment\dotmatrix {\addcytoks{\dotletter{##1}}} {\processtoks{##1}} {\addcytoks{##1}} {\addcytoks{##1}} {\kern 2\dimexpr\dmdotsize cm} {\addcytoks{\kern-\dmdotsize cm}} \begin{document} \dmdot[.5]

R\dotmatrix RyR\enddotmatrix X

\renewcommand\dmdotsize{.023} \renewcommand\dmdotgap{.9pt} \renewcommand\dmdotkern{.5pt} \renewcommand\dmdotbase{-1.8pt} \renewcommand\dmsidebearing{1.4pt}

R\dotmatrix RyR\enddotmatrix X \end{document}

enter image description here