Gabriel Scalosub

Department of Communication Systems Engineering
Ben-Gurion University of the Negev
Alon Building for High-Tech (Building 37), Room 414
P.O.B. 653 Beer-Sheva 84105 Israel
Phone: +972-8-6477230
Fax: +972-8-6472883
Email: press here

"I hear and I forget. I see and I remember. I do and I understand."
Confucius (551 BC - 479 BC)

LaTeX Tips

The TeX Catalogue: a catalogue of useful LaTeX packages Contents:


Compound math symbols

To produce a compound math symbold, e.g., a right arrow with, e.g., the text 'Lemma 1.2' on top, use:
$\stackrel{\mbox{\tiny Lemma 1.2}}{\Rightarrow}$
Another example:


To have math with overbrace or underbrace, use:
$\overbrace{x+y}^{sum}=\underbrace{x \cdot y}_{\mbox{product}}$

Multi-valued Functions

To state a multi valued function, use:
z = \left\{
1 & x >0 \\
0 & \mbox{otherwise}

Equation arrays with (some) equation numbers

The eqnarray environment produces a math-mode environment with an array of 3 columns aligned {rcl}. E.g.
|O| & \leq & |O \setminus A| + |A| \leq \label{eq:start} \\
& \leq & |A| + |A| \leq \nonumber \\
& \leq & 2|A|
Notice the \nonumber on the second line which omits the number. If all lines should be number-less, you can use \begin{eqnarray*} instead of \begin{eqnarray}.

Page Settings


In order to have text written on entire page, consider using the fullpage package, with the additional

Explicitly Determining Page Margins

Consider using the geometric package, e.g.
produces 2.5cm left/right margins, and 4cm top/bottom margins (no need to manipulate any other offsets or heights).

Headers and Footers

Use the fancyhdr package, e.g.
\pagestyle{fancy} % sets the pagestyle to use fancy headers
\fancyhead{} % clear header
\fancyfoot{} % clear footer
\fancyfoot[CO,CE]{\thepage} % replaces the page number to the [C]enter of the footer, in both [O]dd and [E]ven pages
\fancyhead[LO,LE]{ABC} % puts 'ABC' on the header's [L]eft side, on both [O]dd and [E]ven pages
\fancyhead[CO,CE]{DEF} % puts 'DEF' on the header's [C]enter, on both [O]dd and [E]ven pages
\fancyhead[RO,RE]{GHI} % puts 'GHI' on the header's [R]ight side, on both [O]dd and [E]ven pages
One can of course distinguish between the header/footer that appears on odd and even pages.

Line Numbers

In order to have line numbers on the output, consider using the (somewhat buggy, but pretty straightforward) lineno package.

Put \linenumbers to have linenumbers run through the entire document, or \pagewiselinenumbers to have linenumbers reset to 1 at every page. Put either of these commands where you want the linenumbers to begin.

Watermarks and 'draft' version

In order to have a watermark sentence (e.g. ''Draft''), use the draftcopy package, with the additional parameters:
Where instead of [...] use a comma-separated list of parameters taken from the following:
none      Dont print DRAFT across any page
first      Print DRAFT across first page only
firsttwo      Print DRAFT across two first pages only
all      print DRAFT across all pages
bottom      print DRAFT on the bottom of all pages
bottomafter      print DRAFT on the bottom of all pages following the ones who have DRAFT across
light      print DRAFT in light gray
dark      print DRAFT in dark gray
In order to choose the sentence printed (instead of DRAFT), use the command
where the first argument is the sentence to be printed, and the second argument is the scaling factor (start from about 50). This command should appear before the \begin{document} command.


printing slides k-up

To print slides in k-up, use the unix command
psnup -r -k


vertical spacing - space between rows

To adjust the vertical space between rows, i.e. - increase the space between the text and the top/bottom \hline commands, put the following in the preamble:
% Adds a space between the text and the [T]op \hline

% Adds a space between the text and the [B]ottom \hline
one can then use \T and/or \B inside a cell in the row, i.e. after some text in the row, to get extra space between the text and the \hline. These commands will not work if placed between rows. E.g.
% \T and \B would not work if it is placed here (needs to go inside cell)
Col1 \T \B & Col2 \\
$\sqrt{\frac{1}{2}}$ \T & more space from top \verb+\hline+ \\
$\sqrt{\frac{1}{2}}$ & no added space \\
$\sqrt{\frac{1}{2}}$ \B & more space from bottom \verb+\hline+ \\
Col1 & Col2 \\
$\sqrt{\frac{1}{2}}$ & no extra space from top \verb+\hline+ \\
$\sqrt{\frac{1}{2}}$ & no added space \\
$\sqrt{\frac{1}{2}}$ & no extra space from bottom \verb+\hline+ \\

Fixed width columns

To have fixed width columns, the simplest way is to use the 'p' alignment argument (instead of r/c/l). E.g.


Images with math (via xfig)

To create images using xfig with math text, do the following:

In xfig: Afterwards:

Inserting an .eps figure

\epsfig{file=epsfig.eps, scale=0.5}
\caption{Some EPS figure}

Converting PStricks/pstex_t to EPS

Assuing the pstricks-figure/pstex_t is in file figfile, use a latex file (say, texfigfile.tex) containing:
\thispagestyle{empty} % omits page numbers.
The \thispagestyle{empty} is necessary for the bounding box to be defined properly by dvips. Then do
latex texfigfile.tex
dvips texfigfile.dvi -E
Note: the generated file might be a .ps file. However, one can still insert it like any other .eps figure.

Images with pdflatex

Converting images to .pdf
When using pdflatex, images should be converted to .pdf.
Inserting an image
One should add to the preamble
To insert an image, named e.g. pdffig.pdf, use:
\caption{Some caption}
Note that the 'original' files, i.e., the .pstex_t|.pstex|.eps files, should be present in the working directory as well.

pstex missing

When using the Combined PS/LaTeX format in exporting from xfig, two files are generated:

[figname].pstex - contains the graphical information. This is basically an .eps file.

[figname].pstex_t - contains the latex text information.

The [figname].pstex_t file uses \includegraphics{[figname].pstex} to include the graphical info. When compiling from different directories, it is important to make sure that right path appears in the \includegraphics command, namely, that it has the form \includegraphics{PATH/[figname].pstex}

Inserting .jpg images

To insert an image, named e.g. image.jpg, use:
\caption{Some caption}
Remember to specify the 'width' argument.

Drawing Circuits and Logic Diagrams

Use Circuit_macros: Download: dpic

Converting PDF figures to EPS

Download XPDF (for windows), and use the command:
[xpdf-path]\epstopdf.exe -eps input.pdf output.eps


General use

To use the algorithm environment, use the packages
An example of an algorithm is given by:
\caption{MyAlgorithmName (...arguments...)}
    \For{all ...}
        \State do ...
    \State return ...

Changing the type of caption

Sometimes one wants to use the algorithm environment so that instead of Algorithm, one has a different caption, e.g. Protocol, Heuristic, etc. To do this, use the line
\floatname{algorithm}{[New Name]}
just before the algorithm code. E.g., to produce a Protocol, use
\caption{MyProtocolName (...arguments...)}

Algorithm counters in beamer

When preparing slides with overlays using beamer, algorithms in later overlays have their counter increase with each overlay, resulting in a wrong presented counter. To remedy this, one has to explicitly adjust the counter. This could be done within the algorithm environment by using the \addtocounter{algorithm}{...} command.

For example, if the algorithm should be displayed on the second overlay, one could use
which would reduce the counter by 1, and display Algorithm 1 (instead of Algorithm 2). Note that the \addtocounter{algorithm}{...} command should immediately precede the \begin{algorithmic} command.

NOTE: This would only work once in a frame. Beyond that counter management becomes harder.


Using a BibTeX file

To insert the bibliography from a .bib file (e.g. mybib.bib), add the commands
For different styles, see

Producing all entries in the .bib file

To produce the list of all entries in the .bib file, add the command
just before the \bibliography{mybib} command, where the bibliography file is mybib.bib.

Contorling bibliography paramaters

The natbib package provides multiple functionalities. E.g.
determines the space between bib entries.
determines the font used for bib entries.

Contorling bibliography section header

To change the text in the bibliography section header (e.g., to produce 'Bibliography', instead of 'References'), use
just before the bibliography section.


From .tex to A4 .pdf

To produce a pdf for paper size A4, make sure the \documentclass command is defined properly, e.g.,
Use dvips with the switch
-G0 -Ppdf -t A4Size
followed by ps2pdf with the switch
This solves the problem of having incorrect header/footer margins.

Converting .eps to .pdf with embedded fonts

Sometimes, when compiling with pdflatex, one uses .pdf figures that don't have the fonts embedded. To transform the figures to have fonts embedded, one must do the following (in windows), given IN.eps as the eps input file of a figure.
epstopdf  --outfile="TEMP_OUT.pdf" IN.eps
followed by
"[ghostscript\bin path]\gswin32c" -dSAFER -dNOPLATFONTS -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.4 -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -sOutputFile="OUT.pdf" -f TEMP_OUT.pdf
One can then compile the source with the new figures using pdflatex, as usual.

Note: Sometimes discoloration appears in B/W figures. This can be remedied (not elegantly, but it works) by printing the resulting pdf to a new pdf using B/W only. The fonts remain embedded in the resulting .pdf as well.

Converting .eps to .pdf with embedded fonts

Some journals require figures in .eps format. To convert a .pdf figure to .eps, use (be sure to verify the output is in order):
gs -dNOPAUSE -dNOCACHE -dBATCH -sDEVICE=epswrite -sOutputFile=[output-file-name].eps [input-file-name].pdf 


Highlighting text

To produce highlighted text use the soul package, and put the highlighted text in an \hl{...} environment (the default is yellow highlighting). I.e., use
This text would be \hl{highlighted} now.
If one omits the color package, the \hl{...} environment produces an underline.

User Defined Font Size

Sometimes, the predefined \normalsize, \small, \huge, etc., font sizes do not suffice. To produce a userdefined font size one can use the command:
where the first argument gives the height of the font (in pt), and the second argument gives the height of the line (in pt).
E.g., the above \myfontsize produces a fontsize that is between \small and \tiny.