Inserting Figures Into Tex Documents

Inserting Figures Into Tex Documents

Inserting figures into TeX documents Szab´oP´eter Budapest University of Technology and Ecomomics http://www.inf.bme.hu/\~pts/ (without the backslash) Abstract ∗ My article deals with the practical considerations of inserting sampled figures into TeX documents. Sub-topics: Choosing the appropriate compression for sampled images. Software • patents. PostScript and PDF compatibility. Conversion of PNG, JPEG, TIFF and GIF files to PDF (for pdfTeX) and • EPS (for dvips). sam2p, a conversion utility I've developed recently. Creating pixel-based figures with transparent pixels. Transparency support • in sam2p. The LATEX graphics package and epsf.tex for exist that give the user full control over the image plain TEX provide an easy and fairly standard way representation parameters. for including EPS figures into TEX documents with This article analyses the problem and possi- PostScript target, and pdfTeX together with the gra ble solutions in detail, and presents the new util- phics package supports PDF figures in LATEX docu- ity sam2p written by the author of the article, that ments with PDF targets. This works fine for vector implements these solutions. images, because serious editors have EPS export ca- Concepts Although PostScript and PDF are most pability, and one can convert an EPS file to PDF often used for faithfully representing two-dimension- with several utilities (such as epstopdf bundled with al vector graphics, they have sophisticated features teTEX, ps2pdf bundled with Ghostscript, PSTill and for displaying sampled image data as well. Unfortu- Acrobat Distiller). nately the PostScript and PDF output facilities of Inclusion of raster (bitmap) images seems to be existing image converters and editors don't make use even simpler and less troublesome at the first glance. of these advanced features: they often produce large, Under UNIX, the convert utility of ImageMagick slow and incompatible PostScript or PDF code. sam can be used to create a PBM or PGM file, which 2p is a new sampled image conversion utility that can be converted to EPS by the pnmtops utility of gives the user full control to adjust compliance, com- NetPBM. Filters mentioned in the previous para- pression and encoding of the PostScript and PDF graph can be used to create a PDF file from the output files. EPS. There are several other approaches, which will The concept of sampled images is rather sim- be described later in this article. ple: the image is a rectangular array of pixels, in But high-quality raster image files tend to be which the color of each pixel is independent of the huge, and thus documents containing raster images others. A color consists of one or more components can be only trasferred on the network only slowly, (channels, planes): for example, the colors of the and printing is even more slower. It is common RGB color space are composed of a red, a green that a PostScript version of a small article with a and a blue component. The name sampled image few dozen raster illustrations becomes larger than comes from the fact that only a finite number of 100 MB, and printing each page on a personal prin- pixel samples of the continuous picture are stored. ter takes half an hour. Software techniques such (The sampled image is also quantized, e.g. the com- as compression and colorspace transformation can ponents are integers in the range 0 ::: 255, where 0 be used to make these images much smaller, and means darkest, 255 means lightest.) Sampled im- PostScript and PDF support much of these tech- ages are also called raster images or bitmap images. niques, but unfortunately currently no free utilities Some images have an alpha channel, which describes the opacity of the pixels: a pixel having α = 0 is fully transparent, and a pixel with α = 1 is opaque. ∗ The author thanks GUST for funding his participation Non-rectangular shapes can be represented with a in EuroBachoTEX 2002, and Ferenc Wettl for testing sam2p. TUGboat, Volume 0 (2001), No. 0 | Proceedings of the 2001 Annual Meeting 1001 Szab´oP´eter rectangular image having transparent pixels outside sam2p) output sampled PostScript images as EPS. the shape, and opacity can be used this way to draw There is a thumbnail/preview feature in the EPS arbitrary shapes atop of each other. format, but sam2p doesn't emit one, because most Recent versions of the PostScript and PDF for- utilities (including the utilities related to TEX) ig- mats fully support the notions defined above. Many nore it, and they would call Ghostscript to render an features are not available in older PostScript print- independent preview anyway. ers, and there are even some features (such as opac- ity) that are documented in the file format, but not Smaller output Sampled images, especially when rendered in high resolution ( 300 DPI), tend to be implemented in any common free renderers. Thus, ≥ compatibility must be always considered when cre- large and occupy much space on disk. A PDF file ating a PostScript or PDF file containing a sam- with many high resolution figures in it gets down- pled image. These two file formats are based on loaded slowly from the web, and a PDF file with low a common graphics model, and thus they are al- resolution images looks ugly when printed. A long most equivalent. The actual image data (being ei- PostScript file containing large images prints very ther compressed or not) is stored the same way in slowly, and might even fill up the disk space of the PostScript and PDF files, only the syntax of the computer running the printer spooler. (Just imagine surrounding meta-information (such as the image multiple PostScript files of 200 MB being printed on width, height and color space specification) is dif- an old, dedicated print server with small hard disks. ferent. This situation often happened to the author.) Large The most important difference between Post- PostScript files print especially slowly, because the Script and PDF formats is that PostScript is a full- parallel-port interface on which the printer is con- featured programming language, and it gives more nected to the computer is too slow, or the processor power to the programmer to represent the image. embedded to the printer running the PostScript in- For example, one can write a PostScript program terpreter is slow. It is really annoying to wait more that would compute and draw a Mandelbrot or Julia than a minute for a single A4 page, and even more set as a sampled image, but there is no similar capa- annying to wait for someone else's job running at bility in PDF (i.e the pixels have to be pre-computed this \speed". before the generation of the PDF file). The pro- When running TEX on an old machine, the user gramming constructs of PostScript can be used to must wait several minutes for TEX finishing skip- compensate the weaknesses of the interpreter: for ping long EPS files after finding geometry (bound- example, older interpreters don't support the Flate ing box) information. The situation is even worse (ZIP) compression, but this can be overcome by today, when one expects WYSIWYG, or { at least including a pure PostScript implementation of the { instant preview. Several minutes is definitely not instant. /FlateDecode filter into the EPS file, just before the image data, and executing the supplied code Thus, the generated PostScript and PDF files when the filter is missing from the interpreter itself. should be as small as possible. This can be accom- sam2p does this and several other tricks to increase plished by: compatibility of PostScript files. Unfortunately this apply filtering to reduce noise, increase contrast • doesn't work for PDF; there is no way to extend the etc.: This should be done manually in graph- list of available filters. ical image editors. Sometimes even a size re- Raster images are most commonly used as il- duction of a factor of 4 can be achieved by re- lustrations in more complex documents, thus the moving noise and unnecessary information. As holding PostScript and PDF files should be gen- part of the filtering, the user should adjust the erated embeddable. The design of the PDF file color palette: black should be exactly black (RGB format makes embedding any PDF file (including triplet #000000), and white should be completely the most complex ones) very easy, even without the white (RGB triplet #ffffff), because otherwise special attention of the generator. PostScript fig- Ghostscript would print glaring gray regions. ures, on the other hand, share a common names- using less bits for representing a single color com- pace (and very limited memory) with the document • ponent: A black-white image needs only 1 bit per they are embedded into, and extreme caution should pixel, and it would be big waste to include it as be taken to avoid conflicts with the document it- an 8-bit RGB image with 24 bits per pixel. Even self and with other figures. Encapsulated PostScript color images can be encoded with a few bits when (EPS) is the most common file format of embed- using only a palette of very few number of dif- dable PostScript code, and most utilities (including ferent colors. PostScript and PDF support may 1002 TUGboat, Volume 0 (2001), No. 0 | Proceedings of the 2001 Annual Meeting Inserting figures into TeX documents sample formats ranging between 1 ::: 33 bits per PSL2. PostScript LanguageLevel 2 supports sev- pixel. • eral color spaces (e.g. \indexed"=paletted), and using compression adequate for the image types: all compression filters except ZIP. Ghostscript, PS • There is no universal method that finds the com- till, Acrobat Distiller, and most PostScript print- pression with best ratio, but in general, continu- ers today understand this LanguageLevel.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    7 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us