Ryan's Blog

Latex: add date/time to footer

Posted in Uncategorized by ryanlayer on December 31, 2013
\usepackage{fancyhdr}
\usepackage{datetime} %access to \currenttime
\pagestyle{fancy}
\fancyhead{} %clear out default
\fancyfoot[R]{\today\ \currenttime} %set date/time on right
\fancyfoot[C]{\thepage} % page in center
\renewcommand{\headrulewidth}{0pt} % remove awful top bar

More at here and MORE here.

Tagged with: , ,

Metapost Graphs

Posted in latex by ryanlayer on October 24, 2009

Data file: data.d

1 4
2 2
3 1
4 2
5 4

Metapost file:

beginfig(1);
draw begingraph(3in,2in);
gdraw “data.d”;
glabel.bot(btex $x$-axis etex, OUT);
glabel.lft(btex $y$-axis etex, OUT);
glabel.top(btex The graph of $y=f(x)$. etex, OUT);
glabel.rt(btex $y={1\over{4-x^2}}$ etex, 2,3);
endgraph;
endfig;

Tagged with: , ,

Practical Latex and Metapost Tips

Posted in latex by ryanlayer on October 24, 2009

Found what looks like a great collection of practical Latex and Metapost tips.

http://online.redwoods.cc.ca.us/instruct/darnold/staffdev/

Tagged with: ,

Handy Latex Metapost Bibtex Makefile

Posted in latex by ryanlayer on October 8, 2009

This Makefile is not the most robust thing in the world, but it is generic enough for me to use on almost all of my documents.  The command you want to run is `make FILE=<latex file name without extension>`.  If your file is doc.tex, then you will run `make FILE=doc`.  The assumption here is that the tex, mp, and bib files all have matching names (e.g., doc.tex, doc.mp, and doc.bib).  The Makefile checks to see if the metapost file and bibtex file exist before attempting to process them.  The Makefile creates dvi, ps, and pdf files.

NOTE:  You will have to insert tabs to make this work

MPOSTDIR:=./
BIBDIR:=./
LATEX_OPTS:=-halt-on-error
FILE:=$(strip $(wildcard *.tex))
MPOSTFILE:=$(wildcard $(MPOSTDIR)/$(FILE).mp)
BIBFILE:=$(wildcard $(BIBDIR)/$(FILE).bib)
all: pdf

pdf: ps
ps2pdf $(FILE).ps

ps: dvi
dvips -t letter $(FILE).dvi -o $(FILE).ps

dvi: mp bib
latex $(LATEX_OPTS) $(FILE).tex

quick: mp
latex $(LATEX_OPTS) $(FILE).tex
dvips $(FILE).dvi -o $(FILE).ps

bib:
ifdef BIBFILE
latex $(LATEX_OPTS) $(FILE).tex
bibtex $(BIBDIR)/$(FILE)
latex $(LATEX_OPTS) $(FILE).tex
endif

mp:
ifdef MPOSTFILE
cd $(MPOSTDIR) && \
mpost $(FILE).mp && \
cd ..
endif

clean:
rm -f *.aux
rm -f *.bbl
rm -f *.blg
rm -f *.log
rm -f *.dvi
rm -f *.ps
rm -f *.tex\~

Tagged with: ,

Latex Mathematical Symbols

Posted in latex by ryanlayer on October 6, 2009

In the following tables you find all the symbols normally accessible from math mode.

To use the symbols listed in Tables 3.123.16[*], the package amssymb must be loaded in the preamble of the document and the AMS math fonts must be installed on the system. If the AMS package and fonts are not installed, on your system, have a look at
CTAN:/tex-archive/macros/latex/packages/amslatex

Table 3.1: Math Mode Accents
\begin{table}\begin{symbols}{*4{cl}} \W{\hat}{a} & \W{\check}{a} & \W{\tilde}{a}...  ...}{a} &\W{\vec}{a} &\W{\widehat}{A}&\W{\widetilde}{A}\\  \end{symbols}\end{table}

