2. Macros
Definition
A shorthand command used to abbreviate another
command or series of commands.
A
Fact: LTEX is comprised of numerous macros built
on the TEX language.
3. How to write a Macro
Define a macro in the Preamble using:
newcommand{command name}{definition}
4. How to write a Macro
Define a macro in the Preamble using:
newcommand{command name}{definition}
Example:
newcommand{uva}{University of Virginia}
5. How to write a Macro
Define a macro in the Preamble using:
newcommand{command name}{definition}
Example:
newcommand{uva}{University of Virginia}
Whenever you want ”University of Virginia” to appear you use
the uva command.
6. Macros with Arguments
Specify the number of arguments in square braces:
newcommand{command name}[# args]{definition}
Refer to the arguments as #1, #2, #3, #4 etc. in the
definition.
7. Macros with Arguments
Specify the number of arguments in square braces:
newcommand{command name}[# args]{definition}
Refer to the arguments as #1, #2, #3, #4 etc. in the
definition.
Example:
newcommand{shout}[1]{{Huge{bf {#1}}}
8. Macros with Arguments
Specify the number of arguments in square braces:
newcommand{command name}[# args]{definition}
Refer to the arguments as #1, #2, #3, #4 etc. in the
definition.
Example:
newcommand{shout}[1]{{Huge{bf {#1}}}
Pay Attention!
9. Macros with Arguments
Specify the number of arguments in square braces:
newcommand{command name}[# args]{definition}
Refer to the arguments as #1, #2, #3, #4 etc. in the
definition.
Example:
newcommand{shout}[1]{{Huge{bf {#1}}}
Pay Attention!
shout{Pay Attention!}
12. Macros with Math
$$sum_{i=0}^n i^n$$
n
in
i=0
newcommand{sums}{$$sum {i=0}ˆn iˆn$$}
sums
newcommand{sums}[1]{$$sum {i=0}ˆ#1 iˆ#1$$}
sums{5}
5
i5
i=0
15. Renewcommand
Use renewcommand to redefine an existing command
Example:
The emph command italicizes its input.
Suppose you want to use it instead of the shout command:
renewcommand{emph}[1]{{Huge{bf {#1}}}
16. Renewcommand
Use renewcommand to redefine an existing command
Example:
The emph command italicizes its input.
Suppose you want to use it instead of the shout command:
renewcommand{emph}[1]{{Huge{bf {#1}}}
emph{Pay Attention!}
17. Renewcommand
Use renewcommand to redefine an existing command
Example:
The emph command italicizes its input.
Suppose you want to use it instead of the shout command:
renewcommand{emph}[1]{{Huge{bf {#1}}}
emph{Pay Attention!}
Pay Attention!
18. PerlTeX
PerlTeX allows you to define macros using the Perl programming
language
Download:
http://www.ctan.org/tex-archive/macros/latex/contrib/
perltex/
User Manual:
http:
//www.tug.org/TUGboat/Articles/tb25-2/tb81pakin.pdf
19. Ams-LaTeX
A
Ams-LaTeX is a collection of extensions for LTEX in the form of
document classes and packages designed to enhance the
typesetting of mathematics.
The Amsmath package is an extension of AMS-LaTeX that
provides:
Superior equation formatting
Support for multiline equations
Support for better equation numbering
Auxilliary packages that provide additional support for
displayed equations
20. Additional Packages
The Amsthm package provides extensions to the
A
LTEX newtheorem command which include:
Various theorem styles
More control over numbering
A proof environment
21. Additional Packages
The Amsthm package provides extensions to the
A
LTEX newtheorem command which include:
Various theorem styles
More control over numbering
A proof environment
The Amssymb package provides additional fonts and symbols:
22. Additional Packages
The Amsthm package provides extensions to the
A
LTEX newtheorem command which include:
Various theorem styles
More control over numbering
A proof environment
The Amssymb package provides additional fonts and symbols:
23. Amsmath Equation Environments - Align
1
begin{align}
x^2 + y^2 & = z^2 nonumber
x^3 + y^3 & < z^3
end{align}
x2 + y2 = z2
x3 + y3 < z3
(1)
Facts:
A
Better spacing than the LTEX eqnarray environment
Use the ”∗” to suppress numbering - begin{array∗}
Use nonumber to suppress numbering of individual equations
1
This and all following Amsmath slides adapted from
http://www.icms.org.uk/downloads/pgcourses/15october/Zachary.pdf
24. Amsmath Equation Environments - Multline
begin{multline}
lim_{xtoinfty}frac{P(M>x)}{overline{F^s}(x)}
le limsup_{xtoinfty}
frac{P(M>x,,S_{tau_1}>x-R+a-epsilon)}%
{overline{F^s}(x)}
+gamma
left(frac{2-gamma}{(a-epsilon)(1-gamma)^2}right)
end{multline}
lim
x→∞
P(M > x)
F s (x)
≤ lim sup
x→∞
P(M > x, Sτ1 > x − R + a − )
F s (x)
2−γ
+γ
(a − )(1 − γ)2
(2)
25. Amsmath Equation Environments - Cases
begin{equation*}
I_A =
begin{cases}
1 & text{if $xin A$}
0 & text{otherwise}
end{cases}
end{equation*}
IA =
1
0
if x ∈ A
otherwise
26. More Environments
Equation - single equation on a single line
Gather - multiple equations with no alignment
Flalign - horizontally spread version of align
Split - split single equations with alignment
begin{equation}
begin{split}
(a + b)^3 &= (a + b) (a + b)^2
&= (a + b)(a^2 + 2ab + b^2)
&= a^3 + 3a^2b + 3ab^2 + b^3
end{split}
end{equation}
(a + b)3 = (a + b)(a + b)2
= (a + b)(a2 + 2ab + b 2 )
= a3 + 3a2 b + 3ab 2 + b 3
(3)
29. AMS-LaTeX Assistance
For info on AMS-LaTeX:
http://www.ams.org/tex/amslatex.html
For info on the Amsmath package:
ftp://ftp.ams.org/pub/tex/doc/amsmath/amsldoc.pdf
For info on Amsthm:
ftp://ftp.ams.org/pub/tex/doc/amscls/amsthdoc.pdf
31. Headers and Footers
Fancyhdr package creates customizable headers and
footers:
documentclass { a r t i c l e }
usepackage { fancyhdr }
pagestyle{ fancyplain }
b e g i n { document }
l h e a d { Aubry W. V e r r e t }
r h e a d { t o d a y }
end{ document }
33. Fancyhdr Help
You can get assistance with Fancyhdr here:
ftp://ctan.tug.org/tex-archive/macros/latex/
contrib/fancyhdr/fancyhdr.pdf
34. Minipages
The Minipage environment creates miniature pages within
pages.
begin{minipage}...end{minipage}
It is suitable for:
Grouping figures or tables
Placement of footnotes attached to images
Placing a border around a figure and its title
35. Minipage example
b e g i n { f i g u r e } [ htbp ]
centering
b e g i n { m i n i p a g e } [ b ] { 5 cm}
centering
i n c l u d e g r a p h i c s { image 1}
c a p t i o n { C a p t i o n 1}
end{ m i n i p a g e }
b e g i n { m i n i p a g e } [ b ] { 5 cm}
centering
i n c l u d e g r a p h i c s { image 2}
c a p t i o n { C a p t i o n 2}
end{ m i n i p a g e }
end{ f i g u r e }
37. Minipage Example Two
b e g i n { f i g u r e } [ htbp ]
centering
b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm}
centering
i n c l u d e g r a p h i c s [ s c a l e =.14]{ g r a p h i c s / s c i e n c e
c a p t i o n { S c i e n c e Cat }
end{ m i n i p a g e }
b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm}
centering
i n c l u d e g r a p h i c s [ s c a l e =.23]{ g r a p h i c s / p h y s i c s
c a p t i o n { P h y s i c s Cat }
end{ m i n i p a g e }
b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm}
centering
i n c l u d e g r a p h i c s [ s c a l e =.14]{ g r a p h i c s / s c i e n c e
c a p t i o n { S c i e n c e Cat }
end{ m i n i p a g e }
b e g i n { m i n i p a g e } [ b ] { 3 . 3 cm}
centering
i n c l u d e g r a p h i c s [ s c a l e =.23]{ g r a p h i c s / p h y s i c s
c a p t i o n { P h y s i c s Cat }
end{ m i n i p a g e }
end{ f i g u r e }
cat }
cat }
cat }
cat }
39. Fonts
Default Font: Computer modern
Default font size: 10pt
How to change the default font:
Additional fonts are available for installation
(http://www.tug.dk/FontCatalogue/)
40. Fonts
Default Font: Computer modern
Default font size: 10pt
How to change the default font:
Additional fonts are available for installation
(http://www.tug.dk/FontCatalogue/)
How to change the default font size:
documentclass command accepts [11pt] and [12pt] as options
fix-cm package overrides font size defaults
special commands
42. Colored text
Use the xcolor package to add color to your text:
usepackage{xcolor}
Use {color{color name} text} to change the text color.
Predefined colors include:
black, white, red, yellow, blue, green, cyan, magenta
47. Wrap figure
To wrap text around a figure use the Wrapfig package:
usepackage{wrapfig}
Wrap the figure in the wrapfigure environment:
begin{wrapfigure}{alignment}{width}...end{wrapfigure}
alignment Either l (left) or r (right)
width Width of image
48. Wrapfig Example
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam
porttitor rutrum felis eget faucibus. Aliquam erat volutpat. Duis
commodo, libero nec adipiscing pellentesque, risus velit faucibus
augue, eget molestie nibh risus et augue.
b e g i n { w r a p f i g u r e }{ l }{40mm}
begin { center }
includegraphics { far side }
end{ c e n t e r }
caption { Einstein }
end{ w r a p f i g u r e }
Integer quis tristique est. Pellentesque lacinia mi mattis ipsum
rutrum egestas. Aliquam vestibulum pharetra felis, in congue eros
posuere ac.
50. Compiling multiple .tex files
As your tex file grows, you may find that it becomes more difficult
to manage (compiling starts to take a long time, it gets hard to
find things, bugs are harder to find, etc.)
The solution: write several files sepearately and compile them
toether at the end. Use the input command to read each “child”
file into your “root” document...
input{child1.tex}
input{child2.tex}
input{child3.tex}
51. Compiling multiple .tex files
The problem with input is that the “child” files won’t compile on
their own. The solution is in the subfile package.
In the ”root” document the package must be loaded as:
usepackage{subfiles}
Instead of using input, ”child” documents must be loaded as
follows:
subfile{child}
The ”child” documents must start with the following statements:
documentclass[rootdocument.tex]{subfiles}
begin{document}
and end with:
end{document}
52. Alternate Output
A
LTEX can directly generate two formats:
dvi Generate using the latex command
pdf Generate using the pdflatex command
dvi supports only the eps image format
pdf supports jpg, png, pdf image formats
53. Converting from DVI to PDF
Directly (dvi → pdf):
Use dvipdfm.
A
There is a special button for this in most LTEXeditors.
54. Converting from DVI to PDF
Directly (dvi → pdf):
Use dvipdfm.
A
There is a special button for this in most LTEXeditors.
Use this if the original file contains postscript figures
55. Converting from DVI to PDF
Directly (dvi → pdf):
Use dvipdfm.
A
There is a special button for this in most LTEXeditors.
Use this if the original file contains postscript figures
Indirectly (dvi → ps → pdf):
Use dvips, then sp2pdf
56. Converting from DVI to PDF
Directly (dvi → pdf):
Use dvipdfm.
A
There is a special button for this in most LTEXeditors.
Use this if the original file contains postscript figures
Indirectly (dvi → ps → pdf):
Use dvips, then sp2pdf
typically ineffecient and can produce larger files of lower
quality
57. HTML output
A
There are several programs for converting LTEX to HTML:
Hyperlatex Actively maintained to keep up with HTML
standards
TTH Good at formula conversion
Heava Good overall, written in O Caml
LaTeX2HTML Not well maintained
text4ht Difficult to configure but produces good output
58. Beamer
It is possible to create sophisticated presentations while
A
harnessing the power of LTEX
The Beamer class produces presentations that:
Can be easily cutomized
Contain overlays
Can display sophisitcated mathematics
Are easily converted to handouts
Compile directly to PDF
59. How to Use Beamer
Use beamer as the document class:
documentclass[style]{beamer}
Go here for examples of Beamer styles:
http://mike.depalatis.net/beamerthemes/
61. Frames
Beamer uses the Frame environment:
begin{frame}[options]...end{frame}
Options include:
fragile allows you to include text using the verbatim or
listings packages on a slide
allowframebreaks allows Beamer to create extra slides to
handle overflow text
shrink shrinks contents to fit on one slide
63. How to Make A Table
A
To make a table in LTEX use the tabular environment:
begin{tabular}...end{tabular}
64. How to Make A Table
A
To make a table in LTEX use the tabular environment:
begin{tabular}...end{tabular}
Separate columns with the ”&” symbol
Separate rows with the double backslash ””
65. Tabular Layout
Specify the column layout when you call tabular:
begin{tabular}{l|l|l}
Vertical bars produce vertical lines between columns.
Alignment Symbols
l - align left
r - align right
c - centered
66. Tables
begin{tabular}{ l | l | l }
Class
& Species & Lays eggs?
mammal & lion
& XSolidBrush
mammal & tiger
& XSolidBrush
mammal & platypus
& Checkmark
reptile & iguana & Checkmark
reptile & snake
& Checkmark
aves & flamingo & Checkmark
end{tabular}
Class
mammal
mammal
mammal
reptile
reptile
aves
Species
lion
tiger
platypus
iguana
snake
flamingo
Lays eggs?
%
%
!
!
!
!
82. Tables
Making tables look good...
D
5in
5in
5in
10in
10in
10in
test
test
test
test
test
test
1
2
3
1
2
3
Pu
285
287
230
430
433
431
lb
lb
lb
lb
lb
lb
σN
38.200 psi
38.27 psi
30.67 psi
248.67 psi
28.8 psi
28.7334 psi
83. Tables
...takes practice.
Table: Maximum load and nominal tension.
D
(in)
Pu
(lbs)
σN
(psi)
5
test 1
test 2
test 3
285
287
230
38.00
38.27
30.67
10
test 1
test 2
test 3
430
433
431
28.67
28.87
28.73
84. Where To Get Help
A
Books - LTEXConcisely by Adrian Johnstone
Online - numerous manuals available
Research Computing Lab www2.lib.virginia.edu/brown/rescomp/
help/index.html