Hello World (LaTeX)

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

Since LaTeX is a typesetting language, a hello world program does not need any specific output statement, instead the document just contains those words. The following code assumes LaTeX2e, for older LaTex, replace documentclass with documentstyle

First in any LaTeX document, the document class is set. Here the article class is used.

<<hello.tex>>=
\documentclass{article}

Here we could include some packages, set some values or make some definitions, but we don't need that here. So we directly start the document:

<<hello.tex>>=
\begin{document}
document content
\end{document}

Since this is a hello world program, the document content is quite simple:

<<document content>>=
Hello, world!

You can translate that document with

latex hello.tex

which creates the file hello.dvi which you can view with a dvi viewer, e.g. xdvi, or further process e.g. with

dvips hello.dvi -o hello.ps

to obtain a PostScript file. If you want to generate a PDF, you can instead use

pdflatex hello.tex

which translates the LaTeX source directly to PDF, which you can view e.g. with

acroread hello.pdf
Download code
Views
Personal tools