How to Write an Academic Paper Programmatically

Never copy a number by hand. Never re-type a table or re-make a figure after updating your analysis or results. Learn this now, save time later.

Richard Karlsson Linnér · v2026-11-16

With credit to E.A., who fully introduced me to the approach described here.

Level: graduate to PhD. Time to learn: 1–2 days with research programming experience, 7 weeks from basics (R, LaTeX, and shell scripting).

What are results data in a PDF?

Results Data

Everything your code, scripts, and statistical software produce that ends up in a paper: inline numbers/text, figures, tables, and references. In data management plans (DMPs), this is what goes under "research output."

This page teaches you to write manuscripts with every result linked via code. No hand-copying, no re-typing.

A well-made programmatic structure maps 1:1 to the DMP. The DMP adds what the code is not meant to represent: project organization, legalities, ownership, licenses, restrictions, responsible persons. It also summarizes the code, infrastructure, and data flows in prose, but that writes fast when you have grown accustomed to describing a standardized programmatic workflow, not inventing a new one each time. The results data is FAIR by construction: every output during paper writing is already findable (named files in a versioned repository), accessible (plain-text formats), interoperable (CSV, PDF, TeX), and reusable (produced by a script anyone can re-run). Provenance lives in your version-controlled code (Git) at the level of individual results (file names, directory paths, macro names), not at the level of the paper as a whole. This way of organizing an academic paper is close to one button push to fulfill FAIR and archival requirements.

A compiled PDF contains exactly four kinds of results data beyond the prose and math. Each traces back to a file on disk, produced by your analysis script. None of them get typed into the manuscript by hand — every result in your paper is a displayed variable.

A figure.pdf B C D
A — Inline numbers/text
Statistics, variable names, and labels in running text. Read from a results file via \input or \newcommand.
B — Figure
A plot or image. Produced by an R script, saved as .pdf, pulled in by \includegraphics.
C — Table
A formatted table. The whole tabular is written by R as a .tex fragment, loaded via \input.
D — References
Managed in a .bib file. Never typed into the manuscript by hand.

The R scripts compute every number, draw every figure, format every table, and save each one to a file on disk. In the manuscript, you write commands that in effect say "read the file called sample_size.txt and put whatever is in it right here." LaTeX opens each referenced file, reads the contents, and places them. You type file names and variable names. The computer does the rest.


Manual vs. automated

This comparison summarizes how much easier it is to update results or revise an automated paper.

The manual way

1. Run analysis (R, Stata, Python, etc.)
↓
2. Copy output from terminal or Stata console, or copy from regression tables (estout, outreg2). Figures made ad hoc during analysis.
↓
3. Hand-type numbers and tables into LaTeX (Overleaf), Word, or Google Docs. Re-make and re-insert figures.
↓
4. Compile or export PDF
✕ Analysis changes? Repeat steps 2–3 by hand.
What goes wrong: copy errors, stale numbers, no audit trail, no tables on disk (retyped every revision), figures hard to remake, hard to report exact input data (which some journals require), and uploads that fall out of sync.

The automated way

1. Run analysis (R, Stata, Python, etc.)
↓
2. Script saves results to disk — ideally CSV, but any structured or binary format works. Figures and tables made from those same result files.
(Protected environment? Export first, same steps.)
↓
3. LaTeX reads numbers (\input + \newcommand), tables (\input), and figures (\includegraphics) from those files.
↓
4. Compile PDF (latexmk runs the engine as many times as needed)
↺ Analysis changes? Press: re-run steps 1–4.
One update propagates everywhere. Change the data or code, re-run, re-compile. Every number, table, and figure updates. Full audit trail in the result files.

The model above has two apparent bottlenecks — protected environments and Overleaf — but neither breaks the principle. Each just adds one extra copy or upload step, easy to script (if allowed). CBS, for example, has an airlock: your script prepares results and places them in the results export area; on the other side, a script downloads from a fixed output folder or a temporary URL. Even with Overleaf, manually uploading result files introduces a step where things can go stale, but uploading results files collected in a single directory is much better than hand-copying numbers (more on this below). Neither block prevents this model, and arguably even makes the case for it.


Step by step: data to PDF

Three types of results matter most (references get their own section below): A inline numbers/text, B figures, C tables. For each, the R code that writes the result to a file and the LaTeX that reads it.

