Task

How to use pretty-printed documents in LaTeX.

Description

The back-end abox2latex produces LaTeX code according to the formatting defined in a Box term. In order to process this LaTeX code by latex, the `boxenv' style file is required.

The location of this style file depends on your GPP installation but abox2latex includes a comment section in the generated LaTeX code that tells you where to find the style file.

A generated LaTeX file can be incorporated in a larger LaTeX document as follows:

  1. Determine the location of the boxenv style file by inspecting the comments at the beginning of example.tex.

  1. Add this location to your TEXINPUTS environment variable.

  1. Add `\usepackage{boxenv}' to the preamble of main.tex.

  1. Import the generated LaTeX file using `\input'.

  1. Process the file by latex.

The paper A LaTeX Style File For Formatting BOX Expressions contains detailed information about the boxenv style file and its use.

Changing Fonts

You can change how text is displayed by LaTeX by redefining macros in a configuration file 'box-fonts.def'. The following macros can be defined:

KWf:
Defines how keywords are formatted (default '\textbf{...}')
VARf:
Defines how variables are formatted (default '\textit{...}')
NUMf:
Defines how numbers are formatted (default '\textrm{...}')
MATHf:
Defines how mathematical symbols are formatted (default '\ensuremath{...}')
COMMF:
Defines how to comments are formatted (default '\textrm{...}')

Changing Symbols

You can instruct abox2latex to map symbols in an abox term to special LaTeX symbols. To that end, you create an abbreviations table containing mappings from Box symbols to LaTeX symbols, and pass that table to abox2latex with the '-t' switch. For example, abox2latex uses the following default abbreviations table:

   [
     ["->"   , "\\ensuremath{\\rightarrow}"],
     [ "\\/" , "\\ensuremath{\\vee}"],
     [ "/\\" , "\\ensuremath{\\wedge}"],
     [ "=="  , "\\ensuremath{\\equiv}"],
     [ "++"  , "\\ensuremath{+\\kern-.4em+}"]
   ]

Examples

The location of boxenv.sty can be appended to your TEXINPUTS environment variable as follows:

For Bourne shells

 # TEXINPUTS=<boxenv.sty location>:${TEXINPUTS}; export TEXINPUTS

For C shells

 # set TEXINPUTS=<boxenv.sty location>:${TEXINPUTS}; setenv TEXINPUTS

Assuming that the generated LaTeX code is stored in the file example.tex, then a typical LaTeX document that includes the file example.tex looks like:

 \documentstyle{article}
 \usepackage{boxenv}
 
 \begin{document}
 \input{example.tex}
 \enddocument}

Layout Preserving Pretty-Printing with GPP

Abox2latex can be used for layout preserving pretty-printing. To that end, you have to produce an abox term with asfix2abox? and pass it the '-c' switch to preserve layout in the Box expression. Then you use abox2latex with the '--alltt' switch to produce a LaTeX alltt environment:

 asfix2abox -c -i <your_file>.asfix \
 abox2latex --alltt -o <your_file>.tex

Then you include the 'alltt' and 'boxenv' style files in your document, and input '<your_file>.tex:

 \documentclass{article}
 \usepackage{alltt}
 \usepackage{boxenv}

 \begin{document}
 \input{<your_file>.tex}
 \end{document}

See Also

GenericPrettyPrinter, HowToPrettyPrintAGrammar, AboxToLaTex

Revision: r1.5 - 18 May 2005 - 06:39 - MerijnDeJonge
Tools > HowToUseGPPWithLaTeX
Copyright © 1999-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback