• Ei tuloksia

Writing references with bibtex

BibTeX is both a program and a file format for managing your literature references automatically.

6.7. WRITING REFERENCES WITH BIBTEX 101

6.7.1 Idea

•You collect a database of bibtex records (bibtex entries) for all sources you may refer in your document. It can contain also extra entries, because the bibtex selects only those references which are actually re-ferred.

•The bibtex entries look like the following:

@article{Gettys90,

author = ”J. Gettys and P. Karlton and S. McGregor”, title = ”The X Window System, Version 11”, journal = ”Software Practice and Experience”, volume = ”20”,

number = ”2”, year = ”1990”, }

•Each bibtex entry should have a unique label (aboveGettys90). The labels are referred in the text normally by\cite{label}.

•The resulting database is a common text file, and only the reocrds have a special format. The file should be called<file name>.bib. For example,dbase.bib.

•You include the database into your document by commands

\bibliographystyle{alpha}

\bibliography{dbase}

(The first command defines just the style.)

•When you compile the latex document, you have to runbibtextoo.

latex document.tex bibtex document latex document

The first command is a normal latex compilation. Commandbibtex generates a file calleddocument.bbl. It is similar to a latex bibliogra-phy list, but it contains only those sources which are actually referred in your document. The last command includes the references into your document and the resultingdocument.dvifile is ready.

102 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

6.7.2 Bibtex entries

Often you can found the bibtex entries ready typed in the net. However, sometimes they are erroneous and you should be able to check that they are correct. Sometimes you have to write the bibtex entries yourself.

Searching bibtex entries

•Bibtex entries can be find in many digital libraries (e.g. ACM, citeseer) with the article.

•DBLP Computer Science bibliography (http://www.informatik.uni-trier.

de/ley/db/index.html) contains a large collection of bibtex entries!

•You can make a google search using the authors, paper name and word

”bibtex” as keywords.

Writing bibtex entries

When you write the bibtex entries, you should first decide what type of source you have. The most common types are:

•a journal paper→@article

•a conference paper→@inproceedings

•a book→@book

Other types:

•a chapter or a section in a book by one author→@inbook

•a chapter in a book (a collection) which is written by several authors

→@incollection

•a master thesis→@mastersthesis

•a dosctoral thesis→@phdthesis

•a technical report→@techreport

•other: seehttp://www.ecst.csuchico.edu/jacobsd/bib/formats/

bibtex.html

6.7. WRITING REFERENCES WITH BIBTEX 103 When the type is fixed, you should define all required fields. The most often needed fields are:

•author

•title (the title of a paper or book)

•journal (the journal name)

•booktitle (if the paper belongs to a book or collection, and already has a title of its own. Especially, the name of the conference proceedings.)

•year (the publication year)

•pages

•volume (in journals, also if a book has several volumes, and the volumes in LNCS series)

•number (the issue number of a journal or the number of a technical report)

•editor (if a book or a collection has editors)

•publisher (the publisher’s name)

•address (the publisher’s address, not necessary, or the address of an institution. Notice. just the city + country.)

•institution (the sponsoring institution of a technical report, often a department + university)

•Other fields: see standard fields inhttp://www.ecst.csuchico.edu/

jacobsd/bib/formats/bibtex.html Notes:

•By default, Bibtex capitalizes only the first letter of the first word in the titles. If you need other capital letters, you have two choices:

1. Put the letter or letters to be capitalized into braces, e.g.

title=’’Using {B}ayesian student models in intelligent tutoring systems’’

2. Put the whole field value into braces. Now you don’t need the quotation marks at all:

104 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES title={Using Bayesian student models in intelligent tutoring systems}

Notice that journal and book names are usually written such that the first letter of each word is capitalized!

•Remember all the commas and quotation marks! Otherwise bibtex cannot parse the entry. The most common error is a missing quotation mark or a comma in the end of field.

•In DBLP the entry is often in two separate records: one for the whole proceeding and one for the article. The article entry does not contain all fields alone, but it refers to the collection by fieldcrossrefand inherits all fields from it. →copy both entries into your database or add the missing fields to the article entry.

6.7.3 Exercise

Search or write the bibtex entries for your literature sources. Test that the bibtex can generate all references! (Now it is important that you also refer to your sources in the text.)

6.8 Writing algorithms in latex 6.8.1 Instructions

The latex source file of this subsection is available onhttp://www.cs.joensuu.

fi/pages/whamalai/sciwri/algexample.tex.

Using algorithm library

New commands for algorithm environment are defined in package algorithmwh.sty.

It can be loaded fromhttp://www.cs.joensuu.fi/pages/whamalai/sciwri/

algorithmwh.sty. Save it to your working directory. In addition, you have to include two other packages (floatandxspace) in the header. Thus, add the following lines to the header of your latex document:

