Latex tips by A. Fornasiero

additional (La)TeX links

Tex search path

By default, TeX and friends will look for a file in the following locations (in order):

  1. the user tex directory: in my case, ~/texmf (where ~ stands for the home directory);
  2. the local tex directory: /usr/local/share/texmf
  3. the main tex directory: /usr/share/texmf

The defaults are set in the file texmf.cnf (in our system, the complete path is /usr/share/texmf/web2c/texmf.cnf).
If you want to install a tex file, copy it in a suitable subdirectory of ~/texmf (e.g., you will copy a Latex .sty file in a subdirectory of ~/texmf/tex/latex/), and then re-build the database, using the comand texhash . from inside ~/texmf (note the dot).

Suppose now that you want to modify the search path. We will consider the following case: you want tex to search (in order) your texmf directory, the texmf directory of the user fornasiero (me), and then the "system" texmf directories. Of course, we will assume that you can read the contents of the directory /home/fornasiero/texmf. You have to set the system variable $TEXMF. Assume that your home is /home/pippo. With the value
TEXMF= {!!/home/pippo/texmf,!!/usr/local/share/texmf,!!/usr/share/texmf}
you obtain the default behaviour described above. You have to modify TEXMF, and obtain:
TEXMF= {!!home/pippo/texmf,!!/home/fornasiero/texmf,!!/usr/local/share/texmf,!!/usr/share/texmf}

Method: for a temporary change, write (on you shell: we will assume that you use the bash shell)
export TEXMF='{!!$HOME/texmf,!!/home/fornasiero/texmf,!!/usr/local/share/texmf,!!/usr/share/texmf}'
for a permanent change, add the above line to your .bashrc file (it should be in your home directory; if it is not there, create one containing the above line).

Interesting packages

babel
adding for hyphenation and changing names (ad es. section -> sezione)
\usepackage[british]{babel}
amsmath amssymb amsthm
AMS maths packages. amssymb for symbols (greek letters, \prod, etc.) amsthm for theorem environments
nicefrac
for better looking "small" fractions
\usepackage[nice]{nicefrac}
cases
case construction with numeration of every formula
enumerate
better enumeration environment
\begin{enumerate}[{punto }a.]
enumerates using the format punto a, punto b etc. You can use I for roman etc.
You could use instead \renewcommand{\enumi}{punto \alph{enumi}}
makeidx
indexing package
multind
allows many different indexes
xspace
defines the command \xspace
newcent
NewCentury, AvantGarde, Courier fonts
yfonts
additional fonts: gothic, etc. allows to use \textfrak and \textswab
letterspace
to enlarge the space between letters:
\letterspace to 1.5\naturalwidth{abcdefghijklmnopqrstuvwxyz}
prints the alphabet with large space between letters
hyperref
embeds hyperlinks nel file dvi (o pdf) should be installed as the last one but before using \newtheorem
hypbmsex
bookmark entries can be given in another argument of the sectioning commands, for compatibility with pdftex
nohyperref
simulates some commands in hyperref, for compatibility with hyperref
\usepackage[hypertex,colorlinks=true]{hyperref}
srcltx
activates source specials for forward searching
\usepackage[active]{srcltx}
preview
previews the dvi file in the emacs buffer; works with AUCTeX and (X)Emacs
\usepackage[sections,floats,textmath,displaymath]{preview}
showkeys
show key labels in the dvi file
\usepackage[notref]{showkeys}

Tricks

Commands

