summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luabibentry/luabibentry.dtx
blob: 55db6496d7d67d508cfa95da08ed037b7ee21377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
% \iffalse meta-comment
% ==========================================================================
% luabibentry.dtx v0.1a, 2012/02/02
% Copyright (c) Oliver Kopp, 2012
%
% This file is part of the LuaLaTex package `luabibentry'.
% 
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX 
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer and author of this work is Oliver Kopp.
%
% This work consists of the files `luabibentry.dtx' and `README'.
%
% Unpacking:
%   tex luabibentry.dtx
% Documentation:
%   pdflatex luacode.dtx
% ==========================================================================
%
%<*ignore>
\begingroup
  \def\x{LaTeX2e}%
\expandafter\endgroup
\ifcase 0\ifx\install y1\fi\expandafter
         \ifx\csname processbatchFile\endcsname\relax\else1\fi
         \ifx\fmtname\x\else 1\fi\relax
\else\csname fi\endcsname
%</ignore>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
{
\obeyspaces\obeylines
\global\def\preambletext{
\space
Copyright (c) 2012 by Oliver Kopp <oliver.kopp.googlemail.com>

This file was generated from file(s) of luabibentry distribution.
-----------------------------------------------------------------

This work may be distributed and/or modified under the conditions of
the LaTeX Project Public License, version 1.3c of the license.
The latest version of this license is in
  http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of LaTeX
version 2005/12/01 or later.

This work has the LPPL maintenance status "maintained".

The Current Maintainer and author of this work is Oliver Kopp.

This file may only be distributed together with the files listed in
`luabibentry.dtx'. You may however distribute the files listed in 
`luabibentry.dtx' without this file.
}
\global\def\stypreambletext{
\preambletext
Usage:

\string\setupbibentry{<bibliography>} before the usage of \string\bibentry.
\string\setupbibentry{\string\jobname} may be used if the bibliography has the same name as the .tex file.

\string\bibentry{<entry>} where you want to have placed an entry.
In case an entry is not found "?" is output
}
}
%
\expandafter\preamble
\preambletext
\endpreamble
%
\declarepreamble\stypreamble
\stypreambletext
\endpreamble
%
\def\BibTeXComment{@Comment }
\let\MetaPrefix\BibTeXComment
\declarepreamble\bibpreamble
\preambletext
\endpreamble
%
\def\ThreeHyphens{---}
\let\MetaPrefix\ThreeHyphens
%
\expandafter\declarepreamble\expandafter\luapreamble
\preambletext
\endpreamble

\generate{%
  \let\MetaPrefix\DoubleperCent
  \usepreamble\defaultpreamble
  \file{test-luabibentry.tex}{\from{luabibentry.dtx}{testlatex}}%
%
  \let\MetaPrefix\DoubleperCent
  \usepreamble\stypreamble
  \file{luabibentry.sty}{\from{luabibentry.dtx}{package}}%
%
  \let\MetaPrefix\BibTeXComment
  \usepreamble\bibpreamble
  \nopostamble
  \file{test-luabibentry.bib}{\from{luabibentry.dtx}{testbibtex}}%
%
  \let\MetaPrefix\ThreeHyphens
  \usepreamble\luapreamble
  \nopostamble
  \file{luabibentry.lua}{\from{luabibentry.dtx}{lua}}%
}
{
\obeyspaces
\Msg{************************************************************************}
\Msg{*}
\Msg{* To finish the installation you have to move the following}
\Msg{* files into a directory searched by TeX:}
\Msg{*}
\Msg{*     luabibentry.sty and luabibentry.lua}
\Msg{*}
\Msg{* Happy TeXing!}
\Msg{*}
\Msg{************************************************************************}
}