\usepackage{float}

\usepackage{xspace}

\usepackage{algorithmwh}

6.8. WRITING ALGORITHMS IN LATEX 105 Notes

•You can add your own commands to algorithmwh.sty by\newcommand.

Suggestion: rename the style file according to you, if you make changes to it.

•Line numbers are useful, if you refer to certain lines in your code. Begin each code line by\uln. If you don’t need line numbers, drop\uln.

•You have to specify the spaces explicitely by\>.

•Fix the style you use for assignments. There are several alternatives:

x=y,x←y,x:=y.

•Logical bit-operations\uor,\uxor,\uand,\unot require math mode ($ ’s), e.g.x|yis achieved by

$x \uor y$

Example (a text extract)

The basic idea of the algorithm (Alg. 2) is following:

1. Search connected components from graphGby depth-first search. This can be completed in time Θ(|V|+|E|) (See section Analysis.) Let the resulting vertex set beV⊆V, and the corresponding undirected subgraphG= (V, E).

2. For each connected component search self-referring groups fromGby depth-first search (Alg. 3).

6.8.2 Exercises

1. Write Algorithm 4! Test how to refer to it in the text (like here).

2. Test how to write the following kind of method using an itemize list!

Step 1x=x+ 1 Step 2y=x2+ 1

Step 3 Ify≤nreturn to Step 1.

3. Write an algorithm or a method to your paper!

106 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES Alg. 2 SelfReferringSets(G, minf). An algorithm for searching all strongly self-referring sets in graphG= (V, E).

Input:G= (V, E), minf

Output:Y⊆V

1 begin

2 compute all connected components inG= (V, E) 3 foreach connected componentVinG= (V, E)do 4 forallv∈Vdfs({v}, degree(v), minf, v)

5 end

Alg. 3 dfs(X, d, minf, last). A depth-first search of the self-referent sets in subgraphG= (V, E).

5 thenreturn // search failed

6 forall verticesu∈V(u > lastand∃v∈X(v, u)∈E)do 7 dfs(X∪ {u}, d, minf, u)

8 end

6.9 Special latex notes

6.9.1 No numbers to sections or sections

If you do not want to output section or section numbers (like in this doc-ument) use ’*’ after the command, e.g.\subsection*{title}. This is not recommended in master thesis, but you can maybe need it in some special cases.

6.9. SPECIAL LATEX NOTES 107

Alg. 4 PartitioningClustering(S, n, k) Input:Data setS,n=|S|, number of clustersk Output:Centroidsc1, ..., ck

1 begin

2 Select randomlykdata pointsp1, ..., pk∈S

3 forallpi // Initialization

4 begin

5 ci=pi

6 Ci={pi}

7 end

8 while(not converged) // Update clusters

9 begin

15 Update centroidsci

16 end

17 end

6.9.2 Other symbols or item names to lists

If you want to use other symbols that bullets in an itemize list, you can define new symbols or item names in\itemcommand like\item[a]and

\item[Step1] . See example:

\begin{itemize}

\item[Step 1] $x=x+1$

\item[Step 2] $y=x^2+1$

\item[Step 3] If $y \leg n$ return Step 1.

\end{itemize}

outputs Step 1x=x+ 1 Step 2y=x2+ 1 Step 3 Ify≤nreturn Step 1.

108 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

6.9.3 Footnotes

Footnotes1are achieved by command\footnote{text}.

6.9.4 Font size

Font size can be

enlarged

orshrunkby special commands

\Huge \LARGE \Large \tiny

\footnotesize

etc. See latex manual! E.g. if your table contains a lot of text, first try to prune the text, but if it doesn’t help, you can use footnote size:

\begin{center}

If you want to get a table, where some columns are divided into subcolumns on some rows but united in others, you can use command\multicolumn.

This command requires packagemulticol. Include it in the header by com-mand\usepackage{multicol}.

See the following example:

\begin{table}[!h]

\begin{center}

\caption{Comparison of prediction accuracy of {\em LR} and {\em NB} models.

The prediction accuracy is expressed

true positive $TP$ and true negative $TN$ rates.

All models have been evaluated by 10-fold cross-validation and the classification rates have been averaged.}

1These not recommended in computer science texts; use them sparsely!

6.9. SPECIAL LATEX NOTES 109

Table 6.3: Comparison of prediction accuracy ofLRandNBmodels. The prediction accuracy is expressed true positiveT Pand true negativeT N rates. All models have been evaluated by 10-fold cross-validation and the classification rates have been averaged.

Model structure LRrates NBrates

TP TN TP TN

110 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES Notice that you have to define the maximum number of columns in the tabular definition, and multicolumn is used to combine columns on some rows.

6.9.6 Sideway tables

If the table is very large, using footnote size doesn’t help enough. In this case, you can allign the table horizontally by commands\begin{sidewaystable}and

