Math on the Web--Class 8

Today's tips

Hard Links and Symbolic Links in UNIX

On the Web page for class 7, we looked at hard links and at symbolic links in UNIX. There would be an obvious advantage to having a symbolic link from the bookmarks.html file, which is in your .netscape directory, into the html directory: the file that your browser saw would always be current.

Contrary to what I said last week the hard link does not seem to serve the purpose of allowing us to browse our current bookmarks file. However, there is also a symbolic link available, and it does work properly.

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. login or SSH to your clam account
  2. cd html
  3. ln ../.mozilla/username/random_dir_name/bookmarks.html bookmarks.html
  4. chmod o+r bookmarks.html
This seems to do essentially the same thing as copying the file, at least during a single session in your account. 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 not see the current version of your bookmarks, however. 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.

Also contrary to what I said last week, you can set the permissions for a symbolic link so that your browser can read your current bookmarks file "through" the link. Here is what you need to do to set up a symbolic link.

  1. login or SSH to your clam account
  2. cd html
  3. ln -s ../.mozilla/username/random_dir_name/bookmarks.html bookmarks.html
  4. chmod o+r bookmarks.html

The interactive mode in LaTeX

The ? prompt

We have seen LaTeX working in its normal mode. Sometimes, though, it is useful to put LaTeX into its interactive mode, and sometimes, LaTeX will put itself into the interactive mode when it comes across an error in the source file. By now, you have seen the prompt ? that LaTeX uses when there is an error in the source file. At the ? prompt you can press RETURN to continue, H for help (sometimes helpful, often mysterious), or X to exit.

The * prompt

If you happen to leave out the end{document} command, then you will find yourself in the interactive mode with the * prompt. You can then type en{document} to exit. However, you can use the * prompt to get information about LaTeX commands by typing \show and then the command name. This is useful if you want to define your own commands and want to check whether a command already has been defined with a given name. To get into the interactive mode, just comment out the end{document} command line by inserting % as the first character of that line. You can exit by typing end{document}.

Goals to accomplish during class

  1. Learn how to create tables in HTML
  2. Learn more about page styles in LaTeX
  3. Learn how to define commands in LaTeX

In-class Activities


Tables in HTML

One way to arrange material on a Web page is to use the TABLE tag. This allows some fairly simple spacing of graphics and text, which are put into cells. Cells are arranged as an array of rows and columns. The table is built out of rows, which are contained the matching <TR> ...</TR> pair. Each individual entry in a row is contained in the <TD> </TD> pair. Let's take an extremely simple example.
<CENTER>
<TABLE ALIGN=RIGHT>
   <tr>
      <td>Upper Left</td>
      <td>Upper Right</td>
   </tr>
   <tr>
      <td>Lower Left</td>
      <td>Lower Right</td>
   </tr>
</TABLE>
</CENTER>
This is displayed as:
Upper Left Upper Right
Lower Left Lower Right
We want a border, so we use the BORDER attribute for the TABLE tag.
<CENTER>
 <TABLE BORDER>
   <tr>
       <td>Upper Left</td>
       <td>Upper Right</td>
   </tr>
   <tr>
       <td>Lower Left</td>
       <td>Lower Right</td>
   </tr>
 </TABLE>
</CENTER>
Here is how it is rendered:

Upper Left Upper Right
Lower Left Lower Right

Here is a table taken from the Rutgers library web-site.

<CENTER><TABLE BORDER=5 WIDTH=450 CELLPADDING=10 CELLSPACING=10>
  <TR>
      <TD ALIGN=MIDDLE><A HREF="general.shtml">
        General Subjects</A><BR></TD>
      <TD ALIGN=MIDDLE><A HREF="arthum.shtml">
        Arts & Humanities</A><BR></TD>
      <TD ALIGN=MIDDLE><A HREF="science.shtml">
        Science, Technology & Medicine</A><BR></TD>
  </TR>
  <TR>
      <TD ALIGN=MIDDLE><A HREF="socsci.shtml">
        Social Sciences, Business & Law</A><BR></TD>
      <TD ALIGN=MIDDLE><A HREF="gov.shtml">
        Government Information</A><BR></TD>
      <TD ALIGN=MIDDLE><A HREF="alpha.shtml">
        Alphabetized list</A> of all indexes<BR></TD> 
  </TR>
</TABLE></CENTER>
You can view the Rutgers library Subjects Page, which contains the table.

If you view the source HTML for the Subjects Page, you'll notice the use of tables to position graphics. Also notice that the table is captioned by a centered header above it on the Subjects Page.

To make a caption part of the table, after the <TABLE> tag, add the pair of tags <CAPTION>...</CAPTION>. For instance,