Table 3.2: Lowercase Greek Letters
\begin{table} \begin{symbols}{*4{cl}}  \X{\alpha} & \X{\theta} & \X{o} & \X{\ups...  ...& \X{\varsigma} & & \\   \X{\eta} & \X{\xi} & \X{\tau}  \end{symbols}\end{table}

Table 3.3: Uppercase Greek Letters
\begin{table} \begin{symbols}{*4{cl}}  \X{\Gamma} & \X{\Lambda} & \X{\Sigma} & \...  ...lon} & \X{\Omega} \\   \X{\Theta} & \X{\Pi} & \X{\Phi}  \end{symbols}\end{table}

Table 3.4: Binary Relations
\begin{table} \bigskipYou can produce corresponding negations by adding a \verb*...  ...notesize$^a$Use the \textsf{latexsym} package to access this symbol} \end{table}

Table 3.5: Binary Operators
\begin{table} \begin{symbols}{*3{cl}}  \X{+} & \X{-} & & \\   \X{\pm} & \X{\mp} ...  ...\X{\unlhd}$^a$\space & \X{\unrhd}$^a$\space & \X{\wr} \end{symbols}  \end{table}

Table 3.6: BIG Operators
\begin{table} \begin{symbols}{*4{cl}}  \X{\sum} & \X{\bigcup} & \X{\bigvee} & \X...  ...igodot} \\   \X{\int} & \X{\oint} & & & \X{\biguplus} \end{symbols}  \end{table}

Table 3.7: Arrows
\begin{table} \begin{symbols}{*3{cl}}  \X{\leftarrow}or \verb*\vert\gets\vert& \...  ...notesize$^a$Use the \textsf{latexsym} package to access this symbol} \end{table}

