I have and extensive database with references in form of an SQL database. How can I use this information in BibTeX?
[Tex/LaTex] Is it possible to use sql database for BibTeX
bibtexdatabase
Related Solutions
You can modify the bibliography style (.bst
) to achieve your goal. However, is a laborious task, and may be error prune.
So, lets say you have the plain.bst
style. Then you just need to find the FUNCTION {article}
, FUNCTION {book}
, and so on. In general, you need to modify each FUNCTION {<entry>}
that you want to use in your bibliography, and remove the undesired fields from there.
Like this example
FUNCTION {article}
{ output.bibitem
format.authors "author" output.check
new.block
format.title "title" output.check
% new.block
% crossref missing$
% { journal emphasize "journal" output.check
% format.vol.num.pages output
% format.date "year" output.check
% }
% { format.article.crossref output.nonnull
% format.pages output
% }
% if$
% new.block
% note output
fin.entry
}
the commented parts are the ones that will get removed from the final part. And you can save the modified style, let's say myplain.bst
and use it like:
\documentclass{standalone}
\usepackage{cite}
\usepackage{filecontents}
\begin{filecontents}{mybib.bib}
@ARTICLE{Bar2011,
author = {F. Foo and F. Bar},
title = {Foo and Bar},
journal = {Journal of Foo},
year = {2011},
volume = {1},
pages = {1--3}
}
@ARTICLE{Foo2011,
author = {F. Foo and F. Bar},
title = {More on Foo and Bar},
journal = {Journal of Bar},
year = {2011},
volume = {1},
pages = {1--3},
owner = {adin},
timestamp = {2011.12.01}
}
\end{filecontents}
\begin{document}
Test~\cite{Bar2011,Foo2011}.
%\bibliographystyle{plain}
\bibliographystyle{myplain}
\bibliography{mybib}
\end{document}
Minimal (using myplain.bst
):
Full (using plain.bst
):
Unless you know how to write in bibtex's stack-based language, I wouldn't recommend doing it that way. If you just want to use TeX tools without relying on external scripts, you can use datatool
. Here's an example:
\documentclass{article}
\usepackage{datatool}
\begin{filecontents*}{test.csv}
Object,Edible,Color,Size
Apple,yes,green,small
Cat,no,brown,medium
Aardvark,no,grey,medium
\end{filecontents*}
\DTLloaddb{mydata}{test.csv}
% Define a command to access a field in `mydata' in the row identified by a
% given object:
% Syntax: \field{object}{column label}
\newcommand{\field}[2]{%
\dtlgetrowforvalue{mydata}{\dtlcolumnindex{mydata}{Object}}{#1}%
\dtlgetentryfromcurrentrow{\thisvalue}{\dtlcolumnindex{mydata}{#2}}%
\thisvalue
}
% Syntax: \boolfield{object}{column label}{true part}{false part}
\newcommand{\boolfield}[4]{%
\dtlgetrowforvalue{mydata}{\dtlcolumnindex{mydata}{Object}}{#1}%
\dtlgetentryfromcurrentrow{\thisvalue}{\dtlcolumnindex{mydata}{#2}}%
\DTLifstringeq{\thisvalue}{yes}{#3}{#4}%
}
\begin{document}
List the data in a tabular environment:
\DTLdisplaydb{mydata}
Sort on `Object' column.
\DTLsort{Object}{mydata}
List sorted data in a tabular environment:
\DTLdisplaydb{mydata}
Access data: an apple is \field{Apple}{Size} and \field{Apple}{Color}.
It \boolfield{Apple}{Edible}{is}{isn't} edible.
Access data: a cat is \field{Cat}{Size} and \field{Apple}{Color}.
It \boolfield{Cat}{Edible}{is}{isn't} edible.
\end{document}
The above example produces:
(I suggest putting \DTLdisplaydb
inside a table
or use \DTLdisplaylongdb
if it's longer than a page.)
Best Answer
Nelson Beebe gave a talk at TUG 2009 on using SQL databases for bibliographic purposes as a replacement for BibTeX. The program is bibsql and looks very promising, but I haven't used it myself.
You can read more details and examples in his paper in TUGboat 30(2).