<CENTER>
<TABLE BORDER>
  <CAPTION>A very simple table</CAPTION>
   <tr>
       <td>Upper Left</td>
       <td>Upper Right</td>
   </tr>
   <tr>
       <td>Lower Left</td>
       <td>Lower Right</td>
   </tr>
</TABLE>
</CENTER>
Here's how it is rendered:

This is a very simple table
Upper Left Upper Right
Lower Left Lower Right

You can also choose to put the caption at the bottom of the table by using the attribute ALIGN with the value BOTTOM inside the caption start tag.

Of course, you need to put labels on the columns and rows of a table. To label the columns, you put in a header row using the tag pair <th>...</th> for each entry. For the table above, we would need a new row at the top. It should have 3 entries, (perhaps with the first entry left blank) because the rows are also going to need labels, which requires a new entry in each row.


EXERCISE:In your test page, put an HTML version of the table
<-- http://crab.rutgers.edu/~karel/math-on-web/class3/lesson3/small-table.gif -->

that we used in the third class as a LaTeX exercise. Try to get the alignment of material in the cells to match the picture. You may want to adjust the minimum space used between the cell boundary and the text inside. This is done with the CELLPADDING attribute, whose argument is always given in pixels.



Continue with LaTeX

Pagestyles in LaTeX

We have seen how to make minor changes to the page style of your LaTeX document. Namely, the commands \pagestyle and \thispagestyle can be used to change the header and footer, and the \pagenumbering{style} command can be used to select a display style for the page numbers. However, there are further changes that you can make to your page style.

For example, you can use the command \setlength to adjust various page parameters. For example, to make a very narrow page, you might use the command

\setlength{\textwidth}{3in}
This goes in the preamble. That is, it goes somewhere between the \documentclass command and the begin{document} command. Note that the first argument is actually a command name. You'll get an error message if you try
\setlength{textwidth}{3in}

Exercise: Set the first paragraph of Alice in Wonderland as a 3 inch wide column in LaTeX.

Some useful length commands are \parindent (the amount of horizontal white space used to indent a paragraph), \hangindent (the amount of horizontal white space used to indent all but the first line of a paragraph -- use with noindent at the beginning of each paragraph), and \parskip (the amount of extra vertical white space inserted between paragraphs.

The units can be specified as in (inches), pt (points: 72.27pt = 1in), pc (pica: 1pc = 12pt), mm (millimeters), which are absolute measurements, and also as the relative units em and ex, which are roughly the widths of the letters M and x, respectively, in the current font.


Custom commands in LaTeX

You can make the job of typing a LaTeX document easier if you add some of your own commands to the large number of pre-defined commands. For example, you can introduce commands to abbreviate longer commands. To abbreviate the command \begin{equation} to just \be you type
\newcommand{\be}{\begin{equation}}
Then, to put LaTeX into the equation environment, you can just type \be.

If a command already exists with the name you have chosen, LaTeX will give you an error message. You can insist on your own version by substituting \renewcommand for \newcommand. I do not recommend this, since you may want to use a package that makes some use of the original version of the command, and then you will most likely get some puzzling error messages.

At least, if you want to redefine a command, you should check what the current definition is. To do this you go into interactive mode. Then you can type
\show \commandname. Try this with the command \vec. You should see that \vec is a math accent. You could redefine it without much danger. However, some commands are "primitive" TeX commands. They should not be redefined. An example is \hangafter. Try showing it! You can also type the \show \commandname command into your document itself, and get the information in the log file and on the monitor.

The real power of commands comes when you use arguments with them. Here is an example taken from Grätzer's book Math into LaTeX.

\newcommand{\Sum}[2][n]{#2_{1}+#2_{2}+\cdots+#2_{#1}}
The first argument is optional, and the second argument is not.

EXERCISE: To understand what this command does, create a LaTeX file and try out the following:

  1. $\Sum{x}$
  2. $\Sum{t}$
  3. $\Sum[i]{a}$


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. Continue to explore a mathematical topic, with a view to using what you find as part of a project
  2. Revise your list of links to 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 Monday, March 2) Continue writing your short paper in LaTeX designed to teach a first year student the how and why of completing the square.
  4. As an exercise for LaTeX custom command definitions, try typesetting the monster equation below from Michael Spivak's book, The Joy of TeX. You should be able to save a lot of effort by using your own commands to typeset parts of the equation. Amaze your friends by seeing how short (in terms of bytes) your source code can be!
    You'll need the align environment, and to get the fractions correctly sized in the numerator, you can use the command \displayfrac instead of \frac.


/ Home / Contents /


email to:Martin Karel