\ensuremath{formula}
ensures to be in math mode
\newcommand[2][normal]{\pippo}{text #1 #2d}
defines the commands \pippo, with 2 arguments, the first optional, and with default value normal.
\pippo[first]{second}
output
text first second
\providecommand{\pippo}{something}
defines the command \pippo, if it does not already exists; otherwise, does nothing
\renewcommand{\pippo}{something}
redefines the command \pippo, if it does not already exists; otherwise, gives error
\input{nomefile}
inserts the contents of file nomefile as it is
\include{nomefile}
start a new page and inputs nomefile. You cannot \include inside an included file (bu you can use \input instead)
\includeonly{file1,file2}(in the preamble)
tells to use only the files file1 and file2 among the ones mentioned by the \include However, it keeps page numbering and labels as if all files were included

Index

\makeindex \makeglossary (in the preamble)
create index and glossary files
\printindex (in the text)
print the index
\index{$\exp$|see{exponential}} (in the text, at any point, better at the beginnig)
create the index entry $\exp$ (a symbol), with the caption see exponential
\index{$\exp$}(in the text)
add the current page to the $\exp$ entry
\index{length!common}
add the common subetry to the length entry
\index{exponential|(} many pages of text ... text \index{exponential|)}
add a page-range to the exponential entry
Usage
index filename
or index -s indextyle filename
e.g. index -s gind.ist plan
creates an index file for plan.tex using the style gind.ist

Fonts

Mathematics fonts

\mathbf
Bold
\mathsf
Sans-serif
\mathit
Italics
\mathtt
Typewriter
\mathrm
Roman
\mathfrak
Fraktur
\mathcal
CALLIGRAPHIC; only uppercase letters
\mathbb
Blackboard BOLD; only uppercase letters
\mathpzc
Zapf chancery
\text
Text inside math formula

Text fonts

\textit
Italics
\textsl
Slanted
\textbf
Bold
\texttt
Typewriter
\textsc
Small caps
\textsf
Sans-serif
\emph
emphasized (italics)

Font sizes

\tiny
\scriptsize
\footnotesize
\small
\normalsize
default
\large
\Large
\LARGE
\huge
\Huge

Math operators, spacing and dimension

\mathord
normal symbol (eg. a)
\mathop
operator
\mathbin
binary operator
\mathopen \mathclose
parentheses
\mathpunct
punctuation
\left \middle \right
size changing symbols
\bigl \bigm \bigr
large size symbols

For example

\newcommand{\paren}[1]{\ensuremath{\left(#1\right)}}
(1) parentheses of variable height
\newcommand{\Paren}[1]{\ensuremath{\bigl(#1\bigr)}}
(1) big parentheses
\newcommand{\squares}[1]{\ensuremath{\left[#1\right]}}
[1] parentheses of variable height
\newcommand{\Squares}[1]{\ensuremath{\bigl[#1\bigr]}}
[1] big parentheses

Citations and references

\label{labelname}
create a new label
\ref{labelname}
insert a reference to the label
\cite{labelname}
insert a reference to a bibliographical item
\bibliography{surreals}
insert the bibliography from the surreals.bib database
\bibliographystyle{abbrv}
uses the abbrv style for the bibliography
\nocite{label1,label2}
insert label1 an label2 works in the bibliography, even if not actually cited in the text
\nocite{*}
inserts all works in the database
Usage
bibtex filename.tex
\tableofcontents
print a table of contents
\addcontentsline{toc}{chapter}{Index}
add the chapter Index to the table of contents. E.g.
\clearpage
\addcontentsline{toc}{chapter}{Index}
\printindex
will create an index and put the entry Index 117 in the Table of Contents (if, say, the index appears at page 117). You might want to use \cleadoublepage instead of \clearpage. Sometimes, no \clearpage is needed.
Thank to Jan Somorcik for a correction.

Hyphenation

\hyphenation{Ar-chi-me-dean De-de-kind sche-ma-ta}
tell how to hyphenate Archimedean, etc.
\def\hyph{\nobreakdash-\hspace{0pt}\relax}
define the \hyph command (using the amsmath package). \hyph prints a hyphen that does not prevent hyphenation.
E.g. non\hyph Archimedean $p$\hyph adic prints non-Archimedean p-adic and can be now hyphenated normally

Programming

\show\commandname
print in output the definition of the command \commandname
\xspace
print a space if necessary. E.g. \newcommand{\namely}{namely\xspace}
\namely x=y
prints namely x=y
\namely, x=y
prints namely, x=y
note that the spacing is correct in both cases.
There is a problem if before \xspace there is a point: TeX puts some extra space after a point. You can either use \frenchspacing to get rid of this space everywhere. Or you can disable it with \newcommand{\ie}{i.e.\@\xspace} or \newcommand{\ie}{i.e\mbox{.}\xspace} Ulrike Fischer.
Back to homepage
Valid XHTML 1.0! Valid CSS!
Please write me if you have suggestions, find mistakes and/or some links are not working.

My e-mail address is fornasiero at mail.dm.unipi.it
This page address: http://www.dm.unipi.it/~fornasiero/latex.html

Last modified: Mon Jan 9 12:02:43 CET 2012 by A. Fornasiero