46
Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Document Preparation

LaTeX and other vital tools for computing scientists.

CMPUT 603: Teaching and Research MethodsPaul Berube

Sept. 19, 2005

Page 2: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 2

Anatomy of a Thesis

• 6 Chapters, 2 Appendixes

• 14 Section

• 18 Subsections

• 196 Charts

• 11 Figures

• 48 Tables

• 35 cited works

Page 3: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 3

Data for a Thesis

• ~ 40,000 raw data files

• ~ 8,000 processed data files

• 865 charts

• 41 tables

• Charts and tables change when data changes!

Page 4: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 4

Managing the Complexity

• Scripts to process data– Shell scripts, awk, bc, grep, sed, wc, etc…

• Non-interactive programs to create charts– Matlab, gnuplot

• A document preparation system that:– Decomposes and compartmentalizes writing– Integrates with other tools– Automates formatting and numbering

Page 5: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

LaTeX

Page 6: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 6

The Basics

• Commands start with a ‘\’– \chapter, \section, \subsection, \

subsubsection– {\tt <monospaced text>}, {\bf <bold

text>}, {\it <italicized text>}– \input{<filename}

• Some special characters: ‘#’, ‘&’, ‘\’, ‘{‘, ‘}’– ‘~’ : non-breaking space– ‘$’ : math mode, ‘^’ superscript, ‘_’ subscript– ‘%’ : comments

Page 7: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 7

Document Structure

RootFile

Intro.tex Results.tex Conc.tex

Fig1.eps Sec1.tex Sec2.tex

Tab.tex

Local.bib

Fig2.eps

Page 8: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 8

Document Structure

RootFile

Intro.tex Results.tex Conc.tex

Fig1.eps Sec1.tex Sec2.tex

Tab.tex

Local.bib

Fig2.eps

xfig

scriptgnuplot

Page 9: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 9

The figure environment

• Used for inserting images, graphs, charts, etc…

• A “float” environment– Latex will put the figure where it thinks is best

Figure 2, top of page 4:

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Page 10: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 10

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Captions

Caption

Page 11: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 11

Labels & References

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Label

Page 12: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 12

Labels & References

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Label

Figure~\ref{fig:motiv-exmp} shows…

Reference

Page 13: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 13

Labels & References

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Label

Figure~\ref{fig:motiv-exmp} shows…

Figure 2 shows…

Reference

Page 14: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 14

(conclusion.tex <motiv2.eps>Overfull \hbox (196.49pt too wide)

\begin{figure} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure}

Page 15: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 15

figure*

• Adding a ‘*’ lets a figure or table span the whole page in multi-column documents

\begin{figure*} \centering \includegraphics{motiv2.eps} \caption{Motivating Example.} \label{fig:motiv-exmp}\end{figure*}

Page 16: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 16

Tables

• Also a “float” environment

\begin{table} \centering \begin{tabular}{|l|c|} \hline {\bf Evaluation Category} & {\bf Score} \\ How confident are [snip] & \\ \hline {\bf Reviewer Confidence} & \\ Are you convinced [snip] & \\ \hline \end{tabular} \caption{Peer-based referee report for \paper.} \label{tab:eval1}\end{table}

Table 1, Page 3

Page 17: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 17

\begin{table} \centering \begin{tabular}{|l|c|} \hline {\bf Evaluation Category} & {\bf Score} \\ How confident are [snip] & \\ \hline {\bf Reviewer Confidence} & \\ Are you convinced [snip] & \\ \hline \end{tabular} \caption{Peer-based referee report for \paper.} \label{tab:eval1}\end{table}

Tables

• Also a “float” environment

Table 1, Page 3

Table Format Specifier:-‘r’ : right-justified column-‘l’ : left-justified column-‘c’: center-justified column-‘|’ : vertical line

Page 18: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 18

\begin{table} \centering \begin{tabular}{|l|c|} \hline {\bf Evaluation Category} & {\bf Score} \\ How confident are [snip] & \\ \hline {\bf Reviewer Confidence} & \\ Are you convinced [snip] & \\ \hline \end{tabular} \caption{Peer-based referee report for \paper.} \label{tab:eval1}\end{table}

Tables

• Also a “float” environment

Table 1, Page 3& = column separator

Page 19: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 19

\begin{table} \centering \begin{tabular}{|l|c|} \hline {\bf Evaluation Category} & {\bf Score} \\ How confident are [snip] & \\ \hline {\bf Reviewer Confidence} & \\ Are you convinced [snip] & \\ \hline \end{tabular} \caption{Peer-based referee report for \paper.} \label{tab:eval1}\end{table}

Tables

• Also a “float” environment

Table 1, Page 3\\ = newline

Page 20: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 20

\begin{table} \centering \begin{tabular}{|l|c|} \hline {\bf Evaluation Category} & {\bf Score} \\ How confident are [snip] & \\ \hline {\bf Reviewer Confidence} & \\ Are you convinced [snip] & \\ \hline \end{tabular} \caption{Peer-based referee report for \paper.} \label{tab:eval1}\end{table}

Tables

• Also a “float” environment

Table 1, Page 3\hline

Page 21: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 21

Text-figures

• To create a figure containing text, use a tabular inside a figure

• Works great for code segments, etc\begin{figure} \centering \begin{tabular}{|l|}

