1# -*- mode: Perl -*-
2# /=====================================================================\ #
3# |  chapterbib                                                         | #
4# | Implementation for LaTeXML                                          | #
5# |=====================================================================| #
6# | Part of LaTeXML:                                                    | #
7# |  Public domain software, produced as part of work done by the       | #
8# |  United States Government & not subject to copyright in the US.     | #
9# |---------------------------------------------------------------------| #
10# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
11# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
12# \=========================================================ooo==U==ooo=/ #
13package LaTeXML::Package::Pool;
14use strict;
15use warnings;
16use LaTeXML::Package;
17
18DeclareOption('rootbib', sub {
19    AssignValue(CITE_UNIT_GLOBAL => 1); });
20DeclareOption('sectionbib', sub {
21    AssignMapping('BACKMATTER_ELEMENT', 'ltx:bibliography' => 'ltx:section'); });
22
23DeclareOption('gather',    sub { });    # ?
24DeclareOption('duplicate', sub { });    # ?
25
26ProcessOptions();
27
28DefMacro('\sectionbib{}{}', '');        # SHOULD adjust BACKMATTER_ELEMENT!
29
30DefPrimitive('\lx@cb@reset', sub {
31    AssignValue(CHAPTERBIB_UNIT => undef);
32    AssignValue(CITE_UNIT       => undef);
33    return; });
34
35DefPrimitive('\include{}', sub {
36    my ($stomach, $path) = @_;
37    $path = ToString($path);
38    my ($dir, $name, $ext) = pathname_split($path);
39    my $table = LookupValue('including@only');
40    if (!$table || $$table{$path}) {
41      AssignValue(CHAPTERBIB_UNIT => $name);
42      AssignValue(CITE_UNIT       => (LookupValue('CITE_UNIT_GLOBAL') ? 'bibliography ' . $name : $name));
43      $stomach->getGullet->unread(T_CS('\lx@cb@reset'));
44      Input($path); }
45    return; });
46
47DefMacro('\lx@cb@unitname', sub { Explode(LookupValue('CHAPTERBIB_UNIT')); });
48
49our $cbunits = 0;
50
51# Much like unitbib's bibunt environment
52DefEnvironment('{cbunit}', '#body',
53  afterDigestBegin => sub {
54    my $unit = 'chapbib' . ++$cbunits;
55    AssignValue(CHAPTERBIB_UNIT => $unit);
56    AssignValue(CITE_UNIT       => (LookupValue('CITE_UNIT_GLOBAL') ? 'bibliography ' . $unit : $unit));
57    return; });
58
59DefMacro('\bibliography Semiverbatim', '\lx@bibliography[\lx@cb@unitname]{#1}');
60
611;
62