rad!ance

Homepage and Weblog of Fleur Jeanquartier

LaTeX indead can be funny

LaTeX logo hosted by Wikipedia Recently I stumbled upon some questions about how to write something in Latex and also encountered some frustration with LateX stylings. Though its usability is a matter of disccusion, you can achieve really much with the help of this document preparation system called “Latex“.

Assuming you still have the nerves to try out some article-writing in LaTeX I would like to suggest reading further and see some examples of some quite nice styling issues with LaTeX:

To begin with, an easy one:

namely how to generate PDF-output correctly:

1.) include the PdfTex package:

% for including and scaling PostScript graphic files;
usepackage[pdftex]{graphicx}

% for including hyperrefs within pdf
usepackage[pdftex]{hyperref}

2.) To include the TOC as a Link into your TOC

set a pdfbookmark right before defining the tableofcontents:

% Tableofcontents
pdfbookmark[1]{Table Of Contents}{toc} tableofcontents

A list of most possible primitives provided by pdftex can be found on the Tex User Group Homepage.

How to use Sourcecode in a represantative way:

1.) Include the listings package*:

% to use sourcecode listings
usepackage{listings}

* Remind, that you include packages in the code before the begin{document}. Therefore you use the usepackage [hoption-listi] {hpackage-namei} [hrelease-datei] command.

1.) Now include the listing:

par{
small{begin{lstlisting}[frame=tb]
Selektor { Eigenschaft: Wert; }
end{lstlisting}}
}

This listing will look quite similar to that one:

Screenshot of a Listing in Latex

If the listing has more than one row use linenumbering:

par{
% lstset{language=HTML} (no lstset because HTML does not display Inline-CSS very good)
small{begin{lstlisting}[frame=tb,numbers=left,numberstyle=tiny,stepnumber=1]
#some code lines more
#such as some css code in here

body {
border: none;
color: #000;
font-family: Verdana, sans-serif;
margin: 50px;
padding: 0;
}
div {
text-align: center;
align: middle;
border: 1px solid #000;
}
#boxtest {
padding: 20px;
margin: 15px;
border-width: 5px;
width: 100px;
}
–>

end{lstlisting}}
}
This listing will look quite similar to that one:

Screenshot of a Listing in Latex

lstset{language=HTML}
With lstset{…} you can specify the listing’s language. The listing package offers many predefined languages, such as: Ada, Algol, C, C++, Caml, Clean, Cobol, Delphi, Eiffel, Fortran, HTML, Java, Lisp, Logo, make, Mathematica, Matlab, Mercury, Miranda, Pascal, Perl, Prolog, Python, SHELXL, SQL, TeX and some others.

You can also use other languages in the lstset command to display the listings differently, such as:

par{
lstset{language=Php}
small{begin{lstlisting}[frame=tb,numbers=left,numberstyle=tiny,stepnumber=1]
< ?php //validate date $Month = & new $Month(2006, 4, 1); // 1st April 2006 (?!?) if (!$Month->isValid()) {
$Validator = & $Month->getValidator();
while ($Error = $Validator->fetch()) {
echo $Error->toString();
}
}
?>
end{lstlisting}}
}

This listing will look quite similar to that one:

Latex Listing Screenshot 3

A picture says more than a thousand words:

1.) Look at the whole LaTeX listing how to include a graphic:

begin{figure}[h]
begin{center}
includegraphics[scale=0.6]{images/myPicture.png}
caption{A picture of me}
label{fig:pic1}
end{center}
end{figure}

Remind that you have to tell latex to use the GraphicX package with usepackage[pdftex]{graphicx} before.

2.) The explanation of the before used commands:

begin{figure}[h]
The [h] stands for “here”. The figure can also be placed as [t], which stands for top of the page, b for bottom, or [p] to let the graphic float on the page.
begin{center}
Use the command begin{center} to position the image in the middle of the page.
includegraphics[scale=0.6]{images/myPicture.png}
With [scale=…] you specify whether you use the original size of the graphic, or a smaller or bigger one.
caption{A picture of me}
The command caption{…} describes the graphic’s title.
label{fig:pic1}
And the command label{…} describes, as you may already guessed, the graphic’s label.