Table 3.8: Delimiters
\begin{table}\begin{symbols}{*4{cl}}  \X{(} & \X{)} & \X{\uparrow} & \X{\Uparrow...  ...{\rceil} \\   \X{/} & \X{\backslash} & &. (dual. empty) \end{symbols}\end{table}

Table 3.9: Large Delimiters
\begin{table} \begin{symbols}{*4{cl}}  \Y{\lgroup} & \Y{\rgroup} & \Y{\lmoustach...  ... \\   \Y{\arrowvert} & \Y{\Arrowvert} & \Y{\bracevert}  \end{symbols}\end{table}

Table 3.10: Miscellaneous Symbols
\begin{table} \begin{symbols}{*4{cl}}  \X{\dots} & \X{\cdots} & \X{\vdots} & \X{...  ...notesize$^a$Use the \textsf{latexsym} package to access this symbol} \end{table}

Table 3.11: Non-Mathematical Symbols
\begin{table} \bigskipThese symbols can also be used in text mode. \begin{symbol...  ...opyright} \\  \SC{\ddag  } & \SC{\P} & \SC{\pounds} \\  \end{symbols}\end{table}

Table 3.12: AMS Delimiters
\begin{table}\bigskip\begin{symbols}{*4{cl}} \X{\ulcorner}&\X{\urcorner}&\X{\llcorner}&\X{\lrcorner} \end{symbols}\end{table}

Table 3.13: AMS Greek and Hebrew
\begin{table} \begin{symbols}{*5{cl}} \X{\digamma} &\X{\varkappa} & \X{\beth}& \X{\daleth} &\X{\gimel} \end{symbols}\end{table}

Table 3.14: AMS Binary Relations
\begin{table}% latex2html id marker 2770  \begin{symbols}{*3{cl}}  \X{\lessdot} ...  ...lefteq} & \X{\trianglerighteq} &\X{\blacktriangleright} \end{symbols}\end{table}

Table 3.15: AMS Arrows
\begin{table} \begin{symbols}{*3{cl}}  \X{\dashleftarrow} & \X{\dashrightarrow} ...  ...& \\   \X{\circlearrowleft} & \X{\circlearrowright} & & \end{symbols}\end{table}

Table 3.16: AMS Negated Binary Relations and Arrows
\begin{table}\begin{symbols}{*3{cl}}  \X{\nless} & \X{\ngtr} & \X{\varsubsetneqq...  ...Leftarrow} & \X{\nRightarrow} & \X{\nLeftrightarrow}\par\end{symbols}\end{table}

Table 3.17: AMS Binary Operators
\begin{table} \begin{symbols}{*3{cl}}  \X{\dotplus} & \X{\centerdot} & \X{\inter...  ...& \X{\circledast} \\   \X{\curlyvee} & \X{\curlywedge}  \end{symbols}\end{table}

Table 3.18: AMS Miscellaneous
\begin{table} \begin{symbols}{*3{cl}}  \X{\hbar} & \X{\hslash} & \X{\Bbbk} \\   ...  ...& \X{\Finv} & \X{\varnothing} \\   \X{\eth} & \X{\mho}  \end{symbols}\end{table}

Table 3.19: Math Alphabets
\begin{table} \begin{symbols}{@{}*3l@{}} Example& Command &Required package\\  \...  ...b{ABC}\vert  &\textsf{amsfonts} or \textsf{amssymb} \\  \end{symbols}\end{table}

SOURCE: http://www.physics.udel.edu/~dubois/lshort2e/node61.html

Tagged with: ,

Squeezing Space in LaTeX

Posted in latex by ryanlayer on October 6, 2009

Here are some tips on how to squeeze a little more onto LaTeX pages. Note that these methods may adversely affect the appearance of the document, so use them with caution. Rephrasing and editing your text often leads to better results.

The savetrees package executes many of these methods, packing as much text as possible onto each page.

Fonts

Without changing the point size of a font you might be able to fit more text on a page by choosing a more compact font like Times

Page Layout

The a4 package will give you narrower margins. To have more control use the geometry package. If you use the layout package then \layout will produce a test page showing the values of the variables that control page layout.

Prof. Koenraad De Smedt’s suggested that by using \linespread{0.9} (which multiplies the normal space between lines by a factor 0.9) you can often get satisfactory results.

Changing lengths

There are many variables in LaTeX determining lengths. Two commands to change them are \addtolength and \setlength. The dimensions understood by LaTeX include cm, mm, in and pt. Variables can be set to a negative value.

Example: \addtolength{\parindent}{-5mm}

Some useful variables are

  • Page Layout
    • \columnsep: gap between columns
    • \topmargin: gap above header
    • \topskip: between header and text
    • \textheight: height of main text
    • \textwidth: width of text
    • \oddsidemargin: odd page left margin
    • \evensidemargin : even page left margin
  • Paragraphs
    • \parindent: indentation of paragraphs
    • \parskip: gap between paragraphs
  • Floats (tables and figures)
    • \floatsep: space left between floats.
    • \textfloatsep: space between last top float or first bottom float and the text.
    • \intextsep : space left on top and bottom of an in-text float.
    • \dbltextfloatsep is \textfloatsep for 2 column output.
    • \dblfloatsep is \floatsep for 2 column output.
    • \abovecaptionskip: space above caption
    • \belowcaptionskip: space below caption
  • Maths
    • \abovedisplayskip: space before maths
    • \belowdisplayskip: space after maths
    • \arraycolsep: gap between columns of an array
  • Lists
    • \topsep: space between first item and preceding paragraph.
    • \partopsep: extra space added to \topsep when environment starts a new paragraph.
    • \itemsep: space between successive items.

Environments

The atbeginend.sty package provides \BeforeBegin{environment}{code-to-execute}, \AfterEnd ... etc. These commands can be used to remove space around and within environments. This can be useful in situations where the environment resets values that over-ride those you’ve created. For example, \AfterBegin{itemize}{\addtolength{\itemsep}{-\baselineskip}} in a LaTeX file squeezes items together by resetting \itemsep inside the environment.

The mdwlist package has a itemize* environment.

The paralist package offers a compactitem environment (that puts less space between items) and an inparaenum environment (that doesn’t create new paragraphs for each item).

Figures and Tables

To save space, you can put more than one graphic inside a figure environment by using the subfigure package. It’s also possible to wrap text around a figure using the floatflt package.

Using “\begin{figure} ... \centering ...” rather than “\begin{figure} ... \begin{center} ...” saves space. Sometimes excessive white space around a figure isn’t LaTeX’s fault. It may be that a postscript figure contains a big white border. ps2epsi can be used to produce a minimal bounding box, or you can use the clipping feature of the \includegraphics command of the graphicx package.

By default, LaTeX doesn’t like to fill more than 0.7 of a text page with tables and graphics, nor does it like too many figures per page. This behaviour can be changed by placing lines like the following before \begin{document}

\renewcommand\floatpagefraction{.9}
\renewcommand\topfraction{.9}
\renewcommand\bottomfraction{.9}
\renewcommand\textfraction{.1}   
\setcounter{totalnumber}{50}
\setcounter{topnumber}{50}
\setcounter{bottomnumber}{50}

To reduce the size of captions use the caption package.

If you have a big table you might wish to bracket it by \begin{small}\end{small}.

You can reduce the gap between table columns by using \setlength{\tabcolsep}{1pt}. It may also be possible to scale a whole table as you can a piece of graphics, using \resizebox{!}{5cm}{\begin{tabular} ... \end{tabular}} though you need to view the output as postscript.

Controlling where space goes

If latex can’t fill a page (perhaps because the next object is a figure or table that doesn’t fit, or because the next object is a heading that latex doesn’t want to put at the foot of a page) then by default it will spread the vertical white space on the page so that the “height” of the page is the default height. If you want all the extra white space to appear at the bottom of such pages, add \raggedbottom before your \begin{document} line.

Headings

Vertical space around a heading depends on \parskip, \baselineskip and other parameters that LaTeX sends to the @startsection routine. Remember also that LaTeX doesn’t like putting a heading right at the bottom of a page – it would rather leave space.

Unless you want to redefine the sectioning commands yourself, it’s worth looking at the titlesec package, which offers space-saving alternatives to the standard sectioning commands (especially \chapter). Even just \usepackage[small,compact]{titlesec} might save you quite a lot.

Contents and bibliography

The package lets you have a two column table of contents in a single column document.

To reduce the linespacing in a bibliography (the same idea works for contents pages) use the setspace package

\begin{spacing}{0.9}
\tableofcontents
\end{spacing}
...

\begin{spacing}{0.9}
\bibliographystyle{plain}
\bibliography{refs}
\end{spacing}

If you’re using the natbib package (recommended) then you can change the value of \bibsep to control the gap between items. Otherwise put the following (suggested by Axel Reichert) in the preamble

  \let\oldthebibliography=\thebibliography
  \let\endoldthebibliography=\endthebibliography
  \renewenvironment{thebibliography}[1]{%
    \begin{oldthebibliography}{#1}%
      \setlength{\parskip}{0ex}%
      \setlength{\itemsep}{0ex}%
  }%
  {%
    \end{oldthebibliography}%
  }

You can use the same idea to modify other environments – theglossary, etc.

SOURCE: http://www.eng.cam.ac.uk/help/tpl/textprocessing/squeeze.html

Tagged with: , ,

Including graphics in a LaTeX document

Posted in latex by ryanlayer on October 6, 2009

There are two ways to incorporate images into your LaTeX document, and both use the graphicx package by means of putting the command  \usepackage{graphicx} near the top of the LaTeX file, just after the documentclass command.

The two methods are

  1. include only PostScript images (esp. “Encapsulated PostScript”) if your goal is a PostScript document using dvips
  2. include only PDF, PNG, JPEG and GIF (Stefan correctly pointed out that GIF is not supported, you must convert to a supported fomat) images if your goal is a PDF document using pdflatex, TeXShop, or other PDF-oriented compiler.

In all cases, each image must be in an individual 1-image file; no animation files or multipage documents.

Only PostScript images

Most mathematical/scientific graphics software allows you to save graphics (figures, diagrams, graphs) in PostScript form; this includes Mathematica, Maple, Matlab, IDL, and xfig (a marvelous X figure-drawing program). Even bitmap images like JPEG and PNG files can be converted to PostScript form with programs like “xv” or “convert

”.

Where you want a PostScript image to appear, use the \includegraphics command, possibly with scaling or rotation options, e.g.,

  \includegraphics{myfig.eps}
  \includegraphics[width=60mm]{myfig.eps}
  \includegraphics[height=60mm]{myfig.eps}
  \includegraphics[scale=0.75]{myfig.eps}
  \includegraphics[angle=45,width=52mm]{myfig.eps}

Of course, any of these can be inserted into a figure environment, and/or a centering environment or a framebox.

Then you must compile the document with latex followed by dvips -Ppdf, which produces a PostScript document with embedded PostScript images. You can convert the PostScript document to PDF using “ps2pdf” or “dvipdf”.

Two characteristics which the component (Encapsulated) PostScript image files must have are

  • no file contains more than one page
  • each has a valid BoundingBox line

If the PostScript file does not include a bounding box line, you can insert it using the text editor of your choice.

Only non-PostScript images

The compiler pdflatex (Unix) and TeXShop (Macintosh) convert LaTeX source directly to PDF, and do not accept PostScript images. Instead, they take PDF images, as well as bitmap pictures in PNG or JPEG or GIF format. So to use pdflatex, you must convert any PostScript images to one of these other forms. For photos, JPEG is best. For other bitmap images, PNG is best. For non-bitmap images (e.g., graphs, drawings, stuff with text and symbols) it is best to convert to PDF, using the command epstopdf (in the usual TeX bin directory, e.g., /usr/local/tex/bin/epstopdf). The command

unix>   epstopdf myfig.eps

produces the file myfig.pdf, which can then be used in the command \includegraphics{myfig.pdf}. for compilation with pdflatex or TeXShop.

The possible \includegraphics options with PDF/PNG/JPEG images are much the same as with PostScript, e.g.,

  \includegraphics{myfig.pdf}
  \includegraphics[width=60mm]{myfig.png}
  \includegraphics[height=60mm]{myfig.jpg}
  \includegraphics[scale=0.75]{myfig.pdf}
  \includegraphics[angle=45,width=52mm]{myfig.jpg}

With PNG or JPEG you should specify an explicit width or height rather than “scale”, since bitmap images have no intrinsic size, nothing corresponding to Bounding Box information, although graphicx seems to use 72 pixels per inch as a default size for bitmap images.

SOURCE:http://amath.colorado.edu/documentation/LaTeX/reference/figures.html

NASA GISS Help with Latex

Posted in latex by ryanlayer on October 5, 2009
Tagged with:

Latex cline

Posted in latex by ryanlayer on October 5, 2009

\cline

\cline{i-j} The \cline command draws horizontal lines across the columns specified, beginning in column i and ending in column j, which are identified in the mandatory argument. It is used in the tabular and array environment. Two (or more) successive \cline commands draw lines in the same vertical position. Typically, \cline commands are placed after a \ (line breadk) command so that they separate items on two lines; they do not, however, need a line break command afterwards. \begin{tabular}{|r|l|} \hline 7C0 & hexadecimal \ 3700 & octal \ \cline{2-2} 11111000000 & binary \ \hline \hline 1984 & decimal \ \hline \end{tabular} produces this output
Tagged with: , ,

Aligning on decimal points: an example of the @ specifier

Posted in latex by ryanlayer on October 5, 2009

In scientific tables it is often desirable to align the columns on a decimal point. This can be done using the @ col specifier and breaking the number into the integral part in a right-justified column and the fractional part in a left-justified column:

  The following input:          will display as:

  \begin{tabular}{r@{.}l}
  3&14159\                         3.14159
  16&2\                           16.2
  123$456\ \end{tabular}         123.456  

Note that the decimal point is replaced by the column separator, & and that the @suppresses the intercolumn space

Tagged with: ,