Hello World (Pic)

From LiteratePrograms

Jump to: navigation, search
Other implementations: Ada | ALGOL 68 | Alice ML | Amiga E | Applescript | AspectJ | Assembly Intel x86 Linux | Assembly Intel x86 NetBSD | AWK | bash | BASIC | Batch files | C | C, Cairo | C, Xlib | Candle | Clojure | C++ | C# | Delphi | Dylan | E | Eiffel | Erlang | Forth | FORTRAN | Fortress | Go | Groovy | Haskell | Hume | IBM PC bootstrap | Inform 7 | Java | Java, Swing | JavaScript | LaTeX | Lisp | Logo | Lua | Maple | MATLAB | Mercury | OCaml/F Sharp | occam | Oz | Pascal | Perl | PHP | Pic | PIR | PLI | PostScript | Prolog | Python | Rexx | Ruby | Scala | Scheme | Seed7 | sh | Smalltalk | SQL | Standard ML | SVG | Tcl | Tcl Tk | Visual Basic | Visual Basic .NET | XSL

This is a simple pic script that prints a string to the document.



  • pic interpreter: We recommend Dwight Aplevich's dpic.
  • LaTeX
  • eps2png: We need it only if we want to convert an EPS document to a png file.

Drawing "Hello, world!" in a monochrome document

Simple example of PIC output

Every pic document begins with .PS and ends with .PE.

pic codes...

For the first example, we draw an invisible box and centers the text "Hello, world!" in it.

box invis "Hello, world!"

We should convert basic.pic to the LaTeX picture command.

[crypto@crypto ~/Draw/]$ dpic -p basic.pic > basic.tex
[crypto@crypto ~/Draw/]$ cat basic.tex
% dpic version 03.Jan.06 for PSTricks 0.93a
\rput(0.375,0){Hello, world!}

Now we have to embed basic.tex in a normal LaTeX document. head.tex comes before basic.tex and tail.tex follows basic.tex.

\usepackage{pst-eps, boxdims, graphicx, pst-grad}

All these three files must be concatenated to one LaTeX source file.

[crypto@crypto ~/Draw/]$ cat head.tex basic.tex tail.tex > doc.tex

We compile doc.tex to obtain a dvi document, which is converted to EPS document.

[crypto@crypto ~/Draw/]$ latex doc.tex
[crypto@crypto ~/Draw/]$ dvips -X 1440 -Ppdf -G0 -E doc.dvi -o doc.eps

Now this EPS document can be further converted to any graphic file. For example, we can convert EPS into PNG using eps2png.

[crypto@crypto ~/Draw/]$ eps2png doc.eps


We use boxdims.sty in head.tex in order to control tricky box settings. boxdims.sty is originally written by Dwight Aplevich. The original style file is available at http://www.tug.org/tex-archive/graphics/circuit_macros/boxdims.sty in Circuit macro package.

%* Circuit_macros Version 5.9, copyright (c) 2006 J. D. Aplevich, under    *
%* the LaTeX Project Public License. The files of this distribution may    *
%* be redistributed or modified, provided that this copyright notice is    *
%* included and provided that modifications are clearly marked to          *
%* distinguish them from this distribution.  There is no warranty          *
%* whatsoever for these files.                                             *
% boxdims.sty, for use with m4 preprocessors.  Last modified 30 Apr 2004.
% \boxdims{arg1}{arg2} expands to arg2, but writes into file \jobname.dim
% the m4 definitions for macros arg1_h, arg1_w, arg1_d, the height, width
% and depth of \hbox{arg2}.
% \defboxdim{arg1}{arg2} writes the definitions but expands to nothing.
% \boxdimfile{filename} sets the output file to filename, default \jobname.dim
         [2004/04/30 v2.0 Macros: boxdimfile, boxdims, defboxdim (DA)]
  \typeout{ boxdims.sty v2.0: Writing dimension file #1 }}%
    \typeout{ boxdims.sty v2.0: Writing dimension file \jobname.dim }\fi%


All these tricky process can be automated by Makeile. Typing make would open an EPS document. Typing make png would convert the EPS document into a PNG file.

# The name of a drawing file
# Target document
# PIC command
PIC=dpic -p
# dvips options
DVIPSOPT=-X 1440 -Ppdf -G0 -E

	gsview32 $(FIG).eps &

	eps2png $(FIG).eps

	dvips $(DVIPSOPT) $(DOC).dvi -o $(FIG).eps

$(DOC).dvi:$(DOC).tex $(FIG).tex
	latex $(DOC)

	cat $(HEAD) $(FIG).tex $(TAIL) > $(DOC).tex

	$(PIC) $(FIG).pic > $(FIG).tex

	rm -f *~
	find . -maxdepth 1 -type f -name "$(DOC).*" ! -name "$(DOC).png" -exec rm -f {} \;

Colorful example

Colorful example of PIC output

Since pic compiles descriptions of picture into commands that are interpreted by (La)TeX, we can use virtually every trick in (La)TeX. For example, we can generate colorful output using LaTeX color package.

box invis "\color{red}H\color{blue}e\color{green}l\color{yellow}l\color{cyan}o\color{black},\

Typing make png FIG=colorful would produce the colorful "Hello, world!" PNG file.

External links

Download code
Personal tools