Wednesday, July 28, 2010

matlab plotyy

Matlab plotyy is quite useful is we are trying to plot two lines with same x axis but different y-axis. Then it is easy to compare how these parameters vary with varying x coordinate.

Tuesday, May 19, 2009

Latex fonts

LaTeX: Fonts
Fonts

You will need to define your fonts at the beginning of any LaTeX document. After defining them, you'll only need to use font commands to change the font, for instance to bold or italicize a word or words.

In LaTeX, there are generally three styles within any font family, which are distinguished as font family, font shape, and font series. The commands for family, shape, and series are commutative, so they can be combined as with the command:
{\bfseries\itshape\sfffamily text you want in bold, italics, and sans-serif}

The above command would make the type in bold, italic, and sans-serif. The commands for font can only be combined as long as they aren't contradictory. Contradictory font commands would be trying to get slanted italics, or attempting to combine different font families.

LaTeX expects three font families as defaults.
Font Family Code Command
Roman (serif, with tails on the uprights) as the default rm \textrm{text}
Sans-serif, with no tails on the uprights sf \textsf{text}
Monospace (fixed-width or typewriter) tt \texttt{text}

For the common type shape and series commands, use the simplified syntax in the table below.

Type Style Command Example
Italic \textit{words in italics} puts the words in the brackets in italics
Slanted \textsl{words to be slanted} puts a few words in slanted type.
Small Capitals \textsc{words to be in small capitals} puts the words in the brackets in small capitals
Bold \textbf{words to be in bold} puts the words in brackets in bold
Sans-serif \textsf{words to be in sans-serif} puts the words into sans-serif type
Monospace \texttt{words to be in monospace} puts a few words in typewriter type
Emphasis \emph{word} italicizes word(s). When the surrounding text is in italics, LaTeX knows to read \emph{words} as emphasized and so it will unitalicize words when used within surrounding text already in italics.
Monospace {\tt words} Monospaces all words within the curly braces.
Italics {\it words} Italicizes all words within the curly braces.

Font Size

Font size in LaTeX is controlled with font size commands. Please note that you will need to reset the font size with one of these commands after changing it. Also, note that certain commands may overrule the font size commands; for instance, the \end{center} will cancel the font size commands. If you want to select just some text for a size change, use the following commands in the bracket, command, bracket words, close bracket, close bracket syntax; like this: {\huge{short}}. The commands and their sizes are listed in the table below.
Command Nominal Point Size Exact Point Size
\tiny 5 5
\scriptsize 7 7
\footnotesize 8 8
\small 9 9
\normalsize 10 10
\large 12 12
\Large 14 14.40
\LARGE 18 17.28
\huge 20 20.74
\Huge 24 24.88

Changing Fonts

If you use any packages that change the font, those packages will change the default of the same type. For instance, using the Bookman font (which is done by using this command in the preamble: \usepackage{bookman})makes the default Roman font Bookman, but leaves the sans-serif and monospace fonts alone. Similarly, using the Helvetica font (done with this command in the preamble: \usepackage{helvet}) changes the default sas-serif font to Helvetica, but leaves the Roman and Monospace fonts alone. When changing fonts, you can do so like this, using the command and calling the particular font, or you can change all of the default fonts at once with the following commands.
Command Changes the defaults to
times Times, Helvetica, Courier
pslatex same as Times, but uses a specially narrowed Courier. This is preferred over Times because of the way it handles Courier.
newcent New Century Schoolbook, Avant Garde, Courier
palatino Palatino, Helevetica, Courier
palatcm changes the Roman to Palatino only, but uses CM mathematics

For more on the fonts available with a typical LaTeX installation, please see the documentation in the IMAGE Lab (page 75 in A Beginner's Guide to Typsetting with LaTeX). Also, please note that there are many more fonts available for download.

Changing Fonts Temporarily

To change the font temporarily, first group the text where you want the font changed in curly braces. Then, use the commands \fontencoding, \fontfamily, and \selectfont. These commands should be used immediately inside the opening curly braces, like:

{\fontfamily{phv}\selectfont Helvetica looks like this}
and {\fontencoding{OT1}\fontfamily{ppl} Palatino looks like this}.
}

The above commands would make a sentence where "Helvetica looks like this" would be in the Helvetica font (phv is the code for Helvetica) and "and" would be in the default font and "Palatino looks like this" would be in the Palatino font (denoted with the Palatino code, which is ppl). This example would be very rare, but it shows how the fonts can be changed in the most extreme circumstances.

Font Color

Using the color package (which must be called in the Preamble), you can typeset LaTeX in any color. To add the color package in the Preamble, use the command:
\usepackage{color}

The color package makes a default color package available. The colors available with this are: red, green, and blue (for screen display) and cyan, magenta, and yellow (to go with black for the CMYK color model for printing). To make a single word or phrase in color, use the command:
\textcolor{color}{words to be in color}
For example, \textcolor{red}{text in red}

For more on color and how to use 255 colors, please see the documentation in the IMAGE Lab.

Monday, May 18, 2009

Parskip

\parskip

\parskip is the extra vertical space inserted before a paragraph. It has a natural length of zero but should be a rubber length so that it may be stretched in a flushbottom environment.

To increase \parskip to skip a line between paragraphs one could use

\addtolength{\parskip}{\baselineskip}
\baselineskip \baselinestretch

\baselineskip is a length command which specifies the minimum space between the botton of two successive lines in a paragraph. Its value may be automatically reset by LaTeX, for example, by font changes in the text. The value used for an entire paragraph is the value in effect at the blank line or command which ends the paragraph unit.

