Welcome to academic-ads-bibtex
documentation!¶
Introduction¶
The Hugo Academic admin tool
allows for the ingestion of BibTeX records to add to the publication list.
One easy solution is to use the NASA ADS
to retrieve such records from a
NASA ADS Library.
However, such records often contain LaTeX \newcommand
. For example:
@ARTICLE{2016ApJS..226....5L,
author = {{Ly}, C. and {Malhotra}, S. and {Malkan}, M.~A. and {Rigby}, J.~R. and
{Kashikawa}, N. and {de los Reyes}, M.~A. and {Rhoads}, J.~E.
},
title = "{The Metal Abundances across Cosmic Time (MACT) Survey. I. Optical Spectroscopy in the Subaru Deep Field}",
journal = {\apjs},
archivePrefix = "arXiv",
eprint = {1602.01089},
keywords = {galaxies: abundances, galaxies: distances and redshifts, galaxies: evolution, galaxies: ISM, galaxies: photometry, galaxies: star formation},
year = 2016,
month = sep,
volume = 226,
eid = {5},
pages = {5},
doi = {10.3847/0067-0049/226/1/5},
adsurl = {https://ui.adsabs.harvard.edu/abs/2016ApJS..226....5L},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}
Here, the journal name is simplified to \apjs
. This ends up propagating into
Hugo Academic sites. To fix this, this simple pure Python script will convert
such aliases into the full journal names. It uses a journal database to
conduct the replacement.
Installation¶
But first, we recommend creating a separate (virtual) environment to
avoid any possible conflicts with existing software that you used.
Instructions are provided for conda
and virtualenv
.
From PyPi¶
Using conda
:
(base) $ (sudo) conda create -n bibtex python=3.7
(base) $ conda activate bibtex
(bibtex) $ (sudo) pip install academic-ads-bibtex
Using virtualenv
:
(base) $ (sudo) conda install virtualenv # if not installed
(base) $ mkdir academic-ads-bibtex
(base) $ cd academic-ads-bibtex
(base) $ virtualenv venv
(base) $ source venv/bin/activate
(venv) $ pip install academic-ads-bibtex
From Source¶
Using conda
:
(base) $ (sudo) conda create -n bibtex python=3.7
(base) $ conda activate bibtex
(bibtex) $ git clone https://github.com/astrochun/academic-ads-bibtex.git
(bibtex) $ cd academic-ads-bibtex
(bibtex) $ (sudo) python setup.py install
Using virtualenv
:
(base) $ (sudo) conda install virtualenv # if not installed
(base) $ git clone https://github.com/astrochun/academic-ads-bibtex.git
(base) $ cd academic-ads-bibtex
(base) $ virtualenv venv
(base) $ source venv/bin/activate
(venv) $ python setup.py install
Examples¶
The primary script to execute is academic_ads_bibtex. The above installation will include this executable in your python environment paths.
Execution requires only one argument, which is the full path to the BibTeX
file. It can be provided with the -f
or --filename
command-line flag.
$ academic_ads_bibtex -f /full/path/to/my_pubs.bbl
By default:
The code uses the repository-based journal database, bibtex_journals.db. This can be changed by specifying the
-d
or--db_filename
command-line flag.The revised BibTeX file will be based on the input
filename
with the prefix changed to include_revised
. For example, for the above case, the output file will be/full/path/to/my_pubs_revised.bbl
. This can be changed by specifying the-o
or--out_filename
command-line flag.
A log file is constructed: /full/path/to/academic_ads_bibtex.YYYY-MM-DD.log
License¶
This project is licensed under the GNU GPLv3 License. See the LICENSE file for details.
API Documentation¶
academic-ads-bibtex package¶
The class
that is frequently used for this package is converter.Convert
Submodules¶
academic_ads_bibtex.converter module¶
-
class
academic_ads_bibtex.converter.
Convert
(filename, db_filename, out_filename, log=None)¶ Bases:
object
Main class to perform BibTeX conversion for Academic compatibility
- Parameters
filename (
Union
[str
,Path
]) – BibTeX filedb_filename (
Union
[str
,Path
]) – Journal database fileout_filename (
Union
[str
,Path
]) – Modified BibTeX filelog – LogClass or logger object
- Variables
bibtex_content (str) – BiBTeX content (from
import_file
method)db_dict (dict) – Journal database dict (from
import_database
method)bibtex_revised (str) – BibTeX content (from
replace
method)
-
import_database
()¶ Import journal database file
- Return type
dict
-
import_file
()¶ Import BibTeX file
- Return type
str
-
replace
()¶ Replace journal abbreviations
- Return type
str
-
write_file
()¶ Write revised BibTeX file
academic_ads_bibtex.logger module¶
-
class
academic_ads_bibtex.logger.
LogClass
(logfile)¶ Bases:
object
Main class to log information to stdout and ASCII logfile.
Note: Logging level is set to DEBUG for file and INFO for stdout
- To use:
log = LogClass(logfile).get_logger()
- Parameters
logfile (
Union
[str
,Path
]) – Filename for log file
-
get_logger
()¶ - Return type
Logger
-
academic_ads_bibtex.logger.
log_stdout
()¶ Stdout logging
- Return type
Logger