MATH on the WEB: Class 7:
Images in HTML, and more about LaTeX

Today's tips

Hard Links in UNIX

Recall that we looked at the problem of getting to our Netscape bookmarks file when we are using a browser on a machine other than the one where we have our home account. Since we have switched to the Mozilla Firefox browser, that material needs to be rewritten. To keep robotic agents from recovering our bookmark files, Mozilla puts its bookmarks into a randomly labelled directory. For example, vczjmrat.slt/. If you look into your .mozilla directory by using
clam% ls -al .mozilla/[username]/[vczjmrat.slt]/
where you put replace [username] with your own clam username and replace vczjmrat.slt with the filename that mozilla has assigned in your directory .mozilla, then you will find an interesting collection of files, including an ldap file (LDAP stands for Lightweight Directory Assistance Protocol, and is used to retrieve such information as email addresses), and a file bookmarks.html. The latter file, as you would guess from the extension .html, is a text file written (by the Mozilla browser, Firefox). It contains your bookmarks.

For illustrating the main idea, let's assume that you want to use your clam Firefox bookmarks from the comfort of your home.

Previously we made a copy of our Netscape bookmarks file and put it in a directory where it could be read by any browser that we happened to be using: html on our UNIX network's clam server. One obvious problem with making a copy of your .mozilla/[username]/[vc****.slt]/bookmarks.html file to be viewed by your browser is that your copy is not going to reflect any later changes that you make to your original bookmarks file .mozilla/[username]/[vc****.slt]/bookmarks.html. To see the changes you would have to update your copy manually, say by copying the original bookmarks file again.

There would be an obvious advantage to having a hard link from the bookmarks.html file, which is in your .mozilla/vc****.slt directory, into your public browsing directory html on clam. When you use a machine off-campus, your browser could always show your current clam Mozilla bookmarks file in addition to your browser's own bookmarks file.

The hard link is set up by using the ln command. The syntax is

ln source-path/[file] link-path/[link].

For example, instead of making a copy of your bookmark file, you can create a hard link, as follows:

  1. either login or SSH to your clam account
  2. type cd html
  3. type ln ../.mozilla/[username]/[random-name]/bookmarks.html bookmarks.html
  4. chmod o+r bookmarks.html
Now, if you type more bookmarks.html while you are in the directory html/, then you can read the bookmarks file. A Web browser can also read your bookmarks file "through" the link. It does see the current version of your bookmarks. You can try this out by making a text file, say test.txt, and a hard link to it, say test-link.txt. Change the test.txt file and then read the link, test-link.txt.

Symbolic Links in UNIX

UNIX allows the user to create symbolic links to files so that the file can be used conveniently from more than one directory. For example, if you have a file deeply buried several directory levels below your root directory, you could create a symbolic link to work on the buried file.

The symbolic link is set up by using the ln command with the -s option and the syntax:

ln -s source-path link-path/.

WARNING: You would think that you could use a symbolic link in your html directory to your Netscape browser's bookmark file. Then you could always access your bookmark file easily even though you were using a browser on a different computer. However, this does not seem to work, because of problems with setting permissions.

For example, instead of making a copy of your bookmark file, we could have created a symbolic link, as follows:

  1. login or telnet to your clam account
  2. cd html
  3. ln -s ../.mozilla/[username]/[randomname]/bookmarks.html bookmarks.html
  4. chmod o+r bookmarks.html
Now, if you type more bookmarks.html while you are in the directory html/, then you can read the bookmarks file.

However, the resulting link does not actually give read permission to "others", even if we change the permissions for the directories .mozilla and so on along the path, and for the file bookmarks.html, so the link does not seem to be useful for remotely viewing our Mozilla bookmarks file.

Converting Documents and Graphics Files

If you are unable to convert a graphics file from one format to another on the machine or network where you happen to be, there is a way to do many conversions at Carnedgie-Mellon's TOM Conversion Service. (TOM stands for Teachers of Mathematics). For example, this service can be used to convert PostScript files into either GIF or JPEG files. It will also convert between various document formats.

Goals to accomplish during class

  1. Increase your familiarity with HTML
  2. Learn about page styles in LaTeX
  3. Learn about macros in LaTeX

In-class Activities

More about HTML


Controlling line breaks

The browser simply ignores the carriage returns that we put in a document. Instead, the text is allowed to flow from the left margin of the browser window to the right margin. Line breaks can be forced by using the <BR> tag, as we have seen.

Sometimes, however, you may prefer that some words or fragments of text be kept together on a single line. For example, if you refer to somebody as J. Beard, then you probably would rather not see it displayed as J.
Beard.

To keep text on a single line, you can use the "no break" tag. For example:
<nobr>This text is going to be kept on a single line.</nobr> As an exercise, create a small HTML document with the title "Test Page" and link it to your very basic home page. Include the following in your new page and view the page with a Web browser:

<nobr>This is sure a lot of text to keep on a single line, but it might
be interesting to see what happens if we just keep typing on and on and on ...
</nobr>

For keeping just two words or text fragments together, Netscape has introduced the character entity &nbsp;, the "nobreak space". It is a proposed standard according to Musciano and Kennedy; however, it does seem to be used commonly now in commercial Web pages.

Specifying image dimensions

The folks at W3C recommend that every in-line image in a Web page have its dimensions (that is its height and width) specified. You can do that by using the two attributes, height and width inside the IMG tag. The values of the height and width are supposed to be integers that specify the respective dimensions in pixels.

