[comp.text.tex] listoffigures question/problem

art@maccs.dcss.mcmaster.ca (Art Mulder) (07/23/90)

Hello all,
  I trying to get \listoffigures to work and am having some difficulty.

I have some simple macro's:
|  \newcommand{\un}{\underline}
|  \newcommand{\pth}[1]{\un{path} \; #1 \; \un{end}}

used in a caption of a figure as follows:
|  \caption{Labelled sm net intuitively corresponding to $\pth{a;a}$
|           \label{fig:227}}

which puts the following into my .lof file:
[originally this was all one line, I have inserted line breaks]
|  \contentsline {figure}{\numberline {2.30}{\ignorespaces Labelled
|  sm net intuitively corresponding to $\relax $\@@underline {\hbox
|  {path}}$\relax \mskip \thickmuskip a;a \mskip \thickmuskip \relax
|  $\@@underline {\hbox {end}}$\relax $ }}{81}

when I run the file through latex for the second time (to get the 
cross references right) I get this error:
|  ! Missing $ inserted
|  < inserted text>
|		   $
|  ...
|  l.32 ...$\@@underline {\hbox{path}}$\relax $ }}{81}

It appears that latex is putting extra begin-math-mode end-math-mode dollar
signs around the text that is underlined in the caption!  This occurs in
several captions that I have, all with regards to underlining.  When I
manually take out the extra dollar signs, latex works.

Now I can keep doing this, but there are about 10-15 instances of
underlining in captions, and ever time I process the book I have to manually
correct them, and it is a pain.

Am I doing something wrong?  Can anyone suggest a way for me to work around
this?  Any help is appreciated.  Please email to me and I will post the
solution if there is one.

-- 
-----------
Art Mulder,                                      art@maccs.DCSS.mcmaster.ca
                                             ...!uunet!utai!utgpu!maccs!art

dhosek@sif.claremont.edu (Hosek, Donald A.) (07/25/90)

In article <26AB19EC.17589@maccs.dcss.mcmaster.ca>, art@maccs.dcss.mcmaster.ca (Art Mulder) writes...

>Hello all,
>  I trying to get \listoffigures to work and am having some difficulty.

>I have some simple macro's:
>|  \newcommand{\un}{\underline}
>|  \newcommand{\pth}[1]{\un{path} \; #1 \; \un{end}}

>used in a caption of a figure as follows:
>|  \caption{Labelled sm net intuitively corresponding to $\pth{a;a}$
>|           \label{fig:227}}

>which puts the following into my .lof file:
>[originally this was all one line, I have inserted line breaks]
>|  \contentsline {figure}{\numberline {2.30}{\ignorespaces Labelled
>|  sm net intuitively corresponding to $\relax $\@@underline {\hbox
>|  {path}}$\relax \mskip \thickmuskip a;a \mskip \thickmuskip \relax
>|  $\@@underline {\hbox {end}}$\relax $ }}{81}

p. 51 of the LaTeX book:

  The \underline command is fragile

Hmm... let's look up fragile in the index. pp. 151-2:

  Certain command arguments are called moving arguments. A
  fragile command that appears in a moving argument must be
  preceded by a \protect command... The following are all the
  commands and environments with moving arguments:

  o Commands with an argument that may be put into a table of
    contents, list of figures, or list of tables:
    \addcontentslne, \addtocontents, \caption, and the sectioning
    commands.

Hmm, that means \underline is fragile, \caption has a moving
argument, and we need to put \protect before \underline.

Changing the definition of \un to:

\newcommand{\un}{\protect\underline}

will do the trick.

Homework: What happens if \protect is used outside of a moving
argument? Cite the LaTeX manual to back up your assertion.

-dh

---
Don Hosek                         TeX, LaTeX, and Metafont Consulting and
dhosek@ymir.claremont.edu         production work. Free Estimates.
dhosek@ymir.bitnet                
uunet!jarthur!ymir                Phone: 714-625-0147

jwright@cfht.hawaii.edu (Jim Wright) (07/25/90)

dhosek@sif.claremont.edu (Hosek, Donald A.) writes:
>Homework: What happens if \protect is used outside of a moving
>argument? Cite the LaTeX manual to back up your assertion.

p.24
	Except in special cases mentioned in Chapter 5 and Appendix C,
	a \protect command can't hurt, so it is almost always safe to
	use one when you're not sure if it's necessary.
p.152
	All length commands are robust and must not be preceded by \protect.
	A \protect command should not be used in an argument of a \setcounter
	or \addtocounter commmand.

--
Jim Wright
jwright@quonset.cfht.hawaii.edu
Canada-France-Hawaii Telescope Corp.