The code below has two halves. The first is your analysis — computing statistics, fitting models, extracting results. That is your expertise; no tool replaces it. The second is LaTeX scaffolding — \newcommand macros, sprintf formatting, tabular environments. AI chatbots handle this well; humans gain nothing from doing it manually. Just as Excel provides the grid and you fill in the analysis, let the AI write the LaTeX plumbing and you focus on the analysis.

I wrote these lines by hand for years. Humans can do it, and did, but it is tedious as heck. So the code examples below skip the scaffolding and show two things instead: the prompt you give the chatbot, and the file that lands on disk. The prompt holds variable names and layout rules, nothing else: the AI never sees your data, never touches any numbers, and no value comes from the model's own weights — it only writes the scaffolding. If the code is written correctly, the scaffolding does not impact your analysis — pure plumbing between your results files and TeX. Number of digits, thousand separators, column alignment, booktabs rules — all machine work, but absolutely no results hallucinated or generated by the model itself. The working example shows the scaffolding code in full.

General rule: every script should produce rectangular data (CSV) alongside any TeX output, unless the data is protected or truly not relevant. In a small project, one script can produce both the CSV and the formatted .tex in one pass. In a larger project, separate the two steps: one script produces results as CSV, another selects and formats for TeX. This keeps the analysis independent of the presentation.

A — Inline numbers/text

Every statistic in your prose should come from a file that your analysis script wrote. The same applies to labels that appear in multiple places — your focal variable name, a treatment label, the study period — define them as macros and they propagate everywhere, changing in one place instead of many.

Two workflows. A master results file collects all macros in one file — simpler for small projects. One file per constant puts each value in its own file — scales better when constants multiply across subgroups. You can mix both.

Option 1 Master results file

Your R script computes all values and writes them as LaTeX \newcommand macros to a single .tex file. A companion CSV records what each macro means and where it comes from (the audit trail).

R script → results.tex + results.csv → \input{results} → \myValue{} in prose → PDF
make_results.R (you write this)
# === Compute statistics ===
n_total  <- nrow(dt)
mean_age <- round(mean(dt$age), 1)
beta     <- coef(model)["treatment"]
p_val    <- coef(summary(model))[
              "treatment", "Pr(>|t|)"]
prompt to the chatbot
My R script has the values n_total,
mean_age, beta, and p_val. Write R code
that saves them as LaTeX \newcommand
macros to tables/results.tex:
- names: nTotal, meanAge, betaMain, pMain
  (letters only: no digits, no underscores)
- n_total with thousands separator;
  mean_age to 1 decimal; beta to 2
- p_val with its relation sign:
  "= 0.032", or "< 0.001" if smaller
- first line: % generated by
  make_results.R; do not edit
- also save tables/results.csv with
  columns macro, value, source
  (leave source for me to fill in)
Read every value from the R objects;
hardcode nothing.
tables/results.tex (generated)
% generated by make_results.R; do not edit
\newcommand{\nTotal}{2,391}
\newcommand{\meanAge}{41.3}
\newcommand{\betaMain}{0.18}
\newcommand{\pMain}{< 0.001}
manuscript.tex
% in preamble: load all macros
\input{tables/results}

% in the text: use them
Our sample includes \nTotal{}
participants (mean age \meanAge{}).
The main effect was significant
($p \pMain{}$).

Option 2 One file per constant

Each value lives in its own .txt file containing nothing but the bare number. A single LaTeX macro reads any of them by path. The R side needs no LaTeX scaffolding at all.

R script → constants/sample_size.txt → \val{sample_size} → PDF
make_results.R
# === Write constants ===
cat(nrow(dt), file = "constants/sample_size.txt")
cat(round(mean(dt$age), 1),
    file = "constants/mean_age.txt")
cat(round(coef(model)["treatment"], 2),
    file = "constants/beta_main.txt")
