[l2h] ALT tags in equations

Russ Lenth Russ Lenth <rlenth@stat.uiowa.edu>
Fri, 09 Apr 1999 09:29:18 -0500


In my original question, the goal was to replace the ALT attribute in
IMG tags to something more palatable to elementary stat students, who
can't understand TeX markup and who probably don't know how to set
configuration options on their browsers.  

My solution was to write a little script that I can use to post-process
the html file; it is appended.  It simply looks at every IMG tag and
replaces the ALT attribute with the SRC attribute.  The script uses awk.

Russ
-- 
Russell V. Lenth -- Department of Statistics & Actuarial Science      
The University of Iowa -- Iowa City, IA 52242  USA 
Tel (319)335-0814 -- FAX (319)335-3017
mailto:Russell-Lenth@uiowa.edu - http://www.stat.uiowa.edu/~rlenth/


#!/bin/awk -f

# Simple awk script to post-process an HTML file 
# and make the ALT attribute
# the same as the SRC attribute within each <IMG ...> tag
# Russ Lenth, April 8, 1999

/<IMG/ {    # set flag that we're looking at an IMG tag
    isimg = 1
}

/^ SRC/ {    # remember the SRC attribute
    if (isimg) {
        FS = "\""
        src = "\"" $2 "\""
        isimg = 0        # reset the flag - our work is done
    }
}

/^ ALT/ {    # replace the ALT attribute
    multiline = ! match($0, /".*"/)  # don't have "..." in 1 line
    if (!multiline)
        sub (/"[^"]*"/, src)
    else {
        sub (/".*/, src)
        printf("%s", $0)
        do {
            getline                  # look for closing `"'
        } while (!match($0, /"/))
        sub(/[^"]*"/, "")            # erase up through 1st `"'
    }
}

{            # output every line
    print
}