\end{sidewaystable} instead of\begin{table}and\end{table}. These commands demand that you include packagerotating. Add to the header line\usepackage{rotating}.

\begin{sidewaystable}

\begin{center}

\caption{Table caption}

\label{predmodels}

\footnotesize{

\begin{tabular}{|l|l|l|l|l|l|}

\end{tabular}

}

\end{center}

\end{sidewaystable}

6.9.7 Special letters

In foreign names, you need sometimes special letters. E.g. Scandinavian letters ¨a and ¨o are achieved by{\"a}and{\"o}; ´a by{\’a}and `a by {\‘a}.

6.9.8 Removing extra spaces

After a full stop, latex writes always a longer space, because it interpretes it as an end of sentence. However, if you need full stops inside a sentence, e.g.

in an abbreviation, this is not desirable. It is recommended that after each such pseudo-full stop you define the space explicitely by a slash\(and drop the space from text):

E.g.\ tigers, lynxes, and lions are cat animals.

In the article (and master thesis) template the default is that all paragraphs begin by space. This is unconvienent when you just want to leave empty

6.9. SPECIAL LATEX NOTES 111

lines without beginning new paragraphs. You can get rid of the beginning space by command\noindent.

For example:

’’The associated probabilities are

\noindent

$a \rightarrow action1$ $(0.6)$ $a \rightarrow action2$ $(0.4)$\\

$b \rightarrow action3$ $(0.6)$ $b \rightarrow action2$ $(0.4)$\\

$c \rightarrow action3$ $(0.6)$ $c \rightarrow action2$ $(0.4)$’’\\

outputs

”The associated probabilities are a→action1 (0.6)a→action2 (0.4) b→action3 (0.6)b→action2 (0.4) c→action3 (0.6)c→action2 (0.4)”

6.9.9 Adding extra spaces

The latex doesn’t consider how many spaces you have written in the text file – it outputs always just one space. To get assitional spaces, you have to define them explicitely by ˜character.

If you need more space (either horizontal or vertical) you can define it by commands\vspace{2cm}(vertical space of 2 cm) and\hspace{13mm}(a hor-izontal space of 13mm).

112 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

Appendix A: A simple latex template

%This is a really simple latex template for writing your first articles

%The paper size, font size and document type are defined in the following

\documentclass[a4paper,12pt]{article}

%Uncomment the following line, if you write in Finnish (special characters)

%\usepackage[T1]{fontenc}

%The following line is not necessary if you write in English. If you write

%in another language, uncomment the line and change the language

%\usepackage[english]{babel}

%useful special symbols:

\usepackage{amssymb}

\usepackage{latexsym}

%a useful package if you write url addresses:

\usepackage{url}

%a package for figures:

\usepackage[dvips]{color}

\usepackage{epsfig}

%Bibliography style. The alpha style generates references with

%first letters and year. If you prefer numbers, use style plain.

\bibliographystyle{alpha}

%Create your own environments

\newtheorem{definition}{Definition}

\newtheorem{example}{Example}

%If you want to remove the space before paragraphs uncomment the following.

%Remember then to leave an empty line between paragraphs!

%\setlength{\parindent}{0pt}

\title{The main title}

6.9. SPECIAL LATEX NOTES 113

\author{Your name}

%Uncomment the following, if you don’t want the date to be printed

%\date{}

\begin{document}

\maketitle

\section{The title of the first main section}

Write section 1 here.

\section{The title of the second main section}

You can write an introductory paragraph here, before subsections.

However, remember use introductory paragraphs systematically: either everywhere or nowhere.

\subsection{The title of the first subsection}

Write subsection 2.1 here.

\subsection{The title of the second subsection}

Write subsection 2.2 here.

\subsection{The title of the second subsection}

Write subsection 2.3 here.

\section{The title of the third main section}

You can divide this into subsection, too. Etc.

\end{document}

114 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

Appendix B: A latex template for articles

%This is a basic latex template for writing articles like

%course papers, program documents, etc.

% http://www.cs.joensuu.fi/pages/whamalai/sciwri/articletemplate.tex

%The paper size, font size and document type are defined in the following

\documentclass[a4paper,12pt]{article}

%Uncomment the following line, if you write in Finnish (special characters)

%\usepackage[T1]{fontenc}

%The following line is not necessary if you write in English. If you write

%in another language, uncomment the line and change the language

%\usepackage[english]{babel}

%useful special symbols:

\usepackage{amssymb}

\usepackage{latexsym}

%a useful package if you write url addresses:

\usepackage{url}

%a package for figures:

\usepackage[dvips]{color}

\usepackage{epsfig}

%Bibliography style. The alpha style generates references with

%first letters and year. If you prefer numbers, use style plain.

\bibliographystyle{alpha}

%Create your own environments

\newtheorem{definition}{Definition}

\newtheorem{example}{Example}

%If you want to remove the space before paragraphs uncomment the following.

%Remember then to leave an empty line between paragraphs!

%\setlength{\parindent}{0pt}

6.9. SPECIAL LATEX NOTES 115

\title{The main title}

\author{Your name}

%Uncomment the following, if you don’t want the date to be printed

%\date{}

\begin{document}

\maketitle

\section{References}

The references are listed in the end of document. The title is generated automatically. In the article style, the reference list is labelled "References"; in the report style, it is labelled

"Bibliography."

The reference notations are defined in the header by command\\

\verb \bibliographystyle{style}. Style alpha is often used in cs master thesis. If you prefer numbers, use style plain.

Referring to sources, like to \cite{boulay}, happens by \verb \cite command.

Try to refer to other sources! Notice that you have to run latex command a couple of times, before all references are solved.

\section{Referred tables}

We have already practised how to make simple tables. Now we will make tables, like Table \ref{tableexample} which have titles and are referred from the text.

$\rightarrow$ & An arrow to the right\\

\hline

116 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

$\leftarrow$ & An arrow to the left\\

\hline

$\leftrightarrow$ & An arrow to both directions\\

\hline

$\Rightarrow$ & A double line arrow to the right\\

\hline

$\Leftarrow$ & A double arrow to the left\\

\hline

$\Leftrightarrow$ & An double arrow to both directions\\

\hline

\end{tabular}

\end{center}

\end{table}

Table \ref{tableexample} is aligned in the center. Option !h tries to force the figure as near to the given location (between this and the previous paragraph) as possible. If the position does not look good, you can remove the option (especially with large figures and tables).

\section{Figures}

The figures should be postscript files. To test the following examples, load the file cat.ps from

\url{http://www.cs.joensuu.fi/pages/whamalai/sciwri/cat.ps}. Store it to the same directory as this document. If you want to use another directory, you have to specify the path also in the figure. E.g.\ if the file is in a subdirectory ’’figures’’, \verb \includegraphics gets parameter \verb {figures/cat.ps}. ~

If you don’t refer to the figure, you can simply include it here like this:

\begin{center}

\includegraphics[width=0.6\textwidth]{cat.ps}

\end{center}

In scientific text, all figures must have a title (caption) and be referred from the text. This is demonstrated in Figure

\ref{figexample}.

6.9. SPECIAL LATEX NOTES 117

\begin{figure}[!h]

\begin{center}

\includegraphics[width=0.6\textwidth]{cat.ps}

\caption{A cat writing scientific text.}

\label{figexample}

\end{center}

\end{figure}

Figure \ref{figexample} is aligned in the center.

The figure width is defined to be 60\%

of the text width. Try what happens if you change it!

% Literature references:

% If you use bibtex, uncomment the following. Add the name of your

% own bibtex database instead of dbase (now file dbase.bib)

%\bibliography{dbase}

% If you don’t use bibtex, the literature sources are defined in

% the following list. If you use bibtex, delete the list

\begin{thebibliography}{4}

\bibitem{assrule} Agrawal, R., Mannila, H., et al.:

Fast discovery of association rules.

In Fayyad, U.M., Piatetsky-Shapiro, G.,P., Smyth, P., Uthurasamy, R. (eds.):

Advances in knowledge dicovery and data mining.

AAAI/MIT Press, Menlo Park, CA (1996) 307--328

\bibitem{boulay} Boulay, B. du:

Can We Learn from ITSs?

Intelligent Tutoring Systems (2000) 9--17

\bibitem{butz} Butz, C.J., Hua, S., Maguire, R.B.:

Web-based intelligent tutoring system for computer programming. Web Intelligence and Agent Systems: An International Journal 4, 1 (2006) To appear.

\end{thebibliography}

\end{document}

118 CHAPTER 6. LATEXINSTRUCTIONS AND EXERCISES

q0 q1 q2

+, − d

d

d

.

f

x1.

x2

. y1 . y2

. y3

A B

A B Parallel episode Serial episode

1. Understanding domain

3. Discovering patterns

5. Application 2. Preprocessing data

4. Postprocessing results

Figure 6.2: Example figures

Bibliography

[1] Barrass, R.: Scientists must write. A guide to better writing for scientists, engineers and students. Chapman and Hall, London, New York, 1978.

[2] Peat, J. et al.: Scientific writing – easy when you know how. BMJ Books, London, 2002.

[3] Publication Manual of the American Psychological Association. Fifth Edi-tion. American Psychological Association, Washington DC, 2002.

[4] Strunk, W.: Elements of Style. Priv. print, Ithaca, NY, 1918. On-line edition published July 1999 by Bartleby.com.www.bartleby.com/141/.

Loaded 1.3. 2006.

119