%% %% This is file `xnotes2bib.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% xnotes2bib.dtx (with options: `package') %% --------------------------------------------------------------- %% The notes2bib bundle --- Integrating notes into the %% bibliography %% Maintained by Joseph Wright %% E-mail: joseph.wright@morningstar2.co.uk %% Released under the LaTeX Project Public License v1.3c or later %% See http://www.latex-project.org/lppl.txt %% --------------------------------------------------------------- %% \NeedsTeXFormat{LaTeX2e} \begingroup \@ifundefined{eTeXversion}{% \PackageError{xnotes2bib} {Not running under e-TeX} {This package requires e-TeX: enable the extensions!}% \endgroup\endinput }{% \endgroup } \RequirePackage{l3names} \ProvidesExplPackage {xnotes2bib}{2008/09/09}{0.0} {Integrating notes into the bibliography (expl3 version)} \RequirePackage{expl3,xparse} \DeclareOption*{ \PackageWarning{xnotes2bib}{ All~package~control~should~be~given~using~the\MessageBreak \token_to_string:N\niibsetup\space macro } } \ProcessOptions\scan_stop: \int_new:N \g_niib_note_int \def_new:Npn \niib_thenote: { \l_niib_notename_tlp \num_compare:nNnT {\g_niib_totalnotes_int} > {\c_nine}{ \num_compare:nNnF {\g_niib_note_int} > {\c_nine}{ 0 } } \int_to_arabic:n \g_niib_note_int } \RequirePackage{keyval} \clist_new:N\g_niib_KV_bool_clist \clist_put_left:Nn\g_niib_KV_bool_clist{true,false} \def_new:Npn\niib_KV_bool:nT #1#2 { \define@key{niib}{#1}[true]{ \clist_if_in:cnTF{g_niib_KV_bool_clist}{##1}{ #2 }{ \PackageError{xnotes2bib}{ Unknown~choice~`##1' }{ The~Boolean~option~`#1'~accepts~only~the\MessageBreak values~true~and~false } } } } \def_new:Npn\niib_KV_choice:nnT #1#2#3 { \cs_if_free:cTF{g_niib_KV_#1_clist}{ \clist_new:c{g_niib_KV_#1_clist} }{ \clist_gclear:c{g_niib_KV_#1_clist} } \clist_put_left:cn{g_niib_KV_#1_clist}{#2} \define@key{niib}{#1}{ \clist_if_in:cnTF{g_niib_KV_#1_clist}{##1}{ #3 }{ \PackageError{xnotes2bib}{ Unknown~choice~`##1' }{ The~option~`#1'~accepts~only~the~values:\MessageBreak #2 } } } } \def_new:Npn\niib_KV_cs_n:n #1 { \define@key{niib}{#1}{ \def:cNn{niib_#1:n} 0 {##1} } } \def_new:Npn\niib_KV_tlp:n #1 { \tlp_new:c {l_niib_#1_tlp} \define@key{niib}{#1}{ \tlp_set:cn {l_niib_#1_tlp}{##1} } } \niib_KV_cs_n:n{cite} \niib_KV_tlp:n{field} \niib_KV_tlp:n{key~after} \niib_KV_tlp:n{key~before} \niib_KV_tlp:n{key~mixed} \niib_KV_tlp:n{notename} \niib_KV_tlp:n{prefix} \niib_KV_tlp:n{presort~after} \niib_KV_tlp:n{presort~before} \niib_KV_tlp:n{presort~mixed} \niib_KV_tlp:n{record} \let_new:NN\niib_convert_endnotes:\scan_stop: \let_new:NN\niib_convert_footnotes:\scan_stop: \niib_KV_bool:nT{convert~endnotes}{ \let:Nc\niib_convert_endnotes:{niib_convert_endnotes_#1:} } \niib_KV_bool:nT{convert~footnotes}{ \let:Nc\niib_convert_footnotes:{niib_convert_footnotes_#1:} } \niib_KV_bool:nT{debug}{ \let:Nc\niib_debug:n{niib_debug_#1:n} } \def_new:Npn\niib_debug_true:n #1 { \PackageInfo{xnotes2bib}{#1} } \let_new:NN\niib_debug_false:n\use_none:n \bool_new:N\l_niib_after_cite_bool \bool_new:N\l_niib_before_cite_bool \niib_KV_choice:nnT{placement}{after,before,mixed}{ \bool_set_false:N\l_niib_before_cite_bool \bool_set_false:N\l_niib_after_cite_bool \cs_if_really_exist:cT{l_niib_#1_cite_bool}{ \bool_set_true:c{l_niib_#1_cite_bool} } } \setkeys{niib}{ cite = \cite, debug = false, field = note, key~after = zzz, key~before = aaa, key~mixed = {}, notename = Bibnote, placement = mixed, prefix = niib-, presort~after = mn, presort~before = ml, presort~mixed = mm, record = Misc} \NewDocumentCommand{\bibnote}{o>{P}m}{ \IfNoValueTF{#1}{ \int_gincr:N \g_niib_note_int \bibnotetext{#2} \bibnotemark[\niib_thenote:] }{ \bibnotetext[#1]{#2} \bibnotemark[#1] } } \NewDocumentCommand{\bibnotemark}{o}{ \IfNoValueTF{#1}{ \int_gincr:N \g_niib_note_int \niib_notemark:n{\niib_thenote:} }{ \niib_notemark:n{#1} } } \NewDocumentCommand{\bibnotetext}{O{\niib_thenote:}>{P}m}{ \if@filesw \cs_if_free:NT \g_niib_out_stream { \iow_new:N \g_niib_out_stream \iow_open:Nn \g_niib_out_stream {\l_niib_prefix_tlp\c_job_name_tlp.bib} \iow_expanded:Nn \g_niib_out_stream {This~is~an~auxiliary~file~used~by~the~`xnotes2bib'~ package.^^J This~file~may~safely~be~deleted.^^J It~ will~be~recreated~as~required.^^J} } \niib_debug:n{ Writing~text:\MessageBreak #2\MessageBreak to~database~ for~note~`#1' } \iow_expanded:Nn \g_niib_out_stream { @\l_niib_record_tlp{ #1,^^J \space\space \l_niib_field_tlp\space =~{\exp_not:n{#2}},^^J \space\space \l_niib_keyname_tlp\space =~{\niib_key:#1},^^J \space\space presort~ =~{\niib_presort:},^^J }^^J } \fi } \NewDocumentCommand{\flushnotestack}{}{ \clist_if_empty:NF\g_niib_before_cite_clist{ \if@filesw \iow_expanded:Nn\@auxout{ \token_to_string:N\niibbeforecite{ \g_niib_before_cite_clist } } \fi } \clist_if_empty:NF\g_niib_after_cite_clist{ \nocite{\g_niib_after_cite_clist} \if@filesw \iow_expanded:Nn\@auxout{ \token_to_string:N\niibaftercite{\g_niib_after_cite_clist} } \fi } \clist_gclear:N\g_niib_after_cite_clist } \NewDocumentCommand{\niibsetup}{m}{\setkeys{niib}{#1}} \clist_new:N\g_niib_before_cite_old_clist \clist_new:N\g_niib_after_cite_old_clist \tlp_new:N\g_niib_document_tlp \tlp_put_right:Nn\document{\g_niib_document_tlp} \NewDocumentCommand{\niibbeforecite}{m}{ \clist_gput_right:Nn\g_niib_before_cite_old_clist{#1} \tlp_gput_right:Nn\g_niib_document_tlp{\nocite{#1}} } \NewDocumentCommand{\niibaftercite}{m}{ \clist_gput_right:Nn\g_niib_after_cite_old_clist{#1} } \int_new:N \g_niib_totalnotes_int \NewDocumentCommand{\niibtotalnotes}{m}{ \int_gset:Nn \g_niib_totalnotes_int {#1} } \def_new:Npn \niib_notemark:n #1 { \niib_debug:n{Creating~citation~for~note~`#1'} \bool_if:NT\l_niib_before_cite_bool{ \niib_debug:n{Note~`#1'~before~real~citations} \clist_gput_right:Nx\g_niib_before_cite_clist{#1} } \bool_if:NTF\l_niib_after_cite_bool{ \niib_debug:n{Note~`#1'~after~real~citations} \clist_gput_right:Nx\g_niib_after_cite_clist{#1} \niib_after_cite:n{#1} }{ \niib_cite:n{#1} } } \clist_new:N\g_niib_before_cite_clist \clist_new:N\g_niib_after_cite_clist \def_new:Npn\niib_key: { \bool_if:NTF\l_niib_before_cite_bool{ \tlp_use:c{l_niib_key~before_tlp} }{ \bool_if:NTF\l_niib_after_cite_bool{ \tlp_use:c{l_niib_key~after_tlp} }{ \tlp_use:c{l_niib_key~mixed_tlp} } } } \def_new:Npn\niib_presort: { \bool_if:NTF\l_niib_before_cite_bool{ \tlp_use:c{l_niib_presort~before_tlp} }{ \bool_if:NTF\l_niib_after_cite_bool{ \tlp_use:c{l_niib_presort~after_tlp} }{ \tlp_use:c{l_niib_presort~mixed_tlp} } } } \def_new:Npn\niib_convert_endnotes_false: { \niib_debug:n{Restoring~normal~endnotes} \let:NN\endnote\niib_saved_endnote: \let:NN\endnotemark\niib_saved_endnotemark: \let:NN\endnotetext\niib_saved_endnotetext: } \def_new:Npn\niib_convert_endnotes_true: { \niib_debug:n{Converting~endnotes~to~bibnotes} \let:NN\endnote\bibnote \let:NN\endnotemark\bibnotemark \let:NN\endnotetext\bibnotetext } \def_new:Npn\niib_convert_footnotes_false: { \niib_debug:n{Restoring~normal~footnotes} \let:NN\footnote\niib_saved_footnote: \let:NN\footnotemark\niib_saved_footnotemark: \let:NN\footnotetext\niib_saved_footnotetext: } \def_new:Npn\niib_convert_footnotes_true: { \niib_debug:n{Converting~footnotes~to~bibnotes} \let:NN\footnote\bibnote \let:NN\footnotemark\bibnotemark \let:NN\footnotetext\bibnotetext } \def:Npn\thanks #1 { \niib_saved_footnotemark: \protected@xdef\@thanks{\@thanks \protect\niib_saved_footnotetext:[\the\c@footnote]{#1}} } \tlp_new:N \l_niib_keyname_tlp \AtBeginDocument{ \PackageInfo{xnotes2bib}{ Beginning~\token_to_string:N\AtBeginDocument\space tasks } \@ifpackageloaded{biblatex}{ \tlp_set:Nn \l_niib_keyname_tlp {keysort} \gappto\blx@bibfiles{,\niib_prefix\c_job_name_tlp} \let_new:NN\printbibnotes\printbibliography \def_new:Npn\niib_after_cite:n #1 { \AtNextCite{\@fileswfalse} \niib_cite:n{#1} } }{ \tlp_gset:Nn \l_niib_keyname_tlp {key} \let_new:NN\niib_biliography:n\bibliography \def:Npn\bibliography #1 { \int_compare:nNnTF{\g_niib_note_int}={\c_zero}{ \niib_biliography:n{#1} }{ \niib_biliography:n{ #1,\l_niib_prefix_tlp\c_job_name_tlp } } } \NewDocumentCommand{\printbibnotes}{}{ \niib_biliography:n{\l_niib_prefix_tlp\c_job_name_tlp} } \newif\ifniib@filesw \@ifpackageloaded{cite}{ \def_new:Npn\niib_after_cite:n #1 { \let:NN \ifniib@filesw \if@filesw \@fileswfalse \def:Npn \niib_auxhandle: { \let:NN \if@filesw \ifniib@filesw \let:NN \niib_auxhandle: \scan_stop: } \niib_cite:n{#1} } \tlp_gput_right:Nn \g_niib_document_tlp { \cs_if_exist:NTF\@restore@auxhandle{ \tlp_put_right:Nn\@restore@auxhandle{\niib_auxhandle:} }{ \def_new:Npn\@restore@auxhandle {\niib_auxhandle:} } } \let_new:NN\niib_auxhandle:\scan_stop: }{ \def_new:Npn\niib_after_cite:n #1 { \let\ifniib@filesw\if@filesw \@fileswfalse \niib_cite:n{#1} \let\if@filesw\ifniib@filesw } } } \let_new:NN\niib_saved_footnote:\footnote \let_new:NN\niib_saved_footnotemark:\footnotemark \let_new:NN\niib_saved_footnotetext:\footnotetext \let_new:NN\niib_saved_endnote:\endnote \let_new:NN\niib_saved_endnotemark:\endnotemark \let_new:NN\niib_saved_endnotetext:\endnotetext \niib_convert_endnotes: \niib_convert_footnotes: \niib_KV_bool:nT{convert~endnotes}{ \use:c{niib_convert_endnotes_#1:} } \niib_KV_bool:nT{convert~footnotes}{ \use:c{niib_convert_footnotes_#1:} } \PackageInfo{xnotes2bib}{ Finished~\token_to_string:N\AtBeginDocument\space tasks } } \def_new:Npn\niib_rerun_check:n #1 { \clist_if_empty:cTF {g_niib_old#1cite_clist}{ \clist_if_empty:cF {g_niib_#1cite_clist}{ \niib_rerun_log: } }{ \clist_if_empty:cTF {g_niib_#1cite_clist}{ \niib_rerun_log: }{ \bool_set_false:N\l_tmpa_bool \def:Npn\niib_rerun_test:n ##1 { \clist_if_in:cnTF{g_niib_old#1cite_clist}{##1}{ \bool_set_true:N\l_tmpa_bool \clist_map_break:w }{ } } \clist_map_function:cN{g_niib_#1cite_clist} \niib_rerun_test:n \def:Npn\niib_rerun_test:n ##1 { \clist_if_in:cnTF{g_niib_#1cite_clist}{##1}{ \bool_set_true:N\l_tmpa_bool \clist_map_break:w }{ } } \clist_map_function:cN{g_niib_old#1cite_clist} \niib_rerun_test:n \bool_if:NF\l_tmpa_bool{ \niib_rerun_log: } } } } \let_new:NN \niib_rerun_test:n \use_none_i:n \def_new:Npn\niib_rerun_log: { \PackageInfo{xnotes2bib}{ To~get~notes~in~the~correct~order,~please\MessageBreak rerun~LaTeX,~(re)run~BibTeX~on~the~file~\c_job_name_tlp.aux \MessageBreak and~rerun~LaTeX~again~afterwards } \io_put_log:x { REQ:3:latex:REQ\iow_newline: REQ:2:bibtex:REQ\iow_newline: REQ:1:latex:REQ\iow_newline: } \let\niib_rerun_log:\scan_stop: } \AtEndDocument{ \niib_rerun_check:n{before} \niib_rerun_check:n{after} \flushnotestack \iow_expanded:Nn\@auxout{ \token_to_string:N\niibtotalnotes{ \int_to_arabic:n \g_niib_note_int } } \num_compare:nNnF{\g_niib_totalnotes_int}={\g_niib_note_int}{ \niib_rerun_log: } \cs_if_free:NF \g_niib_out_stream{ \iow_close:N \g_niib_out_stream } } %% %% Copyright (C) 2007-2008 by %% Joseph Wright %% %% It may be distributed and/or modified under the conditions of %% the LaTeX Project Public License (LPPL), either version 1.3c of %% this license or (at your option) any later version. The latest %% version of this license is in the file: %% %% http://www.latex-project.org/lppl.txt %% %% This work is "maintained" (as per LPPL maintenance status) by %% Joseph Wright. %% %% This work consists of the file notes2bib.dtx %% xnotes2bib.dtx %% and the derived files notes2bib.pdf, %% notes2bib.sty, %% notes2bib.ins, %% xnotes2bib.pdf, %% xnotes2bib.sty and %% xnotes2bib.ins. %% %% %% End of file `xnotes2bib.sty'.