On the one hand, specifying dimensions should speed the loading of the page, since the Web browser otherwise has to determine the dimensions of the image before it can start rendering the page. On the other hand, specifying dimensions of the displayed image gives you extra control over the displayed image independent of its natural dimensions. WARNING: if the dimensions you specify are not proportional to the dimensions of the original image, the result will be a distorted display. For example, compare the natural-sized image

with the image

One trick that can be used to good effect is to create a rectangular box and fill it with a given color by letting the SRC attribute have as its value the URL of a very small image. For example, if we have an image that has height of 1 pixel and width of 1 pixel, then

     <img src="single-pixel.gif" height=3 width=640>
should create a horizontal rule in the given color. This can save network bandwith. It could also save you the effort of creating new image files for various shaped horizontal rules. EXERCISE: Test this out by creating a horizontal rule with some one color by using the above idea. Part of the exercise is to find a an image and to get a single pixel GIF file from it by using the available tools. You could start by downloading an image from the Web and then checking the SGI man pages for imgview and imgworks. Put the image on your test page or home page.

Using images as link contents

Each pair of anchor tags, <A>... </A> creates a container. We refer to the contents of this container as link contents. Thus far, we have used only text as link contents. However, it is easy to use an image as the contents of a link. Here is an example:
 
<A
HREF="http://www.rutgers.edu/"> <IMG
SRC="http://www.rutgers.edu/images/header.gif"  WIDTH=288 HEIGHT=144 ALT="Rutgers
header">  </A>  
The resulting link looks like this:

Rutgers header

The image has both its height and width reduced by half.

Notice the border, which most browsers put around the image to indicate that it is actually a link. You can control the thickness of the border. Use the border attribute in the IMG tag. The border is normally 2 pixels thick. The value of the border attribute should be the number of pixels thickness that you want. For example,

<A HREF="http://www.rutgers.edu/"> <IMG
SRC="http://www.rutgers.edu/images/header.gif" WIDTH=288 HEIGHT=144  ALT="Rutgers header" BORDER=8 ></A>
will produce the following link image:

Rutgers header

You can eliminate the border by using BORDER=0 in the IMG tag. By the way, you may have observed that the Rutgers header.gif has the property that the background shows through the image: the header.gif is a so-called clear GIF. Without the border, it isn't so obvious where the image boundaries are, so if you eliminate the border, which the browser provides to show that the image is a link, then you should put in some text to inform the gentle reader that the image is a link.

The allowable content of a link container are pretty simple: text, breaks, images and headings. If you want your link contents to be in a different font, you just put the anchor into another container that will change the font.

EXERCISE In your very basic homepage (or in your test page), please put a link with the link contents given by an image. Note: in case you would prefer something other than the header.gif, there are loads of small icon-type images on the Web which can be used.



Continue with LaTeX

Pagestyles in LaTeX

You may want to change the page style of your LaTeX document. This can be done with the commands \pagestyle and \thispagestyle. The command \pagestyle changes the page style of the current page and and of all subsequent pages, whereas the command \thispagestyle changes only the page style of the current page.

The standard LaTeX page styles are:

empty
Both the header and footer are empty
plain
The header is empty and the footer contains the page number
headings
The header contains information determined by the document class and the page number; the footer is empty
myheadings
Similar to headings, but the user controls the header

you can use the \pagenumbering{style} command to select a display style for the page numbers. The default style is arabic, but for an introduction you might want to use roman, which gives i, ii, iii, iv, and so on. Also available are Roman, Alph and alph. It is easy to guess what they do>

To get a page break, use the command \clearpage.

LaTeX Cross references

One of the most useful features of LaTeX is its easy-to-use cross reference system. To allow cross-references to some element of your document, you can assign the element a "key" given by a "key-string", which is a string that can consist of letters, digits and punctuation. That key-string can later be referred to generate a cross-reference elsewhere to the original element. The elements that are commonly labelled are equations, sections and subsections (etc.), figures and tables.

Here is an example of an equation with a label and a reference to the equation. This is taken from Section 4.2 of LaTeX, a Document Preparation System by Leslie Lamport, ©1994, 1985 by Addison-Wesley.


Equation~\ref{eq:euler}
Section~\ref{sec-early} below
...
\subsection{Early Results}
\label{sec-early}
Euler's equation
\begin{equation}
  e^{i\pi}+1 = 0 \label{eq:euler}
\end{equation}
combines the five most important numbers in mathematics in a single 
equation.

The results, depending on what numbering scheme was chosen in the document preamble, might look as follows:

LaTeX reference typeset

Finished?

If you have done all the above activities, and there is still time left, here are some other activities you can do.

Homework for after class

You should have time to start on these during class.

  1. Explore any mathematical topic that interests you, with a view to using what you can find out about it as part of a project
  2. Keep a list of links to any mathematical sites that you think are worth revisiting. Include the list of links either on your very basic Web page or as a separate document linked to that Web page.
  3. For Wednesday, November 10, write a short paper in LaTeX designed to teach a first year student the how and why of completing the square. There are many Web pages that deal with this, but most are not impressive, and a few actually have mistakes in them. The paper should be one-and-a-half to two pages in length, or so. Make sure that you have at least three numbered equations in your paper, and that you have at least two cross references to your equations (so these will need labels). I hope that you will also use the sectioning command.

/ Home / Contents /


email to:Martin Karel