# .latexmkrc.example - Bibliography filtering integration for latexmk
#
# This configuration runs filter_bibliography.py to include only
# cited references in your bibliography.
#
# filter_bibliography.py uses only Python standard library (no pip dependencies),
# making it ideal for Overleaf and restricted environments.
#
# RECOMMENDED: Use the END block approach for Overleaf (works with pdfLaTeX compiler).
#
# Usage:
#   1. Copy this file to your project as '.latexmkrc'
#   2. Copy filter_bibliography.py to your project
#   3. Adjust BIB_FILE name(s) below
#   4. Recompile - refs_filtered.bib appears in your file list!
#
# Requirements:
#   - filter_bibliography.py: Python 3 only (no dependencies - works on Overleaf!)

# ==============================================================================
# Configuration - Adjust these for your project
# ==============================================================================

# Path to filter script
$FILTER_SCRIPT = 'filter_bibliography.py';

# Your bibliography file(s) - space-separated for multiple files
# Multiple files are merged; duplicates cause an error.
$BIB_FILES = 'references.bib';              # Single file
# $BIB_FILES = 'refs1.bib refs2.bib';       # Multiple files

# Output filtered bibliography
$BIB_FILTERED = 'refs_filtered.bib';

# ==============================================================================
# Latexmk settings
# ==============================================================================

# Use pdflatex by default
$pdf_mode = 1;

# Enable bibtex when needed
$bibtex_use = 2;

# ==============================================================================
# RECOMMENDED: END block approach (works on Overleaf with pdfLaTeX!)
# ==============================================================================
# This runs the filter AFTER compilation completes.
# The filtered .bib file appears in your Overleaf file list for download.
#
# NOTE: Keep your original \bibliography{references} in your .tex file.
# The filtered file is created as an output artifact.

END {
  system("python3 $FILTER_SCRIPT . -b $BIB_FILES -o $BIB_FILTERED -r --no-warn-missing");
}

# ==============================================================================
# ALTERNATIVE: Pre-bibtex hook (requires changing \bibliography{})
# ==============================================================================
# If you want to USE the filtered bibliography during compilation,
# uncomment ONE of these and update your .tex file accordingly.
#
# For natbib: Change \bibliography{references} to \bibliography{refs_filtered}
# $bibtex = "python3 $FILTER_SCRIPT %R.tex -b $BIB_FILES -o $BIB_FILTERED --no-warn-missing && bibtex %O %B";
#
# For biblatex: Change \addbibresource{references.bib} to \addbibresource{refs_filtered.bib}
# $biber = "python3 $FILTER_SCRIPT %R.tex -b $BIB_FILES -o $BIB_FILTERED --no-warn-missing && biber %O %S";

# ==============================================================================
# Overleaf Quick Setup (pdfLaTeX compiler)
# ==============================================================================
#
# 1. Upload filter_bibliography.py to your Overleaf project
#
# 2. Create '.latexmkrc' with:
#
#    # Single bib file:
#    END {
#      system("python3 filter_bibliography.py . -b references.bib -o refs_filtered.bib -r --no-warn-missing");
#    }
#
#    # Multiple bib files:
#    END {
#      system("python3 filter_bibliography.py . -b refs1.bib refs2.bib -o refs_filtered.bib -r --no-warn-missing");
#    }
#
# 3. Recompile - refs_filtered.bib appears in your file list!
