Reproducible research

a.k.a Literate programming.

An attempt to model reproducibility is Conceptualizing Reproducibility Using Simulations and Theory (CRUST).

bookmarks for PDF

It is handy to export/import bookmarks from Foxit Pro but it is also possible with pdftk.

To install pdftk for Ubuntu,

sudo snap install pdftk       # version 2.02-4, or
sudo apt  install pdftk-java  # version 3.2.2-1

and for Fedora, sudo dnf install pdftk-java.

pdftk src.pdf dump_data output bookmarks.txt
pdftk target.pdf update_info bookmarks.txt output target-bm.pdf

or in a Bash script copy-pdf-bookmarks.sh,

#!/usr/bin/env bash
# Usage: copy-pdf-bookmarks.sh src.pdf target.pdf

set -euo pipefail
[[ $# -eq 2 ]] || { echo "Usage: $0 src.pdf target.pdf" >&2; exit 1; }
tmp=$(mktemp)
trap 'rm -f "$tmp"' EXIT
pdftk "$1" dump_data output "$tmp"
pdftk "$2" update_info "$tmp" output "${2%.pdf}-bm.pdf"
echo "Created: ${2%.pdf}-bm.pdf"

A bookmarks.txt example is converted to books.txt as follows,

awk '!/-/ {print}
     $0 ~ /BookmarkTitle: [0-9]{3} - (.*)/ {
        text = substr($0, RSTART + 21);
        print "BookmarkTitle: " text;
     }' bookmarks.txt > books.txt

To split a large PDF file into four equal parts, use the following script:

#!/usr/bin/env bash
set -euo pipefail

PDF="${1:?Usage: $0 input.pdf}"
N=$(qpdf --show-npages "$PDF")
CHUNK=$(( (N + 3) / 4 ))

for i in 0 1 2 3; do
    START=$(( i * CHUNK + 1 ))
    END=$(( (i + 1) * CHUNK ))
    (( END > N )) && END=$N
    (( START > N )) && break

    qpdf "$PDF" --pages . "$START-$END" -- "part$((i+1)).pdf"
done

for $M$ part,

#!/usr/bin/env bash
set -euo pipefail

PDF=$1
M=$2
N=$(qpdf --show-npages "$PDF")
(( M > 0 && M <= N )) || { echo "Invalid number of parts"; exit 1; }
BASE="${PDF%.pdf}"
Q=$((N / M))
R=$((N % M))
START=1
for ((i=1; i<=M; i++)); do
    SIZE=$((Q + (i <= R)))
    END=$((START + SIZE - 1))
    qpdf "$PDF" --pages . "$START-$END" -- "${BASE}_part${i}.pdf"
    printf 'Part %d: %d-%d\n' "$i" "$START" "$END"
    START=$((END + 1))
done

quarto

This is extensively documented under Linux, https://cambridge-ceu.github.io/csd3/applications/quarto.html.

Under Windows, however it is simpler which involves these steps

  1. Install R, e.g., R-4.3.1

    Optionally, one installs RStudio or Visual Studio Code (Extension Quarto available, ctrl-+/- to enlarge/shrink fonts).

  2. Install python from https://www.python.org/downloads/

    rem Program files\quarto\bin\tools deno upgrade py -m pip install tinytex py -m pip install jupyter py -m pip install numpy py -m pip install matplotlib

  3. Install quarto, e.g., quato-1.3.450, from https://quarto.org

Now we intend to render matplotlib.qmd adapted from https://quarto.org, rendered by quarto render matplotlib.qmd.

---
title: "matplotlib demo"
format:
  html:
    code-fold: true
jupyter: python3
---

For a demonstration of a line plot on a polar axis, see @fig-polar.

```{python}
#| label: fig-polar
#| fig-cap: "A line plot on a polar axis"

import numpy as np
import matplotlib.pyplot as plt

r = np.arange(0, 2, 0.01)
theta = 2 * np.pi * r
fig, ax = plt.subplots(
  subplot_kw = {'projection': 'polar'} 
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```

Reference

Devezer B, Nardin LG, Baumgaertner B, Buzbas EO. Scientific discovery in a model-centric framework: Reproducibility, innovation, and epistemic diversity. PLoS One. 2019 May 15;14(5):e0216125. doi: 10.1371/journal.pone.0216125. eCollection 2019.