# How do I typeset a file containing ASCII art using a fixed-width character font?

I have a string with the text precisely spaced the way I want it displayed. It's sort of an ASCII art project. I want to convert this text to a PDF so I can print a poster with the text at my local printshop.

The font needs to be fixed width and there are no tabs or anything like that. The lines end in the \n character. There are several space characters.

The image is several hundred characters wide and several hundred high. So, it doesn't fit in the space of a typical page.

Is there an easy way to do this in LaTeX?

-
Check out the aafigure python utility. It may even be included in your distro if you are using Linux. – user1189687 Aug 14 '12 at 0:40

Assuming your ascii art project is contained in a separate file called, say, artproject.asc, you could use the fancyvrb package and its command \VerbatimInput to display the contents of the file using a "typewriter" (aka monospaced) font. Obviously, there are lots and lots of different monospaced fonts, so you'll probably want to play around a bit and determine which font works best for your project.

The following MWE shows how this might be done; it assumes that the paper size is A0, that you want a margin of 1in on all four sides of the page, and that you will use the font "beramono".

\documentclass{article}
\usepackage[a0paper,margin=1in]{geometry}
\usepackage{fancyvrb}
\usepackage{beramono} % or whatever monospaced font you wish to employ
\begin{document}
\pagestyle{empty} % don't need to display page numbers, right?
\VerbatimInput{artproject.asc}
\end{document}

-

You can import the text file with some parameters preset (partly taken from Hard whitespace):

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{filecontents}% http://ctan.org/pkg/filecontent
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
\begin{filecontents*}{asciiart.txt}
Lorem  ipsum  dolor sit  amet, consectetur  adipiscing elit. Donec sed magna risus, id  iaculis  nisi. \n
Phasellus fermentum lorem ut velit ultrices at tincidunt lacus suscipit. Maecenas sed convallis dolor. \n
Etiam  at diam velit,  quis condimentum massa.  Aenean  vel  massa mi. In id  placerat dui.  Curabitur \n
ligula  justo,  pellentesque   sed   interdum  ut,   vulputate  et  sapien.  Donec   semper,  nisi  et \n
tincidunt  vulputate,   lorem  tortor  rhoncus  dui,  sed  posuere  tellus  nisi   nec   magna.   Cras \n
sodales,  quam  at  tristique  pellentesque,   massa  orci  hendrerit  ipsum,  nec  congue  diam  elit \n
sed  urna.  Curabitur   consequat,  metus  in   accumsan  aliquam,  ligula  felis  laoreet  elit,  non \n
dapibus sapien libero eu dolor.
\end{filecontents*}
\def\n{}% Remove the functionality typically used for \n in a different language
\setlength{\parindent}{0pt}% Remove paragraph indent
\newsavebox{\asciiart}% Box storing ASCII art content
\pagestyle{empty}% Remove page header/footer (including page numbers)
\begin{document}
\begingroup
\ttfamily% Mono-spaced/typewriter font
\obeyspaces% Keep all spaces
\let =\ % Fix spaces
\obeylines% Obey line breaks
\begin{lrbox}{\asciiart}\begin{varwidth}{10\textwidth}
\input{asciiart.txt}

geometry can also be used to scale the paper size to your liking.