\hline Title\\ 1. Introduction\\ Acknowlegments\\ \hline\end{tabular}

\caption{Organization for \paper.} \label{fig:organization}\end{figure}

Page 22: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 22

Other Table Tricks

• Multicolumn– \multicolumn{<span>}{<text>}

• Multirow– \multirow{<span>}*{<common text>}

Page 23: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 23

Enumeration Environments

• Not a float

• Enumerate : ordered list

• Itemize : unordered list

• Description : unordered list with item labels

Canadian bands include:\begin{itemize} \item Chilliwack \item Harlequin \item The Guess Who\end{itemize}

Page 24: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 24

Math Mode

• LaTeX is the tool to typeset mathematics and symbols

• $ <math> $ : inline math

• $$ <math> $$ : not-inline math

Page 25: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 25

Make your own commands

• Customized commands– Shorthand– Help ensure consistency

• \def– \def\course{{\tt CMPUT}~603}

•This course is \course.

• \let, \newcommand, \newenvironment

This course is CMPUT 603.

Page 26: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 26

Citations & Bibliographies

• Bibtex makes it easy– Create a .bib file with your references– Cite references with \cite{<name>} in text

– \cite{<name>} [<num>] in text, eg, [3]– Bibliography automatically generated with

proper formatting– Bibliography only includes references you

actually cite

Page 27: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 27

Citations & Bibliographies

.bib file

Page 28: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 28

Citations & Bibliographies

Optional

Required

•Color-coded items

Page 29: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 29

Citations & Bibliographies•Fill in everything you can find out.

Page 30: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 30

Citations & Bibliographies•CTRL-C, CTRL-C to clean up bib entry

Page 31: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 31

Things to read about

• Math mode

• Subfigures

• Tabularx environment

• Tabbing environment

• Minipages

• Algorithmics packages

Page 32: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Bash scripting

See: Advanced Bash-Scripting Guide

Page 33: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 33

Scripts

• Automate tedious tasks

• Tests and checks more robust than manual execution

• “Glue” to bind a collection of tasks

• High-level programming– Scripts like a “meta-program”?

• Rely on common utilities to do the “real work”

Page 34: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

sed

See: Advanced Bash-Scripting Guide

Page 35: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 35

Sed

• String manipluation utility

• Substitution– $> sed –e “s/hate/love/” file– $> find ./data/ -name “*.data” | sed –e

“s/\.\/data\///” < file

• Selection– $> sed –n –e “10p” file

Page 36: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

awk

See: Google

Page 37: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 37

Awk

• Used to process data in plain-text formats

• C-like syntax

• Can address file data by column– $> awk ‘{print $3}’ file

Page 38: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 38

Awk

• Use to process data in plain-text formats

• C-like syntax

• Can address file data by column

• Can perform math, has variables

awk ‘BEGIN \ {max = 0; min = 9999; cnt = 0; sum = 0} \ { cnt++; sum += $1; \ if($1 > max) max = $1; \ if($1 < min) min = $1; } \ END \ {printf "%f %f %f\n", min, max, sum/cnt}’

Page 39: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 39

Awk

• Use to process data in plain-text formats

• C-like syntax

• Can address file data by column

• Can perform math, has variables

awk ‘BEGIN \ {max = 0; min = 9999; cnt = 0; sum = 0} \ {cnt++; sum += $1; \ if($1 > max) max = $1; \ if($1 < min) min = $1; } \ END \ {printf "%f %f %f\n", min, max, sum/cnt}’

Page 40: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 40

Awk

• Use to process data in plain-text formats

• C-like syntax

• Can address file data by column

• Can perform math, has variables

awk ‘BEGIN \ {max = 0; min = 9999; cnt = 0; sum = 0} \ {cnt++; sum += $1; \ if($1 > max) max = $1; \ if($1 < min) min = $1; } \ END \ {printf "%f %f %f\n", min, max, sum/cnt}’

Page 41: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 41

Awk

• Use to process data in plain-text formats

• C-like syntax

• Can address file data by column

• Can perform math, has variables

awk ‘BEGIN \ {max = 0; min = 9999; cnt = 0; sum = 0} \ {cnt++; sum += $1; \ if($1 > max) max = $1; \ if($1 < min) min = $1; } \ END \ {printf "%f %f %f\n", min, max, sum/cnt}’

Page 42: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

gnuplot

See: gnuplot webpage, Google

Page 43: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 43

gnuplot

• Script-based 2D and 3D plotting

• Many output formats, including eps

• Graph functions and/or data from files

• Apply functions to data in files before graphing

Page 44: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 44

gnuplot

set term postscript epsset output ‘sincos.eps’set title “sin(x), cos(x)”set xrange [-2*pi:2*pi]plot sin(x) with lines, cos(x) with points

Page 45: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 45

Putting It All Together

• A Script:– Build the program if needed– Run the program to simulate M experiments,

each run N times– Calulate the min, max, and average of the N

runs for each experiment– Graph the results

• Max and min lines

• Smooth average line

• Each data point

Page 46: Document Preparation LaTeX and other vital tools for computing scientists. CMPUT 603: Teaching and Research Methods Paul Berube Sept. 19, 2005

Sept. 19, 2005 CMPUT 603, Paul Berube 46

Putting It All Together

Demo…