%\csname endinput\endcsname
\endbatchfile
%</install>
%<package>\NeedsTeXFormat{LaTeX2e}[1995/06/01]
%<package>\ProvidesPackage{luabibentry}
%<driver>\ProvidesFile{luaindex.dtx}
%<*driver|package>
[2012/02/02 v0.1a LuaLaTeX Package to place bibliography entries in text]
%</driver|package>
%<lua>if (luatexbase and (luatexbase.provides_module)) then
%<lua>   luatexbase.provides_module({
%<lua>      name = "luabibentry",
%<lua>      date = "2012/02/02",
%<lua>      version = "0.1a",
%<lua>      description = "LuaLaTeX Package to Place Bibliography Entries in Text",
%<lua>      author = "Oliver Kopp",
%<lua>      licence = "LPPL v1.3c or later"
%<lua>  })
%<lua>end
%<*ignore>
\fi
%</ignore>
%<*driver>
\documentclass[oneside,DIV=16,BCOR=0cm,parskip=half]{scrdoc}
\usepackage[english]{babel}
\usepackage{hyperref}
\providecommand*{\LuaLaTeX}{Lua\kern-.025em\LaTeX}
\CodelineIndex
\RecordChanges
\GetFileInfo{luabibentry.ltx}
\title{%
  The \texttt{luabibentry} package
}
%\date{\fileversion} %currently doesn't work
\date{Version 0.1a as of 2012/02/02}
\author{Oliver Kopp\thanks{oliver.kopp%
@%
googlemail%
.%
com}}
\begin{document}
\maketitle
\DocInput{luabibentry.dtx}
\end{document}
%</driver>
%\fi^^A meta-comment
%
% \changes{v0.1}{2011/06/27}{start of new package}
% \changes{v0.1a}{2012/02/02}{fixed lua code to use `require' instead of `dofile'.}
%
% \begin{abstract}
%   Typically, bibliographic entries are put at the end of a document. This 
%   package allows for \emph{repeating} bibliographic entries in the document itself. The package
%   is inspired by bibentry, which provides similar functionality for \LaTeX{}.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
% This package allows one to place bibliographic entries anywhere
% in the text. It is to be used to produce annotated bibliographies, such as
% \begin{quote}
%   For an intoduction to the topic of workflow management, see 
%   Frank Leymann and Dieter Roller. {\it Production Workflow -- Concepts and Techniques}. 
%   Prentice Hall PTR, 2000.
% \end{quote}
%
% The idea is that the full reference is used, not just the citation [1] or
% Leymann and Roller [2000].
%
% This package is a variant of bibentry.sty by Patrick W.\ Daly. bibentry.sty is
% distributed with the natbib
% package\footnote{\url{http://mirror.ctan.org/macros/latex/contrib/natbib/}}. This
% documentation of luabibentry is mostly adapted from Patrick's documentation of
% bibentry. bibentry itself is part of the natbib package.
%
% The main reason for the reimplementation is the incompatibility of hyperref's
% backref with bibenetry.sty. The \texttt{\textbackslash saved \makeatletter
% @\makeatother bibitem} solution did not work here.
% 
% The differences to bibentry.sty is: 
% The commands |\nobibliography| and |\nobibliography*|
% are unsupported. luabibentry always uses the bibliography of the
% document.
%
% \section{Usage}
% |\setupbibentry{<bibliography>}| before the usage of |\bibentry|.\\
% |\setupbibentry{\jobname}| may be used if the bibliography has the same name as the |.tex| file.
%
% |\bibentry{<entry>}| where you want to have placed an entry.
% In case an entry is not found, ``?'' is output.
%
% \section{Caveats}
% The caveats of the entry format are similar to the bibentry package. The only 
% difference is that luabibentry expects the key as last token in the bibitem entry.
% Thus, the following text is a verbatim copy of bibentry's documentation with the 
% reference to the allowed space after the key being removed.
%
% The entries in the \texttt{.bbl} must be of the form
% \begin{quote}
%  |\bibitem|\oarg{label}\marg{key}\\
%  \emph{Text of the reference entry.}\\[1ex]
%  |\bibitem|\dots
% \end{quote}
% That is, there must be a new line after the \marg{key}
% and a blank line before the next |\bibitem|. The final period in the text
% will be removed, if present, allowing one to place the |\bibentry| commands
% in mid-sentence. Of course, there may be other periods within the text that
% might look funny.
% 
% \section{Test}
% A simple test whether luabibentry runs is provided here:
%
% \iffalse meta-comment
%<*testlatex>
% \fi
%    \begin{macrocode}
\documentclass{article}
\usepackage{luabibentry}
\setupbibentry{\jobname}

\usepackage[backref=page]{hyperref}

\begin{document}

The entry for \cite{LR2000} is: \bibentry{LR2000}.

\bibliographystyle{plain}
\bibliography{test-luabibentry}

\end{document}
%    \end{macrocode}
% \iffalse meta-comment
%</testlatex>
% \fi
%
% \iffalse meta-comment
%<*testbibtex>
% \fi
%    \begin{macrocode}
@BOOK{LR2000,
  title = {{P}roduction {W}orkflow -- {C}oncepts and {T}echniques},
  publisher = {Prentice Hall PTR},
  year = {2000},
  author = {Frank Leymann and Dieter Roller},
  isbn = {0130217530}
}
%    \end{macrocode}
% \iffalse meta-comment
%</testbibtex>
% \fi
%
% \section{Implementation of Lua Module \texttt{luabibentry.lua}}
% \iffalse meta-comment
%<*lua>
% \fi^^A meta-comment
%    \begin{macrocode}
module("luabibentry", package.seeall)
require("lualibs-file")

-- stores all entries
local entries = {}

-- builds the data by reading the given filename
function builddata(filename)
  -- Parameters seem to be passed as arrays. 
  -- We access the first element of the parameter to get the filename
  local file = io.open(filename[1], "r")
  if file==nil then
     texio.write_nl("luabibentry: could not open file " .. filename[1])
     return
  end
  local line = file:read("*line")
  while (line~=nil) do
    -- \bibitem is our marker for new entries
    local i = string.find(line, "\\bibitem")
    if i~=nil then
      -- we expect the key in brackets in the same line
      i = string.find(line,"{")
      local lasti = 0
      -- we jump to the last bracket
      while i~= nil do
         lasti = i
         i = string.find(line,"{",i+1)
      end
      local key = string.sub(line, lasti+1)
      -- we use the text from the last opening bracket ("{") until
      -- the end of the line minus one
      -- we expect nothing more to follow in this line
      key = string.sub(key, 1, string.len(key)-1)
      -- the next lines are the entry
      -- we expect an entry to be finished with a blank line 
      -- (or the end of the file)
      line = file:read("*line")
      local entry = ""
      while (line~=nil) and (line~="") do
         entry = entry .. line
         line = file:read("*line")
      end
      -- remove the final dot (if present)
      local entryLen = string.len(entry)
      local lastChar = string.sub(entry, entryLen, entryLen)
      if lastChar == "." then
        entry = string.sub(entry, 1, entryLen-1)
      end
      entries[key]=entry
    end
    line = file:read("*line")
  end
  file:close()
end

-- looks up the given key in the entries
-- in case an entry is not found, a bold question mark is printed
function bibentry(key)
  local res = entries[key[1]]
  if res==nil then
     res = "\\textbf{?}"
  end
  tex.print(res)
end

%    \end{macrocode}
%
% \iffalse meta-comment
%</lua>
% \fi^^A meta-comment

% \section{Implementation of \LaTeX{} Package  \texttt{luabibentry.sty}}
%
% \iffalse meta-comment
%<*package>
% \fi^^A meta-comment
% \LuaLaTeX{} must be used to use the package.
%    \begin{macrocode}
\RequirePackage{ifluatex}
\ifluatex\else
  \PackageError{luabibentry}{lualatex needed}{%
    Package `luabibentry' needs LuaTeX.\MessageBreak
    So you should use `lualatex' to process you document!\MessageBreak
    See documentation of `luabibentry' for further information.}%
  \expandafter\expandafter\expandafter\csname endinput\endcsname
\fi
%    \end{macrocode}
%
% Load the lua module:
%    \begin{macrocode}
\directlua{require("luabibentry.lua")}
%    \end{macrocode}
%
% Interface to the lua module:
%    \begin{macrocode}
\newcommand{\setupbibentry}[1]{\directlua{luabibentry.builddata{"#1.bbl"}}}
\newcommand{\bibentry}[1]{\nocite{#1}\directlua{luabibentry.bibentry{"#1"}}}
%    \end{macrocode}
%
% \iffalse meta-comment
%</package>
% \fi^^A meta-comment
%
% \section{Acknowledgements}
% This package is a variant of |bibentry.sty| by Patrick W.\ Daly. |bibentry.sty| is
% distributed with the |natbib| package. This documentation of luabibentry is
% mostly adapted from Patrick's documentation of |bibentry|.
%
% Thanks to Markus Kohm for the dtx and lua inspirements, Manuel
% P\'egouri\'e-Gonnard for the Makefile, dtx, and lua inspirements, and 
% Heiko Oberdiek for his detailed feedback on a draft version of this package.
%
% \Finale
%
\endinput