manuscript.tex
% one macro to read any constant
\newcommand{\val}[1]{%
  \input{constants/#1.txt}\unskip}

% in the text
Our sample includes \val{sample_size}
participants (mean age \val{mean_age}).
The estimated effect was
$\hat{\beta} = \val{beta_main}$.

B — Figures

Figures are the most straightforward. Every plot is saved to disk by the script that creates it, and the manuscript includes the file. Most of you already do this; the point is that figures follow the same pattern as numbers and tables. Unless the underlying data is protected — plotted data may not leave the server — always save the exact data as plotted (after any subsetting, transformation, or aggregation) as a companion CSV next to the figure. Not the raw input; the final values that went into the plot. This makes replication possible and satisfies journals that require source data for figures. When the data cannot leave, the figure CSV is simply absent.

R script → figures/main_plot.csv + figures/main_plot.pdf → \includegraphics{...} → PDF
make_figures.R
# === Write figure data (as plotted, after transforms) ===
fig_data <- data.frame(label = labels, value = values)
write.csv(fig_data, "figures/main_plot.csv",
  row.names = FALSE)

# === Write figure ===
pdf("figures/main_plot.pdf", width = 7, height = 4.5)
barplot(values, names.arg = labels, ylab = "Outcome")
dev.off()
manuscript.tex
% ask AI: "wrap this includegraphics in a figure float"
\begin{figure}[t]
  \centering
  \includegraphics[width=\linewidth]{%
    figures/main_plot.pdf}
  \caption{Your caption.}
  \label{fig:main}
\end{figure}

C — Tables

Tables work the same way. Your script writes the whole tabular (column spec, rules, and rows) as a LaTeX fragment. The manuscript loads that fragment with \input, inside a table environment that handles the caption and label. The script decides how many columns it writes, so it also writes the column spec: add a column in R and the manuscript needs no change. With restricted data, disclosure rules may require minimum cell counts; build that suppression into your script.

Tools that generate table fragments (use a package when one fits your table):

  • R: modelsummary (regression tables), kableExtra, xtable, gt
  • Stata: esttab, outreg2
  • AI chatbots: for custom layouts no package covers. Ask for the LaTeX scaffolding, then you link each cell to your result variables

There is no value in a PhD student spending hours aligning {}, \mbox, and booktabs rules. That is machine work. Ask the AI for the table structure, then plug in your variable names. The prompt below shows what to ask.

R script → tables/descriptives.tex → \input{tables/descriptives} → PDF
make_tables.R (you write this)
# === Compute descriptives ===
desc <- aggregate(
  outcome ~ group, data = dt,
  FUN = function(x) c(
    N = length(x),
    Mean = round(mean(x), 2),
    SD = round(sd(x), 2))
)
desc <- do.call(data.frame, desc)
prompt to the chatbot
My R data frame `desc` has the columns
group (chr), outcome.N, outcome.Mean,
outcome.SD (all numeric). Write R code
that saves it to tables/descriptives.tex:
- the full tabular environment, booktabs
  rules, no table float, no caption
- headers: Group, N, Mean, SD
- N with thousands separator; Mean and
  SD to 2 decimals
- first line: % generated by
  make_tables.R; do not edit
- also save desc to
  tables/descriptives.csv
Read every value from `desc`;
hardcode nothing.
tables/descriptives.tex (generated)
% generated by make_tables.R; do not edit
\begin{tabular}{lrrr}
\toprule
Group & N & Mean & SD \\
\midrule
Control & 1,204 & 3.41 & 0.88 \\
Treated & 1,187 & 3.67 & 0.91 \\
\bottomrule
\end{tabular}
manuscript.tex
% ask AI: "wrap this \input in a table float"
\begin{table}[t]
  \centering
  \caption{Descriptive stats}
  \label{tab:desc}
  \input{tables/descriptives}
\end{table}

Audit trail

This is the part that saves you when a reviewer asks "where does this number come from?" Both workflows above already give you a trace. With a master results file, the results.csv records every macro, its value, and its data source. With one file per constant, the file path is the trace: constants/r2_gc.txt tells you the quantity; the script that wrote it tells you the rest.

Two things make this trace useful as the project scales.

Name your macros well

This costs nothing and does most of the work. One hard rule first: LaTeX \newcommand names can only contain letters (a–z, A–Z) — no digits, no underscores. If your R script generates a name like numRate2535 from a numeric variable, LaTeX will read it as the command \numRate plus literal text 2535 and throw a misleading error. Use words: \numRateYoung, \numRatePrime. Use a lookup table in R to replace digits with words before writing the macros.

A small project with five macros is fine with \nTotal and \meanAge. But when a project grows to dozens of constants across years and subgroups, a naming convention pays for itself. A pattern that works well: prefix + quantity + period + group.

A reviewer reading \numRatePreHoog in your manuscript source already knows what it is without opening any other file. And because the same name appears in both your R script and your .tex, a simple Ctrl+F on the name finds the source upstream in seconds. You do not need detailed source notes at every step — as long as the output file name links to a script upstream, the chain is traceable.

Principle: always reference results by name, not by position. Write coef(model)["treatment"], not coef(model)[4]. A numeric index breaks silently when the model changes; a name fails loudly or stays correct. The same principle applies to your file and directory names: do not add metadata for information already encoded in the organization. If the path says constants/ALZ/, you do not need a column that repeats disease = ALZ. Reserve extra metadata for what the structure cannot tell you: the data license, restrictions, ownership, or the date of the source data. Names like \val3 or \result_b give you neither traceability nor self-documentation.

Record the data source, not the R expression

In the companion CSV, the source column records the data file and variable, not the R expression: e.g., analysis.csv, col age or model 1, treatment. With one file per constant, the directory path itself is the source: constants/ALZ/r2_gc.txt. Both are machine-readable — agents can parse them to generate file manifests and documentation.

Example: tracing a number backward

Every displayed number traces backward to a CBS column (both examples come from the working example below). A direct value passes through unchanged; a derived value branches into its inputs:

Direct: "17,590,672" in the text, \popTotal{}
  ↑ fmt(17590672) ↑ df$TotaleBevolking_1
  ↑ filter: most recent year, 2022JJ00 ↑ cbs_get_data("37296ned")

Derived: "3,525,453" in the text, \popSenior{}
  ↑ 2672346 + 853107 = 3525453
  ↑ inputs: k_65Tot80Jaar_13 (2672346)
            k_80JaarOfOuder_14 (853107)

Every step carries its actual value. The only time you replace a value with a file pointer is when the data is protected. The goal: hand the reviewer a complete trace, 100% transparent, as far as data protection permits.

What an audit trail page looks like

The traces above can be generated as a standalone HTML page with expandable rows — one row per macro, table cell, and figure. Click any row to see its value, CBS source, script, and manuscript location. A companion CSV (audit-manifest.csv) makes the same data machine-readable.

Open the mini-example audit trail →

Scaling up: output-to-exhibit mapping

For a publication-grade replication package, the README maps every exhibit to the script that produced it. A referee or a replicator years later can trace any table, figure, or in-text constant back to exactly one program:

ExhibitEstimation scriptCollection script
Figure 1code/run_analysis.Rcode/make_figures.R
Table 1code/run_analysis.Rcode/make_tables.R
In-text constantscode/run_analysis.Rcode/make_results.R

A collection script copies all publication exhibits into a flat exhibits/ directory with standardized names (Figure_1a_row1_col1.pdf, Table_4.tex, constants/ALZ/r2_gc.txt). The final step: a verification script MD5-checks every text file against the author's reference output. Byte-identical files prove the pipeline reproduced the published numbers exactly.

You do not need the full mapping on day one. Good names and the companion CSV from the code patterns above are enough to start. The exhibit mapping and verification come when you submit to a journal that reviews replication packages. Each step is a natural extension of what you already have.


Working example: CBS open data

A minimal but complete project you can run on your own machine. One R script pulls publicly available data from CBS (Statistics Netherlands), computes a statistic, makes a figure and a table, and writes everything to disk. One LaTeX file reads it all and compiles to PDF. The whole thing is about 85 lines of R (plus 90 for the backtrace manifest) and 30 lines of LaTeX.

Project structure

mini-example/
  code/
    make_results.R       # pulls CBS data, produces everything
  tables/
    results.tex          # \newcommand macros (generated)
    results.csv          # audit trail (generated)
    tab_population.tex   # table body (generated)
    tab_population.csv   # table data (generated)
    manifest.csv         # backtrace for every number (generated)
  figures/
    fig_population.pdf   # figure (generated)
    fig_population.csv   # figure data as plotted (generated)
  manuscript.tex         # the paper

The R script

Show code/make_results.R (scaffolding written out in full)
code/make_results.R
#!/usr/bin/env Rscript
# Pull population data from CBS open data
library(cbsodataR)

# === Fetch data ===
raw <- cbs_get_data("37296ned")
raw <- raw[order(raw$Perioden), ]
raw <- raw[nrow(raw), , drop = FALSE]
yr  <- sub("JJ00", "", raw$Perioden)
df  <- as.data.frame(raw)

fmt <- function(x) formatC(x, format = "d", big.mark = ",")

# === Write inline numbers ===
pop_total   <- df$TotaleBevolking_1
pop_under20 <- df$JongerDan20Jaar_10
pop_senior  <- df$k_65Tot80Jaar_13 + df$k_80JaarOfOuder_14

macros <- c(
  "% generated by code/make_results.R; do not edit",
  sprintf("\\newcommand{\\popYear}{%s}", yr),
  sprintf("\\newcommand{\\popTotal}{%s}", fmt(pop_total)),
  sprintf("\\newcommand{\\popUnder}{%s}", fmt(pop_under20)),
  sprintf("\\newcommand{\\popSenior}{%s}", fmt(pop_senior))
)
writeLines(macros, "../tables/results.tex")

audit <- data.frame(
  macro  = c("popTotal", "popUnder", "popSenior"),
  value  = c(pop_total, pop_under20, pop_senior),
  source = c("CBS 37296ned, TotaleBevolking_1",
             "CBS 37296ned, JongerDan20Jaar_10",
             "CBS 37296ned, k_65Tot80Jaar + k_80JaarOfOuder")
)
write.csv(audit, "../tables/results.csv",
  row.names = FALSE)

# === Write table ===
age_labels <- c("Under 20", "20-40", "40-65", "65-80", "80+")
age_values <- c(
  df$JongerDan20Jaar_10, df$k_20Tot40Jaar_11,
  df$k_40Tot65Jaar_12, df$k_65Tot80Jaar_13,
  df$k_80JaarOfOuder_14)
rows <- sprintf("    %s & %s \\\\", age_labels, fmt(age_values))
tab <- c(
  "\\begin{tabular}{@{}lr@{}}",
  "  \\toprule",
  "  Age group & Population \\\\",
  "  \\midrule",
  rows,
  "  \\bottomrule",
  "\\end{tabular}")
writeLines(tab, "../tables/tab_population.tex")
write.csv(data.frame(age_group = age_labels, population = age_values),
  "../tables/tab_population.csv", row.names = FALSE)

# === Write figure ===
pdf("../figures/fig_population.pdf", width = 6, height = 4)
par(mar = c(5, 5, 3, 1))
barplot(age_values / 1e6, names.arg = age_labels,
  main = paste("Population by age group, Netherlands", yr),
  ylab = "Population (millions)",
  col = "steelblue", border = NA,
  axes = FALSE,
  ylim = c(0, ceiling(max(age_values / 1e6))),
  yaxs = "i", space = 0.5)
axis(2, las = 1)
box(bty = "l")
dev.off()
write.csv(data.frame(age_group = age_labels,
    population = age_values),
  "../figures/fig_population.csv", row.names = FALSE)

# === Write backtrace manifest ===
# traces every number in the PDF back to CBS source
# (see full script for implementation)
# output: ../tables/manifest.csv (54 rows)

The manuscript

manuscript.tex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx, booktabs}
\usepackage[margin=1in]{geometry}
\usepackage{microtype}

% load all computed values
\input{tables/results}

\begin{document}

\section*{Programmatic manuscript --- mini example}
The total population of the Netherlands
in \popYear{} was \popTotal{}
(CBS StatLine, table 37296ned).
Of these, \popUnder{} were under~20
and \popSenior{} were 65 or older.

\begin{table}[h]
  \centering
  \caption{Population by age group, \popYear{}.}
  \input{tables/tab_population}
\end{table}

\begin{figure}[h]
  \centering
  \includegraphics[width=0.75\linewidth]{%
    figures/fig_population.pdf}
  \caption{Population by age group, \popYear{}.
    Source: CBS StatLine (table 37296ned).}
\end{figure}

\end{document}

Build it

# === Step 1: run the analysis ===
cd code
Rscript make_results.R

# === Step 2: compile the paper ===
cd ..
latexmk -pdf manuscript.tex

That is it. When CBS publishes a new year, re-run both commands (the script always takes the most recent year), and every number, table, and figure in the PDF updates.

The compiled PDF contains every number, the table, and the figure — all produced by the R script and read from files. Even the year (2022) was computed, not typed.

Backtrace: where does each number come from?

The same script that produces the results also produces a manifest — a CSV that traces every number in the PDF backward to its CBS source, with the value at each step. This is what you hand a reviewer alongside the paper. The manifest is generated by the code, not written by hand.

Here are four rows from manifest.csv, one for each result type. Read from step 1 (displayed) to the highest step (raw source):

Direct inline number: \popTotal{} → "17,590,672"

StepLabelValueExpressionSource
1display17,590,672fmt(17590672)
2extract17590672df$TotaleBevolking_1
3filter17590672most recent year: 2022JJ00
4fetch17590672cbs_get_data("37296ned")CBS 37296ned
5raw_column17590672TotaleBevolking_1CBS 37296ned

Derived inline number: \popSenior{} → "3,525,453" (chain branches at step 3)

StepLabelValueExpressionSource
1display3,525,453fmt(3525453)
2compute35254532672346 + 853107
3input_65to802672346df$k_65Tot80Jaar_13CBS 37296ned
3input_80plus853107df$k_80JaarOfOuder_14CBS 37296ned

Table cell: "Under 20" row → "3,737,817"

StepLabelValueExpressionSource
1display3,737,817fmt(3737817)
2extract3737817df$JongerDan20Jaar_10
3fetch3737817cbs_get_data("37296ned")CBS 37296ned
4raw_column3737817JongerDan20Jaar_10CBS 37296ned

Figure bar: "Under 20" bar → 3.738 million

StepLabelValueExpressionSource
1display3.738 M3737817 / 1e6
2extract3737817df$JongerDan20Jaar_10
3raw_column3737817JongerDan20Jaar_10CBS 37296ned

The full manifest.csv (54 rows) covers every inline macro, every table cell, and every figure bar. It is produced by the same make_results.R script that generates the results — one script, one run, all outputs including the backtrace. For protected data, replace values with file pointers; the structure stays the same.


Secure research environments

In practice, many of us run the analysis inside a secure research environment — a trusted research environment (TRE), remote data environment (RDE), or similar closed platform such as the CBS microdata environment or the UK Biobank RAP — where you cannot compile LaTeX. The results come out as files after disclosure review. The workflow still works; the only difference is that you upload result files to Overleaf instead of compiling locally.

The flow

Protected environment
Run R scripts → generate results.tex, results.csv, tables/*.tex, figures/*.pdf
↓ disclosure review & export
Your local machine
Receive exported files: results.tex, tables/*.tex, figures/*.pdf
↓ upload files to Overleaf
Overleaf
Replace tables/ and figures/ folders → recompile → every number updates

The key difference from the manual approach: you are uploading generated result files, not hand-typed numbers. The manuscript still reads everything via \input and \includegraphics. One folder replacement in Overleaf updates the entire paper.

What this looks like in practice

Inside the secure research environment
# === Run analysis (same scripts as local) ===
Rscript make_results.R
Rscript make_tables.R
Rscript make_figures.R

# === Output folder after running ===
output/
  tables/results.tex      # macros
  tables/results.csv      # audit trail
  tables/descriptives.tex # table body
  figures/main_plot.pdf   # figure

# Request export of output/ folder
On Overleaf
Your Overleaf project structure:
manuscript.tex   # unchanged
tables/
  results.tex    # ← replace with export
  descriptives.tex
figures/
  main_plot.pdf  # ← replace with export

Upload the exported tables/ and figures/
folders. Overleaf recompiles. Done.

The \input{} and \includegraphics{}
commands pick up the new files
automatically.

When analysis and manuscript live in different places, this preserves the automated chain. The only manual step is the file upload to Overleaf, and that replaces files, not individual numbers.


D — Bibliography management

References are the fourth type of result in your paper, and they follow the same principle: a .bib file is the single source of truth. You should never type a reference by hand into the manuscript. Here are three ways to build your .bib file.

Three ways to get .bib entries

1. CrossRef API (fastest for a DOI)

If you have a DOI, you can get a formatted BibTeX entry in one command. The CrossRef API is free and requires no account.

# From the terminal: get a .bib entry by DOI
curl -sLH "Accept: application/x-bibtex" \
  https://doi.org/10.1038/s41588-018-0147-3

# Or in R:
bib_entry <- rcrossref::cr_cn(
  "10.1038/s41588-018-0147-3",
  format = "bibtex")
cat(bib_entry)

Paste the output into your .bib file. The entry key, authors, title, journal, year, and DOI are all filled in automatically.

2. Google Scholar / database export

Most databases (Google Scholar, PubMed, Web of Science) can export citations. Look for an export button that offers BibTeX (.bib) directly. If only RIS (.ris) is available, convert it:

# === RIS to BibTeX ===
# Zotero (drag and drop) or ris2bib:
pip install ris2bib
ris2bib exported.ris > new_entries.bib

3. Reference manager (Zotero)

Zotero collects references as you browse. Its Better BibTeX plugin auto-exports your library to a .bib file that stays in sync. Point your manuscript at that file.

% in your LaTeX preamble (with BibLaTeX):
\usepackage[backend=biber]{biblatex}
\addbibresource{bibliography.bib}

% or with classic BibTeX:
\bibliographystyle{apalike}
\bibliography{bibliography}

The principle is the same: the .bib file is a plain-text database. You cite by key (\cite{okbay2022}), and the compiler resolves it to a formatted reference. Add entries to the file once, and they are available in every manuscript that points to it.

For the writing itself, the Academic Phrasebank (Morley, 2023; University of Manchester) is a useful reference. It collects commonly used phrasal elements in academic English, organized by section of a paper (introduction, methods, results, discussion). Available as a free PDF.


Overleaf

Most collaborators use Overleaf. Set up a folder structure where result files can be swapped in with a single upload.

Option A: Start from a blank project

Create a new blank project on Overleaf. Add folders tables/ and figures/. Copy the template below into main.tex.

Option B: Upload a zip

Set up the folder structure locally, zip it, and use New Project → Upload Project on Overleaf. This is faster for projects with existing result files.

Starter template

Copy this into your Overleaf project as main.tex. It is ready for the automated workflow: result macros load from tables/results.tex, tables from fragments in tables/, and figures from figures/.

main.tex (copy to Overleaf)
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage[backend=biber, style=apa]{biblatex}
\addbibresource{bibliography.bib}

% === Load computed results ===
% Option 1: master results file with \newcommand macros
\input{tables/results}

% Option 2 (alternative): one file per constant
% \newcommand{\val}[1]{\input{constants/#1.txt}\unskip}

\title{Your Paper Title}
\author{Your Name}
\date{\today}

\begin{document}
\maketitle

\section{Introduction}
Your introduction here. Cite with \textcite{key2024}
or \parencite{key2024}.

\section{Results}
% Use macros from results.tex:
Our sample includes \nTotal{} participants
(mean age \meanAge{}).

% Include a generated table:
\begin{table}[h]
  \centering
  \caption{Descriptive statistics}
  \label{tab:desc}
  \input{tables/descriptives}
\end{table}

% Include a generated figure:
\begin{figure}[h]
  \centering
  \includegraphics[width=0.8\linewidth]{%
    figures/main_plot.pdf}
  \caption{Your figure caption.}
  \label{fig:main}
\end{figure}

\section{Discussion}
Your discussion here.

\printbibliography
\end{document}

Overleaf project structure

your-project/
  main.tex               # the template above
  bibliography.bib       # your references
  tables/
    results.tex          # ← upload from analysis
    descriptives.tex     # ← upload from analysis
  figures/
    main_plot.pdf        # ← upload from analysis

When you re-run your analysis, export the new tables/ and figures/ files and upload them to Overleaf, replacing the old ones. Overleaf recompiles, and every \input and \includegraphics picks up the updated files.


Bonus: good habits that come free

Once you work programmatically, these cost nothing extra:

  • Paper title in one file — define it once as a \newcommand, use in the manuscript, figure titles, and headers. Change it in one place.
  • URLs and DOIs in variables — a data source URL used in text, footnotes, and the README lives in one macro, not copy-pasted three times.
  • Year or period as a variable — change one value, every caption and in-text reference updates.
  • Formatting function defined once — fmt() or nlt() ensures consistent number formatting across all outputs.
  • Git diff as revision log — you see exactly what changed between drafts. No track-changes chaos, no emailing files.
  • One config, multiple outputs — swap a dataset ID or a model specification, re-run, everything regenerates.
  • Hot-swap tables, figures, and chapters — replace a .tex fragment, a .pdf figure, or even a full chapter file, recompile, and see the difference instantly. Compare model specifications or robustness checks side by side.

What to learn next

Programmatic paper checklist

Set this up at the start. Retrofitting is harder.