Skip to content

Commit

Permalink
Add bibtags
Browse files Browse the repository at this point in the history
  • Loading branch information
dspinellis committed Apr 5, 2022
1 parent d5f242f commit 26b8a88
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
NAME=bibget
BIBGET=bibget
BIBTAGS=bibtags

PREFIX?=/usr/local
INSTALL?=install

.PHONY: all install

all:
perl -c $(NAME).pl
perl -c $(BIBGET).pl
sh -n $(BIBTAGS).sh

install:
install $(NAME).pl $(PREFIX)/bin/$(NAME)
install $(BIBGET).pl $(PREFIX)/bin/$(BIBGET)
install $(BIBTAGS).sh $(PREFIX)/bin/$(BIBTAGS)
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# bibget: Extract BibTeX records to standalone file
# Bibtools: Tools for working with BibTeX bibliography files
This repository hosts simple tools I've developed for working
with BibTeX bibliography files.
They help sharing references with co-authors and navigating to
bibliography entries from the editor.
See also the
[advice for working with LaTeX](https://github.com/dspinellis/latex-advice)
repository.

## Installation
Run `make install` to install the files in the `/usr/local/bin` directory.
If you lack administrator privileges or want to install the files
in a different directory, specify it as the `PREFIX` variable
when running _make_, e.g. `make PREFIX=$HOME` or `make PREFIX=/usr` to
install the files in `$HOME/bin` or `/usr/bin`, respectively.
To execute the programs ensure that the installation directory
is in your `PATH`.

## bibget: Extract BibTeX records to standalone file

The _bibget_ tool will process LaTeX `.aux` or `.bcf` files,
and use the data found there to output the required BibTeX records into
Expand All @@ -10,7 +28,7 @@ personal collection of BibTeX records.
Here is how the same LaTeX file can use both the personal BibTeX files
and the shared generated one.

## BibTeX
### BibTeX
Use the following in place of the `\bibliography` command.

```.tex
Expand All @@ -31,7 +49,7 @@ latex '\let\mypubs\relax \include{file}'
bibget file.aux >shared-refs.bib
```

## Biber
### Biber
Use the following in place of the `\addbibresource` commands.

```.tex
Expand All @@ -57,3 +75,12 @@ bibget file.bcf >shared-refs.bib
```

(Under the Windows `cmd32` shell replace the single quotes with double quotes.)

## bibtags: Create a vim/vi/Emacs tags file for bibliography records

The _bibtags_ tool will process the specified `.bib` files,
and will create in the current directory a file named `tags`,
which allows the quick navigation to bibliography entry from
your editor.
For example, in _vim_ you can do this by pressing `^]`,
when the cursor is on the entry's field.
36 changes: 36 additions & 0 deletions bibtags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
#
# Create an editor tags file out of the specified .bib files
#
# Copyright 1992-2022 Diomidis Spinellis
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

set -euo pipefail

if [ -z "$1" ] ; then
echo "Usage: $0 file ..." 1>&2
exit 1
fi

awk '
BEGIN { seen[""] = seen["\r"] = 1 }
/^@/ && !seen[$2] {
gsub("\r", "")
seen[$2] = 1
printf "%s\t%s\t?^%s?\n", $2, FILENAME, $0}' \
FS='[,{ (]*' "$@" |
LC_ALL=C sort >tags

0 comments on commit 26b8a88

Please sign in to comment.