\baselinestretch scales the value of \baselineskip. Its default value is 1.0 but it may be reset with a \renewcommand command. If one wants to change the spacing in a document one should reset \baselinestretch and not \baselineskip as the latter may be reset automatically by LaTeX to account for local variations in the text, but it is always scaled by the former. In principle, "double spacing" can be obtained by \renewcommand{\baselinestretch}{2}.

\textwidth \linewidth

\textwidth is the normal width of the text on a page. It should generally be changed only in the preamble.

\linewidth is the width of lines in the current environment. Normally equal to \textwidth, it may be different within an environment such as list or quote environments

The \unitlength command is a Length command. It defines the units used in the Picture Environment.

The default value is 1 point (approximately 1/72 inch) but it may be changed using the \setlength command.

\newlength

\newlength{\gnat}

The \newlength command defines the mandatory argument, \gnat, as a length command with a value of 0in. An error occurs if a \gnat command already exists.

\setlength

\setlength{len-cmd}{len}

The \setlength command is used to set the value of a length command, len-cmd, which is specified as the first argument. The len argument can be expressed in any terms of length LaTeX understands, i.e., inches (in), millimeters (mm), points (pt), etc.

\addtolength{len-cmd}{len}

The \addtolength command increments a length command, len-cmd, which is specified by the first argument, by the amount specified in the len argument. It can be a negative amount.

As an example,

\addtolength{\parskip}{-.1\parskip}

decreases the value of \parskip by 10%.

\settowidth

\settowidth{len-cmd}{text}

The \settowidth command sets the value of a length command, len-cmd, which is specified as the first argument, equal to the width of the text argument in the current font.

\settoheight{len-cmd}{text}

The \settoheight command sets the value of a length command, len-cmd, which is specified as the first argument, equal to the maximum height of the text argument in the current font.

For example,

\settoheight{\baselineskip}{Xanadu}
\setlength{\baselineskip}{1.5\baselineskip}

would set the value of \baselineskip to 1.5 times the height of the capital "X".

\settodepth{len-cmd}{text}

The \settodepth command sets the value of a length command, len-cmd, which is specified as the first argument, equal to the depth (distance below the baseline) of the text argument in the current font.

The \hfill fill command produces a rubber length which can stretch or shrink horizontally. It will be filled with spaces. It is equivalent to \hspace\fill.

\hspace[*]{len}

The \hspace command adds horizontal space. The length of the space len can be expressed in any terms that LaTeX understands, i.e., points, inches, etc. You can add negative as well as positive space with an \hspace command. Adding negative space is like backspacing.

LaTeX removes horizontal space that comes at the end of a line. If you don't want LaTeX to remove this space, include the optional * argument. Then the space is never removed.

\addvspace{length}

The \addvspace command normally adds a vertical space of height length. However, if vertical space has already been added to the same point in the output by a previous \addvspace command, then this command will not add more space than needed to make the natural length of the total vertical space equal to length.

\smallskip

The \smallskip command is equivalent to \vspace{\smallskipamount} where \smallskipamount is determined by the document style.

\medskip

The \medskip command is equivalent to \vspace{\medskipamount} where \medskipamount is determined by the document style.

\bigskip

The \bigskip command is equivalent to \vspace{\bigskipamount} where \bigskipamount is determined by the document style.

\vfill

The \vfill fill command produces a rubber length which can stretch or shrink vertically. It is equivalent to a blank line followed by \vspace\fill. It should be used only in paragraph mode.

\vspace

\vspace[*]{length}

The \vspace command adds vertical space. The length of the space can be expressed in any terms that LaTeX understands, i.e., points, inches, etc. You can add negative as well as positive space with an \vspace command.

If \vspace appears in the middle of a paragraph the space is added after the line containing it.

LaTeX removes vertical space that comes at the end of a page. If you don't want LaTeX to remove this space, include the optional * argument. Then the space is never removed.

LATEX enumerate

Enumerate:

\begin{enumerate}
\item ...
\end{enumerate}

The enumerate-environment is used to create numbered lists.
If you like to change the appearance of the enumerator, the simplest way to change is to use the enumerate-package, giving you the possibility to optionally choose an enumerator.


\usepackage{enumerate}
...
\begin{enumerate}[I]%for capital roman numbers.
\item
\end{enumerate}

\begin{enumerate}[(a)]%for small alpha-characters within brackets.
\item
\end{enumerate}

Itemize:

\begin{itemize}
\item ...
\end{itemize}

Itemization is probably the mostly used list in Latex. It also provides four levels. The bullets can be changed for each level using the following command:

\renewcommand{\labelitemi}{$\bullet$}
\renewcommand{\labelitemii}{$\cdot$}
\renewcommand{\labelitemiii}{$\diamond$}
\renewcommand{\labelitemiv}{$\ast$}

Amongst the more commonly used ones are $\bullet$ (\bullet), $\cdot$ (\cdot), $\diamond$ (\diamond), $-$ (-), $\ast$ (\ast) and $\circ$ (\circ).

Description:

\begin{description}
\item[] ...
\end{description}

The description list might be the least known. It comes in very handy if you need to explain notations or terms. Its neither numbered nor bulleted.

Example:

\begin{description}
\item[Biology] Study of life.
\item[Physics] Science of matter and its motion.
\item[Psychology] Scientific study of mental processes and behaviour.
\end{description}

And in a PDF it would look like this:
Example of a description list.

Example of a description list.

Note:

The space between different items can be controlled with the \itemsep command (can only be added just after “begin”):

\begin{itemize}\itemsep2pt
\item
\end{itemize}