Command Line
Last updated on 2026-11-15 | Edit this page
Overview
Questions
- How can I make my results easier to reproduce?
Objectives
- Introduce Zipf’s Law project.
- Introduce git branches.
- Illustrate pain and fragility of building with editor and sequences of command line commands.
Let’s imagine that you are writing code for a research project to test Zipf’s Law.
Zipf’s Law
The most frequently-occurring word occurs approximately twice as often as the second most frequent word. This is Zipf’s Law.
We have set up a git repository with a sequence of branches to step through the tutorial today. You should start by cloning the repository
OUTPUT
Cloning into 'work_dir'...
done.
Change to the new directory, checkout the branch 06-documentation, and list the branches
OUTPUT
* 06-documentation
setup
remotes/origin/01-command-line
remotes/origin/02-first-makefile
remotes/origin/03-no-hands
remotes/origin/04-testing
remotes/origin/05-standards
remotes/origin/06-documentation
remotes/origin/HEAD -> origin/setup
remotes/origin/setup
Today, we will start with the branch 01-command-line and step through the numbered branches arriving at the branch 06-documentation which uses all of the tool we will introduce.
First let’s peek at the final results
View the result with (depending on your OS)
View the result with (depending on your OS)
Let’s take a couple of minutes to skim the document.
Now clean up and start with the 01-command-line branch
The output of the last command should be
OUTPUT
06-documentation
* my-01-branch
setup
remotes/origin/01-command-line
remotes/origin/02-first-makefile
remotes/origin/03-no-hands
remotes/origin/04-testing
remotes/origin/05-standards
remotes/origin/06-documentation
remotes/origin/HEAD -> origin/setup
remotes/origin/setup
Look at the files that git provides and in the directory
OUTPUT
.gitignore
README
abyss.txt
analyze.py
isles.txt
local.bib
report.tex
setup/README.md
setup/check_setup.sh
setup/environment.yml
setup/requirements.txt
setup/shell.nix
setup/test_branches.sh
OUTPUT
README analyze.py local.bib setup
abyss.txt isles.txt report.tex src
The directory src is left over from using the 06-documentation branch for the preview. Let’s remove it
$ rm -r src
Now build the document pdf by following the instructions in the README file.
OUTPUT
To build report.pdf we need the following:
1. Insert data from abyss.dat into report.tex
2. Insert into report.tex counts of the two most frequent words and
their ratio for abyss.txt and isles.txt.
3. The figure files abyss.pdf and isles.pdf
In report.tex, each place that needs results of calculations is
marked by a line containing \FixMe. Replace each \FixMe line with
those results, as steps 2 and 3 below describe. (LaTeX does not know
\FixMe, so it stops with "Undefined control sequence" at any that
remain.)
One can generate the required information and build the document as
follows:
1. From the command line, run
$ python analyze.py abyss.txt abyss.dat abyss.pdf
$ python analyze.py isles.txt isles.dat isles.pdf
2. In the table in report.tex, replace the \FixMe line and the three
lines after it with the top_two counts reported above and the
calculated ratios. The result should look like this:
Book & First & Second & Ratio\\ \hline
abyss & 4044 & 2807 & 1.44 \\
isles & 3822 & 2460 & 1.55 \\
\hline
3. Replace the \FixMe line before the verbatim block in report.tex by
putting the first two items in each of the first ten lines from
abyss.dat inside that block. Those lines should be:
the 4044
and 2807
of 1907
a 1594
to 1515
in 1221
i 974
was 695
it 680
for 675
4.Run latexmk to build the document:
$ latexmk -pdf report.tex
If you are not sure you did it right, you can start over by running:
$ rm *.dat *.pdf *.aux *.bbl *.blg *.fdb_latexmk *.fls *.log
or if you have clobbered some source files:
$ rm * ; git checkout .
If you use rm * ; git checkout ., rm will
print
OUTPUT
rm: cannot remove 'setup': Is a directory
That is expected: rm leaves the directory setup
alone, and git checkout . restores the files it
removed.
Key Points
- We hope to improve on executing instructions from a README.