CS 2204 Lab 12

Your name here (please print):

Your student ID number here:

    In this lab you will hone your LaTex skills to perfection.

  1. (1 point) Download this file UNIX.ps and open it by gv UNIX.ps . If this does not work, open UNIX.pdf using acroread or xpdf . Ok
  2. (An automatic A+ in this class ) Completely on your own create a LaTex code to reproduce the above. Just kidding. haha
  3. (2 points) Can you change "UNIX" into "CSVT" in the above picture? Here is the LaTex source: UNIX.tex " Make the PDF. Literally just change the letters UNIX to CSVT on line 61
  4. (7 points) Now let's do something useful. Create a gawk script stat.awk that does the following. It takes a set of numbers as input and produces different averages of these numbers. It makes a LaTex input file that can then be converted into a PDF file to show these averages inside a nice looking table. You will compute the simple arithmetic average: (Sum_i data_i)/N . You will also compute this average: sqrt[ (Sum_i data_i*data_i )/N ] where N is the number of data points. Here is a hint on how to begin:
    awk 'BEGIN{ {s=0} {print "\\begin{document}" } {print "\\begin{tabular}" } } { s+= $1 } END {print s/NR }' < data
    
    where the input.data file looks like this:
    12
    13.3
    17.5
    10.11
    0.11
    -6.11
    0.16
    
  5. In the example above the awk line computes the arithmetic average and also outputs parts of the latex code. You will need to extend it. The table should have two columns and two rows. Use the top row to label the numbers computed: use math symbols to define the averages you put in the cells below (that is use a symbol for the square root, for the sum, etc. ). The LaTex -> PDF step (as well as the LaTex compilation itself) can be done on the command line, outside of the script. I suggest you start by figuring out how to make the table you need in Latex. Most of the special math symbols you need (summation, etc) were introduced in the lecture.

    #!/usr/bin/gawk -f
    BEGIN {
      total=0;
      totalsquared=0
      print "\\documentclass{article}"
      print "\\begin{document}";
    }

    { total += $1; totalsquared += ($1 * $1); }

    END {
      # NR is "number of records", where each record was a number in our average
      print "\\LARGE";
      print "\\begin{tabular}{|r|r|}";
      print "\\hline"
      print "$(\\Sigma_i data_i)/N$ & $ (\\sqrt{ \\Sigma_i data_i^2 })/N $ \\\\ \\hline";
      print total/NR, "&";
      print sqrt(totalsquared/NR), "\\\\";
      print "\\hline";
      print "\\end{tabular}";
      print "\\end{document}";
    }

    Note that you could also invoke the above awk script as
    gawk ' BODY OF YOUR AWK, from BEGIN to END '







  6. (2 extra points ) Write a bash script that executes stat.awk and does the rest to produce the PDF. #!/bin/bash
    stat.awk < input.data > t.tex
    latex t
    dvipdf t