%%
%% This is file `ltb2bib.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ltb2bib.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2017 by Laurent Bartholdi <laurent.bartholdi@gmail.com>
%% --------------------------------------------------------------------------
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{ltb2bib}
    [2017/04/03 0.01 First release in the wild]
\ProvidesPackage{ltb2bib}[2017/04/03 v0.01]
\@ifundefined{thebibliography}{\newenvironment{thebibliography}{}{}}{}
\@ifundefined{footnotesize}{\let\footnotesize\relax}{}
\RequirePackage{amsrefs}
\RequirePackage{xpatch}
\newwrite\@bibfile
\let\protected@iwrite\protected@write
\xpatchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\def\bib@write#1{\protected@iwrite\@bibfile{\let~\relax\def\ndash{--}}{#1}}
\gdef\space{ }
\gdef\spsp{\space\space}
\def\@author#1{\toks0={}\toks1={}%
  \def\name##1{\toks0=\expandafter{\the\toks0\the\toks1{##1}}\toks1={\spsp and }}%
  #1
  \bib@write{\spsp author={\the\toks0},}%
}
\def\@editor#1{\toks0={}\toks1={}%
  \def\name##1{\toks0=\expandafter{\the\toks0\the\toks1{##1}}\toks1={\spsp and }}%
  #1
  \bib@write{\spsp editor={\the\toks0},}%
}
\def\@translator#1{\toks0={}\toks1={}%
  \def\name##1{\toks0=\expandafter{\the\toks0\the\toks1{##1}}\toks1={\spsp and }}%
  #1
  \bib@write{\spsp translator={\the\toks0},}%
}
\def\@contribution#1{\bib@write{\spsp contribution=\@charlb#1\@charrb,}}
\def\@isbn#1{\def\fld@elt##1{\bib@write{\spsp isbn=\@charlb##1\@charrb,}}#1}
\def\@issn#1{\def\fld@elt##1{\bib@write{\spsp issn=\@charlb##1\@charrb,}}#1}
\def\@review#1{\def\MR##1{\let\MR\relax\bib@write{\spsp review={\MR{##1}},}}#1}
\def\@partial#1{\bib@write{\spsp partial=\@charlb#1\@charrb,}}
\def\@accessdate#1{\bib@write{\spsp accessdate=\@charlb#1\@charrb,}}
\def\@address#1{\bib@write{\spsp address=\@charlb#1\@charrb,}}
\def\@book#1{\bib@write{\spsp book=\@charlb#1\@charrb,}}
\def\@booktitle#1{\bib@write{\spsp booktitle=\@charlb#1\@charrb,}}
\def\@conference#1{\bib@write{\spsp conference=\@charlb#1\@charrb,}}
\def\@copula#1{\bib@write{\spsp copula=\@charlb#1\@charrb,}}
\def\@date#1{\bib@write{\spsp year=\@charlb#1\@charrb,}}
\def\@doi#1{\bib@write{\spsp doi=\@charlb#1\@charrb,}}
\def\@edition#1{\bib@write{\spsp edition=\@charlb#1\@charrb,}}
\def\@eprint#1{\bib@write{\spsp eprint=\@charlb#1\@charrb,}}
\def\@fulljournal#1{\bib@write{\spsp fulljournal=\@charlb#1\@charrb,}}
\def\@hyphenation#1{\bib@write{\spsp hyphenation=\@charlb#1\@charrb,}}
\def\@institution#1{\bib@write{\spsp institution=\@charlb#1\@charrb,}}
\def\@journal#1{\bib@write{\spsp journal=\@charlb#1\@charrb,}}
\def\@label#1{\bib@write{\spsp label=\@charlb#1\@charrb,}}
\def\@language#1{\bib@write{\spsp language=\@charlb#1\@charrb,}}
\def\@name#1{\bib@write{\spsp name=\@charlb#1\@charrb,}}
\def\@note#1{\bib@write{\spsp note=\@charlb#1\@charrb,}}
\def\@number#1{\bib@write{\spsp number=\@charlb#1\@charrb,}}
\def\@organization#1{\bib@write{\spsp organization=\@charlb#1\@charrb,}}
\def\@pages#1{\bib@write{\spsp pages=\@charlb#1\@charrb,}}
\def\@part#1{\bib@write{\spsp part=\@charlb#1\@charrb,}}
\def\@place#1{\bib@write{\spsp place=\@charlb#1\@charrb,}}
\def\@publisher#1{\bib@write{\spsp publisher=\@charlb#1\@charrb,}}
\def\@reprint#1{\bib@write{\spsp reprint=\@charlb#1\@charrb,}}
\def\@school#1{\bib@write{\spsp school=\@charlb#1\@charrb,}}
\def\@series#1{\bib@write{\spsp series=\@charlb#1\@charrb,}}
\def\@setup#1{\bib@write{\spsp setup=\@charlb#1\@charrb,}}
\def\@status#1{\bib@write{\spsp status=\@charlb#1\@charrb,}}
\def\@subtitle#1{\bib@write{\spsp subtitle=\@charlb#1\@charrb,}}
\def\@title#1{\bib@write{\spsp title=\@charlb#1\@charrb,}}
\def\@translation#1{\bib@write{\spsp translation=\@charlb#1\@charrb,}}
\def\@type#1{\bib@write{\spsp type=\@charlb#1\@charrb,}}
\def\@url#1{\bib@write{\spsp url=\@charlb#1\@charrb,}}
\def\@volume#1{\bib@write{\spsp volume=\@charlb#1\@charrb,}}
\def\@xref#1{\bib@write{\spsp xref=\@charlb#1\@charrb,}}
\def\@year#1{\bib@write{\spsp year=\@charlb#1\@charrb,}}
\def\make@bibspec#1#2{\BibSpec{#1}{%
    +{}{\bib@write{@#2\@charlb\current@citekey,}}{transition}
    +{}{\@author}        {author}
    +{}{\@editor}        {editor}
    +{}{\@translator}    {translator}
    +{}{\@contribution}  {contribution}
    +{}{\@isbn}          {isbn}
    +{}{\@issn}          {issn}
    +{}{\@review}        {review}
    +{}{\@partial}       {partial}
    +{}{\@accessdate}    {accessdate}
    +{}{\@address}       {address}
    +{}{\@book}          {book}
    +{}{\@booktitle}     {booktitle}
    +{}{\@conference}    {conference}
    +{}{\@copula}        {copula}
    +{}{\@date}          {date}
    +{}{\@doi}           {doi}
    +{}{\@edition}       {edition}
    +{}{\@eprint}        {eprint}
    +{}{\@fulljournal}   {fulljournal}
    +{}{\@hyphenation}   {hyphenation}
    +{}{\@institution}   {institution}
    +{}{\@journal}       {journal}
    +{}{\@label}         {label}
    +{}{\@language}      {language}
    +{}{\@name}          {name}
    +{}{\@note}          {note}
    +{}{\@number}        {number}
    +{}{\@organization}  {organization}
    +{}{\@pages}         {pages}
    +{}{\@part}          {part}
    +{}{\@place}         {place}
    +{}{\@publisher}     {publisher}
    +{}{\@reprint}       {reprint}
    +{}{\@school}        {school}
    +{}{\@series}        {series}
    +{}{\@setup}         {setup}
    +{}{\@status}        {status}
    +{}{\@subtitle}      {subtitle}
    +{}{\@title}         {title}
    +{}{\@translation}   {translation}
    +{}{\@type}          {type}
    +{}{\@url}           {url}
    +{}{\@volume}        {volume}
    +{}{\@xref}          {xref}
    +{}{\@year}          {year}
  +{}{\bib@write{\@charrb^^J}}{transition}
}}
\newskip\ltb@baselineskip
\newskip\ltb@parskip
\newcommand\writebib[2]{%
  \immediate\openout\@bibfile=#2.bib
  \bib@write{\@percentchar\space Converted bibliography from #1[.ltb] to #2.bib}%
  \typeout{Writing bibliography to #2.bib...}%
  \make@bibspec{article}{Article}%
  \make@bibspec{partial}{InCollection}%
  \make@bibspec{contribution}{InCollection}%
  \make@bibspec{book}{Book}%
  \make@bibspec{collection.article}{InCollection}%
  \make@bibspec{conference}{Conference}%
  \make@bibspec{innerbook}{InBook}%
  \make@bibspec{report}{TechReport}%
  \make@bibspec{thesis}{PhdThesis}%
  \make@bibspec{webpage}{Misc}%
  \ltb@parskip=\parskip
  \ltb@baselineskip=\baselineskip
  \let\ltb@item=\item
  \parskip=0pt
  \baselineskip=0pt
  \let\item=\relax
  \let\fld@elt=\relax
  \bibselect*{#1}%
  \bib@write{\@percentchar\space End of #2.bib}%
  \immediate\closeout\@bibfile
  \parskip=\ltb@parskip
  \baselineskip=\ltb@baselineskip
  \let\item=\ltb@item
}

\endinput
%%
%% End of file `ltb2bib.sty'.
