Introduction to Scientific Typesetting
Lesson 12: Verbatim Text
and Drawing in LATEX
Ryan Higginbottom
January 20, 2012
1
An Overview
An Overview
Verbatim Text
Verbatim Text
The Basics of The Basics of pstricks
pstricks
Color
Color
2
An Overview
Verbatim Text
Writing About LATEX (or
other code)
Typing Verbatim Text
Inline
Rules for Verbatim Text
Inline
Displayed Verbatim
Text
Rules for the
Verbatim Text
verbatim
Environment
Example
Verbatim Text in
Presentations
The Basics of
pstricks
Color
3
Writing About LATEX (or other code)
An Overview
If you are writing about LATEX or any other code within your
Verbatim Text
Writing About LATEX (or
document, chances are you’ll want to include some examples of
other code)
Typing Verbatim Text
that code.
Inline
Rules for Verbatim Text
Inline
Displayed Verbatim The problem is: how do you allow your reader see exactly what
Text
Rules for the
you’re typing? Most of the time this is difficult to do.
verbatim
Environment
Example
Verbatim Text in
This is known as the problem of typing verbatim text.
Presentations
The Basics of
pstricks
Color
This section relies heavily on pages 145–148 of More Math into
LATEX.
4
Typing Verbatim Text Inline
An Overview
The command \verb allows you to type verbatim text inline. The
Verbatim Text
Writing About LATEX (or
character that comes directly after \verb is a delimiter, so you
other code)
Typing Verbatim Text
need to type that character again after the verbatim text is done.
Inline
Rules for Verbatim Text
Inline
Displayed Verbatim
Type: It is not hard to type \verb+\%+
Text Get: It is not hard to type \%
Rules for the
verbatim
Environment
Example Choose your delimiter carefully! The delimiter cannot appear in the
Verbatim Text in
Presentations verbatim text itself without causing problems!
The Basics of
pstricks
If you want to have 2+2=4 show up in verbatim, you cannot use +
Color
as your delimiter! Use !, |, - or something else.
\verb!2+2=4!
5
Rules for Verbatim Text Inline
An Overview
Some rules to follow when using \verb:
Verbatim Text
Writing About LATEX (or
other code)
The entire \verb command must be typed on a single line in
Typing Verbatim Text your .tex file.
Inline
Rules for Verbatim Text
Inline You cannot have a space between \verb and your delimiter.
Displayed Verbatim
Text
Rules for the The \verb command cannot appear in the argument of
verbatim
Environment another command.
Example
Verbatim Text in
Presentations
The \verb command cannot appear in an aligned math
The Basics of environment.
pstricks
Color Do not use * as a delimiter.
6
Displayed Verbatim Text
An Overview
If you have a lot of verbatim text to type at once, use the verbatim
Verbatim Text
Writing About LATEX (or
environment.
other code)
Typing Verbatim Text
Inline
Rules for Verbatim Text
Inline
\begin{verbatim}
Displayed Verbatim
Text
verbatim text goes in here
Rules for the \end{verbatim}
verbatim
Environment
Example
Verbatim Text in
It is not necessary, but I believe you will get better behavior from this
Presentations
environment by including \usepackage{verbatim} in your
The Basics of
pstricks preamble.
Color
7
Rules for the verbatim Environment
An Overview
Some rules to follow:
Verbatim Text
Writing About LATEX (or A verbatim environment cannot be placed within another
other code)
Typing Verbatim Text verbatim environment.
Inline
Rules for Verbatim Text
Inline A verbatim environment cannot be placed within the
Displayed Verbatim
Text argument of another command.
Rules for the
verbatim
Environment You must have \end{verbatim} on a line by itself, with no
Example
spaces before it.
Verbatim Text in
Presentations
The Basics of
pstricks There are a few other packages which can be used to typeset
Color
verbatim text: alltt, listings, and fancyvrb. Look into them if
you like. (I use fancyvrb in my slides.)
8
Example
An Overview
Open the first example file (.tex), build and view.
Verbatim Text
Writing About LATEX (or
other code)
Typing Verbatim Text
Inline
Rules for Verbatim Text
Inline
Displayed Verbatim
Text
Rules for the
verbatim
Environment
Example
Verbatim Text in
Presentations
The Basics of
pstricks
Color
9
Verbatim Text in Presentations
An Overview
You will need to make a small adjustment if you’d like to have a slide
Verbatim Text
Writing About LATEX (or
with verbatim text within a presentation.
other code)
Typing Verbatim Text If you are using beamer, you’ll need the [fragile] option on
Inline
Rules for Verbatim Text any frame with verbatim text. That is, you’ll need:
Inline
Displayed Verbatim
Text \begin{frame}[fragile]
Rules for the
verbatim slide contents with verbatim text
Environment
Example
\end{frame}
Verbatim Text in
Presentations
If you are using powerdot, you’ll need the method=file
The Basics of
pstricks option on any slide with verbatim text. That is, you’ll need:
Color
\begin{slide}[method=file]{Title}
slide contents with verbatim text
\end{slide}
10
An Overview
Verbatim Text
The Basics of
pstricks
The Motivation
Getting Started
Basic Graphical
Objects
Curves and Rounding The Basics of pstricks
Example
Modifications
Arrows
Grids
Options for Grids
Framed Boxes
Options for Framed
Boxes
Example
Using psset
Placing Objects and
Text
Practice
Color
11
The Motivation
An Overview
It is very inconvenient to have to include a graphic every time you’d
Verbatim Text
like a picture in your document or presentation. Additionally, if you
The Basics of
pstricks are sharing a file with someone else, this means that you’ll have to
The Motivation
send along the picture file(s) too. It’s much more convenient to use
Getting Started
Basic Graphical a package where LATEX code generates your pictures for you.
Objects
Curves and Rounding
Example Enter pstricks!
Modifications
Arrows
Grids
Because
Options for Grids
Framed Boxes
Options for Framed
Boxes Graphics can spice things up!
Example
Using psset
Placing Objects and
Text You’ll need \usepackage{pstricks} in the preamble.
Practice
Color
12
Getting Started
An Overview
While pstricks commands can be used within the flow of text, it is
Verbatim Text
more common to draw pictures that are set off by themselves. This
The Basics of
pstricks happens within a pspicture environment.
The Motivation
Getting Started
Basic Graphical You need to specify the dimensions of the environment. (One unit is
Objects
Curves and Rounding
1 cm by default.) This happens by specifying the lower left and
Example upper right coordinates of the environment. (Think of it as a grid!)
Modifications
Arrows
Grids \begin{center}
Options for Grids
\begin{pspicture}(0,0)(4,4)
Framed Boxes
Options for Framed ...
Boxes
Example
\end{pspicture}
Using psset \end{center}
Placing Objects and
Text
Practice
Color
13
Basic Graphical Objects
An Overview
Here are some pstricks commands for simple geometric objects.
Verbatim Text
The Basics of \psline(0,0)(2,1) — A line starting at (0, 0) and ending at
pstricks
The Motivation
(2, 1). Also valid: \psline(0,0)(2,1)(3,4).
Getting Started
Basic Graphical \psframe(0,0)(3,2) — A rectangle with corners at (0, 0),
Objects
Curves and Rounding
(3, 0), (3, 2), and (0, 2).
Example
Modifications
\pspolygon(0,0)(3,1)(1,2) — A triangle with vertices at
Arrows (0, 0), (3, 1), and (1, 2). A polygon can have any number of
Grids
vertices and pstricks will close up the polygon properly.
Options for Grids
Framed Boxes Order matters!
Options for Framed
Boxes
Example
\pscircle(1,2){.5} — A circle with radius 0.5 cm centered
Using psset at (1, 2).
Placing Objects and
Text
Practice
\psellipse(0,0)(2,3) — An ellipse centered at (0, 0) with
Color
horizontal radius 2 cm and vertical radius 3 cm.
14
Curves and Rounding
An Overview
There are two versions of a curve to mention.
Verbatim Text
The Basics of \pscurve(0,0)(.5,0)(1,3)(-1,4) — This interpolates a
pstricks
The Motivation
curve through the points specified. (The showpoints=true
Getting Started option can help you adjust things here.)
Basic Graphical
Objects
Curves and Rounding
\psccurve(0,0)(.5,0)(1,3)(-1,4) — This interpolates
Example a closed curve through the points.
Modifications
Arrows The linearc option:
Grids
For \psline and \pspolygon, the linearc option rounds the
Options for Grids
Framed Boxes
corners of your objects (default is 0pt):
Options for Framed
Boxes
Example
Using psset
Placing Objects and
linearc=8pt
Text
Practice
Color
15
Example
An Overview
Open the second example file (.tex).
Verbatim Text
The Basics of
pstricks
The Motivation Make sure your Build Profile is LaTeX => PS => PDF.
Getting Started
Basic Graphical
Objects
Curves and Rounding
Build and view.
Example
Modifications
Arrows
Grids
Options for Grids
Framed Boxes
Options for Framed
Boxes
Example
Using psset
Placing Objects and
Text
Practice
Color
16
Modifications
An Overview
There are some easy ways to modify these basic commands.
Verbatim Text
These are optional arguments.
The Basics of
pstricks
The Motivation
linewidth=1.5pt — changes the thickness of the lines you
Getting Started draw; default is 0.8 pt;
Basic Graphical
Objects
Curves and Rounding
linecolor=red — changes the color of your line; default is
Example black;
Modifications
Arrows fillstyle=solid, fillcolor=blue — applies to objects
Grids
that can be filled; default fillstyle is none; you must specify
Options for Grids
Framed Boxes a fillcolor when you want a solid fillstyle; see posted
Options for Framed
Boxes document for fillstyles and linestyles
Example
Using psset \pscircle*(0,0){1} — all graphics objects have a starred
Placing Objects and
Text version which draws a solid object of color linecolor
Practice
Color
17
Arrows
An Overview
On any line or curve you can draw arrows, and pstricks has a lot
Verbatim Text
of options for arrowhead styles. (See posted document.) These are
The Basics of
pstricks given with the arrows option. Here are a few:
The Motivation
Getting Started
Basic Graphical
Objects
arrows=<->
Curves and Rounding
Example
arrows=*-o
Modifications
Arrows
Grids arrows=<<-<
Options for Grids
Framed Boxes
Options for Framed
Boxes
arrows=|->|
Example
Using psset
Placing Objects and
Text
Practice
Color
18
Grids
An Overview
A powerful way to make grids:
Verbatim Text
The Basics of
\psgrid(x0,y0)(x1,y1)(x2,y2) — draws a grid with
pstricks
opposing corners at (x1, y1) and (x2, y2); the numbering starts at
The Motivation
Getting Started (x0, y0).
Basic Graphical
Objects
3
Curves and Rounding
2
Example
Modifications 1
Arrows
Grids
0
Options for Grids 0 1 2 3 4 5 6 7 8
Framed Boxes
Options for Framed \begin{center}
Boxes
Example \begin{pspicture}(0,0)(8,3)
Using psset \psgrid(0,0)(0,0)(8,3)
Placing Objects and
Text \end{pspicture}
Practice
\end{center}
Color
19
Options for Grids
An Overview
Here are some ways to change grids.
Verbatim Text
The Basics of Option Default
pstricks
The Motivation
gridcolor black
Getting Started gridlabels 10 pt
Basic Graphical
Objects subgriddiv 5
Curves and Rounding
Example
The unit dimensions affect psgrid a great deal, but they affect
Modifications
Arrows everything else too. The default unit is 1 cm, but this can all be
Grids
changed.
Options for Grids
Framed Boxes xunit horizontal units
Options for Framed
Boxes yunit vertical units
Example
runit radial units
Using psset
Placing Objects and unit changes all 3 at once
Text
Practice
Example:
Color
\psgrid[unit=1in,gridlabels=8pt,
subgriddiv=8](0,0)(0,0)(8,4)
20
Framed Boxes
An Overview
There are a number of options for framing text:
Verbatim Text
The Basics of \psframebox — draws a simple box around your text; the
pstricks
The Motivation
*-version is filled with fillcolor rather than linecolor as in
Getting Started geometric objects;
Basic Graphical
Objects
Curves and Rounding
\psdblframebox — draws a double frame ;
Example
Modifications \psshadowbox — draws a single frame with a shadow ;
Arrows
Grids
Options for Grids
Framed Boxes
\pscirclebox — draws a circle around your text;
Options for Framed
Boxes
Example
\psovalbox — draws an oval around your text.
Using psset
Placing Objects and
Text
Practice
Color
21
Options for Framed Boxes
An Overview
Here are some options you might want to use:
Verbatim Text
The Basics of framesep — distance between each side of a frame and
pstricks
The Motivation
what’s inside; default is 3pt;
Getting Started
Basic Graphical boxsep — true/false; should LATEX space things according to
Objects
Curves and Rounding
the frame or the stuff inside the frame?
Example
Modifications framearc — rounds the corners on \psframebox; this needs
Arrows
to be a number between 0 and 1, higher is more rounded;
Grids
Options for Grids
Framed Boxes
Options for Framed
Example: This is nice text .
Boxes
Example
\psframebox[framesep=8pt,framearc=.6]{nice text}.
Using psset
Placing Objects and
Text
Practice
Color
22
Example
An Overview
Open the third example file (.tex).
Verbatim Text
The Basics of
pstricks
The Motivation
Getting Started Build and view.
Basic Graphical
Objects
Curves and Rounding
Example
Modifications
Arrows
Grids
Options for Grids
Framed Boxes
Options for Framed
Boxes
Example
Using psset
Placing Objects and
Text
Practice
Color
23
Using psset
An Overview
If you want your lines to be 2pt thick throughout your document, it is
Verbatim Text
going to be a pain for you to type
The Basics of
pstricks
The Motivation linewidth=2pt
Getting Started
Basic Graphical
Objects on every object you draw. Instead, type
Curves and Rounding
Example
\psset{linewidth=2pt}
Modifications
Arrows
Grids
before your pspicture environment and this sets the option
Options for Grids globally.
Framed Boxes
Options for Framed
Boxes
Example:
Example \psset{unit=.5cm,linewidth=1pt,linecolor=blue}
Using psset
Placing Objects and
Text
Practice
Color
24
Placing Objects and Text
An Overview
Inside a pspicture environment, graphics objects are drawn, but
Verbatim Text
text needs to be placed. This is done using these two main
The Basics of
pstricks commands:
The Motivation
Getting Started \rput*[refpoint]{rot}(x,y){stuff}
Basic Graphical
Objects
refpoint is the center of the box by default, but it could be
Curves and Rounding
Example
l, r, t, b, or a combination like lt.
Modifications
Arrows
\uput*{labelsep}[refangle]{rot}(x,y){stuff} —
Grids This places stuff a distance labelsep from (x, y) in the direction
Options for Grids
refangle. It is useful for labeling things.
Framed Boxes
Options for Framed
Boxes
a leg
Example
\pspolygon(0,0)(1,0)(0,1)
Using psset
Placing Objects and \rput{90}(-.2,.5){a leg}
Text
Practice
Color
25
Practice
An Overview
Let’s practice!
Verbatim Text
The Basics of Open the fourth example file (.pdf) and reproduce it.
pstricks
The Motivation
Getting Started
Basic Graphical
Objects
Curves and Rounding
You only need to reproduce the objects/text in the grid. (But you do
Example not need to reproduce the grid itself or the text below the grid.)
Modifications
Arrows
Grids
Options for Grids
Framed Boxes
Options for Framed
Boxes
Example
Using psset
Placing Objects and
Text
Practice
Color
26
An Overview
Verbatim Text
The Basics of
pstricks
Color
The Default Colors
Defining New Colors
Matching Colors Color
An Example
Practice
27
The Default Colors
An Overview
The pstricks package recognizes 11 colors by name:
Verbatim Text
The Basics of
pstricks
black darkgray gray lightgray
Color
white red green blue
The Default Colors cyan magenta yellow
Defining New Colors
Matching Colors
So in addition to using this to color pstricks objects
An Example
Practice (fillcolor=green), you can use this to color text if you like.
...use this to \textcolor{red}{color text} if...
There are several methods available to define new colors; we’ll
focus on two of them.
grayscale colors
RGB colors
28
Defining New Colors
An Overview
Here are the two methods.
Verbatim Text
The Basics of \newgray{color}{num} — This gives the name color to the
pstricks
gray created. num needs to be a number between 0 (black) and
Color
The Default Colors
1 (white).
Defining New Colors Example: .33
Matching Colors
An Example
Practice \newrgbcolor{color}{num1 num2 num3} — This gives
the name color to the color resulting from num1 red, num2
green, and num3 blue. These should all be numbers between 0
and 1.
Example: .5 0 .5
29
Matching Colors
An Overview
What do you do if you want to match a nice color you’ve found
Verbatim Text
somewhere?
The Basics of
pstricks
1. Find an image of it somewhere. If it’s a web page, PrintScreen,
Color
The Default Colors
open Paint, and Paste.
Defining New Colors 2. Open the image in MSPaint. (This is a really low-budget image
Matching Colors
editor; nicer ones have this function and more.)
An Example
Practice 3. Choose the eye-dropper tool and click on the area of the picture
that has the color you want.
4. Go to the menu Colors, then Edit Colors, then click on Define
Custom Colors.
5. Your desired color should be selected and its RGB values are
listed.
6. To use in pstricks, divide each RGB value by 255 to get the
proper decimal.
30
An Example
An Overview
Suppose I want to capture the color maroon in the W&J logo. (See
Verbatim Text
posted image file.)
The Basics of
pstricks
Color We find:
The Default Colors
Defining New Colors
Red 178
Matching Colors
An Example
Green 41
Practice Blue 27
\newrgbcolor{wjred}{.698 .16 .106}
Now I can type in this color or draw a circle filled with this color!
31
Practice
An Overview
Let’s practice!
Verbatim Text
The Basics of Open the fifth example file (.pdf) and reproduce it.
pstricks
Color
The Default Colors
Defining New Colors
Matching Colors
An Example
Practice
32