bibtex/init.lua |
|
---|---|
The bibtex module for the Textadept editor. It provides helpers for editing BibTeX files and inserting items in LaTeX or ConTeXt files. The source is on GitHub, released under the MIT license. InstallationClone the git repository to your
UsageYou can load this module in your LaTeX or ConTeXt module, define the
locations of your BibTeX files and include it in snippets.
To only add a key you could assign
|
local M = {}
|
Fields |
|
_M.bibtex.files: A table with BibTeX files. |
M.files = {}
|
_M.bibtex.references: A table with references and their BibTeX key. |
M.references = {}
|
Commands |
|
Try to read entries from a BibTeX file. Author, year and title are
joined for an entry in the |
local function parse_entries(filename)
file = io.open(filename, 'rb')
bibentries = file:read('*all')
file:close()
for bibentry in bibentries:gmatch('@.-\n}\n') do
key = bibentry:match('@%w+{(.-),') or ''
author = bibentry:match('author%s*=%s*["{]*(.-)["}],?')..', ' or ''
year = bibentry:match('year%s*=%s*["{]?(%d+)["}]?,?')..', ' or ''
title = bibentry:match('title%s*=%s*["{]*(.-)["}],?') or ''
M.references[#M.references + 1] = author..year..title
M.references[#M.references + 1] = key
end
end
|
Read BibTeX entries from the files listed in the |
local function read_bibfiles()
references = {}
for _, bibfile in ipairs(M.files) do
parse_entries(bibfile)
end
end
|
Present a filtered list dialog and return the BibTeX key of the selected entry. |
function M.select_reference()
if #M.files > 0 and #M.references == 0 then
read_bibfiles()
end
if #M.references > 0 then
local status, item = ui.dialogs.filteredlist{
title='References',
columns={'Reference', 'Key'},
items=M.references,
string_output=true,
['output-column']=2,
width=900
}
if item then
return item -- the BibTeX key
end
end
end
|
Snippets |
|
Container for BibTeX-specific snippets. |
snippets.bibtex = {
['@'] = [[
@%1(article){%2(key),
author = {%3},
title = {%4},
publisher = {%5},
year = {%6},
}
]]
}
return M
|