Last active
March 27, 2017 06:01
-
-
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).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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