# Latex tips by A. Fornasiero

## 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
\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

• \DeclareFontFamily{OT1}{pzc}{}
\DeclareFontShape{OT1}{pzc}{m}{it}%
{<-> s * [0.900] pzcmi7t}{}
\DeclareMathAlphabet{\mathpzc}{OT1}{pzc}%
{m}{it}
Zapf Chancery is the standard PostScript calligraphic font. Allows to use the command \mathpzc for calligraphic letters (uppercase and lowecase) in math mode. s* means silently the number in [] is the magnification factor (default 1).
Usage: \fontfamily{pzc}\selectfont to switch to Zapf Chancery in normal text; $\mathpzc{text}$ to use Zapf Chancery inside math mode.
•  \renewcommand\@makefnmark{\@textsuperscript{\normalfont(\@thefnmark)}} 
change style of footnotes: (1) instead of 1
• \renewcommand{\@pnumwidth}{1.75em}
\renewcommand{\@tocrmarg}{2.75em}  
redefine the page number width in the toc, in order to avoid overflowing
• \newcommand{\rst}[1]{\ensuremath{{\mathbin\upharpoonright}%
\raise-.5ex\hbox{$#1$}}}  
define the \rst command. \rst{A} print something like |A, with the A slightly lowered. $f\rst{A}$ should mean the function f restricted to the set A.
• \newcommand{\unover}[1]{\ensuremath{%
\frac{\raisebox{-.1ex}{\ensuremath{1}}}%
{\raisebox{.2ex}{\ensuremath{#1}}}}}  
define \unover
\unover{x} prints a better looking fraction 1/x to be used in display math mode
• \newcommand{\unosu}[1]{\ensuremath{\mathchoice%
{\unover{#1}}%        display math mode
{\nicefrac{1}{#1}}%   in-line math mode
{\nicefrac{1}{#1}}%   scriptstyle
{\nicefrac{1}{#1}}}}% scriptscriptstyle  
define \unosu
\unsosu{x} print a better version of 1/x uses the package nicefrac

## 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
\addcontentsline{toc}{chapter}{Index}
\clearpage
\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.
Back to homepage
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