Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
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
add comment

2 Answers

up vote 9 down vote accepted

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".

\usepackage{beramono} % or whatever monospaced font you wish to employ
\pagestyle{empty} % don't need to display page numbers, right?
share|improve this answer
add comment

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

enter image description here

\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{filecontents}% http://ctan.org/pkg/filecontent
\usepackage{varwidth}% http://ctan.org/pkg/varwidth
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.
\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)
\ttfamily% Mono-spaced/typewriter font
\obeyspaces% Keep all spaces
\let =\ % Fix spaces
\obeylines% Obey line breaks
\end{varwidth}\end{lrbox}% Read ascii art
\resizebox{\textwidth}{!}{\usebox{\asciiart}}% Rescale and print ascii art.

Packages used:

  • graphicx for scaling content (in our case the box \asciiart);
  • filecontents for writing content to files without the regular filecontents restrictions. Probably not needed in your case since you already have asciiart.txt.
  • varwidth for variable width boxing.

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

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.