Skip to content

Instantly share code, notes, and snippets.

@cgranade
Last active March 27, 2017 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgranade/2cb79d1f457162f2c3af9a42ad5dc007 to your computer and use it in GitHub Desktop.
Save cgranade/2cb79d1f457162f2c3af9a42ad5dc007 to your computer and use it in GitHub Desktop.
Check a BibTeX bibliography to make sure everything is properly linked (DOI, ISBN or arXiv).
ipmo posh-tex
function ConvertFrom-BibTeX {
param(
[string] $Path
)
$bibDB = Invoke-Python @"
import bibtexparser
import json
with open(r"$Path") as bibtex_file:
bib_db = bibtexparser.load(bibtex_file)
print(json.dumps(bib_db.entries))
"@ | ConvertFrom-Json;
foreach ($bibItem in $bibDB) {
$bibItem | Write-Output
}
}
function Get-CitedKeys {
param([string] $Path)
(
Select-String -Path $Path -Pattern "\\citation\{([\w\-\:\,]*)\}" |
% { $_.Matches.Groups[1].Value -split "," } | Sort-Object | Get-Unique
)
}
function Confirm-Citations {
param([string] $AuxPath, [string] $BibPath)
$citedKeys = Get-CitedKeys $AuxPath;
ConvertFrom-BibTeX $BibPath | ? {($_.ID -in $citedKeys) -and -not ($_.DOI -or $_.ISBN -or ($_.link -match ".*arxiv\.org.*"))}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment