%% %% This is file `notes2bib.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% notes2bib.dtx (with options: `package') %% --------------------------------------------------------------- %% notes2bib --- 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 %% --------------------------------------------------------------- %% \RequirePackage{xparse} \ProvidesExplPackage {notes2bib} {2012/07/16} {2.0i} {Integrating notes into the bibliography} \RequirePackage{l3keys2e} \tl_new:N \c__niib_file_message_tl \tl_set:Nn \c__niib_file_message_tl { \iow_char:N \% ~ This~is~an~auxiliary~file~used~by~the~'notes2bib'~package. \iow_newline: \iow_char:N \% ~ This~file~may~safely~be~deleted. \iow_newline: \iow_char:N \% ~ It~will~be~recreated~as~required. \iow_newline: } \clist_new:N \g__niib_after_clist \clist_new:N \g__niib_before_clist \clist_new:N \g__niib_all_after_clist \clist_new:N \g__niib_all_before_clist \int_new:N \g__niib_note_int \tl_new:N \l__niib_presort_tl \tl_new:N \l__niib_sortkey_tl \clist_new:N \g__niib_previous_after_clist \clist_new:N \g__niib_previous_before_clist \int_new:N \g__niib_previous_notes_int \tl_new:N \g__niib_notes_tl \tl_new:N \l__niib_sortkey_field_tl \int_new:N \g__niib_total_notes_int \cs_new_nopar:Npn \__niib_cite:w { } \keys_define:nn { notes2bib } { cite-function .code:n = { \AtBeginDocument { \cs_set_eq:NN \__niib_cite:w #1 } } , file-name .tl_gset_x:N = \g__niib_filename_tl , convert-endnotes .choice: , convert-endnotes / false .code:n = { \AtBeginDocument { \__niib_from_bibnote:n { endnote } } } , convert-endnotes / true .code:n = { \AtBeginDocument { \__niib_to_bibnote:n { endnote } } } , convert-footnotes .choice: , convert-footnotes / false .code:n = { \AtBeginDocument { \__niib_from_bibnote:n { footnote } } } , convert-footnotes / true .code:n = { \AtBeginDocument { \__niib_to_bibnote:n { footnote } } } , keyword-entry .tl_set:N = \l__niib_keyword_tl , note-field .tl_set:N = \l__niib_note_field_tl , note-name .tl_set:N = \l__niib_note_name_tl , placement .choice: , placement / after .code:n = { \cs_set_eq:NN \__niib_mark_note:n \__niib_mark_note_after:n \tl_set_eq:NN \l__niib_presort_tl \l__niib_presort_after_tl \tl_set_eq:NN \l__niib_sortkey_tl \l__niib_sortkey_after_tl }, placement / before .code:n = { \cs_set_eq:NN \__niib_mark_note:n \__niib_mark_note_before:n \tl_set_eq:NN \l__niib_presort_tl \l__niib_presort_before_tl \tl_set_eq:NN \l__niib_sortkey_tl \l__niib_sortkey_before_tl }, placement / mixed .code:n = { \cs_set_eq:NN \__niib_mark_note:n \__niib_mark_note_mixed:n \tl_set_eq:NN \l__niib_presort_tl \l__niib_presort_mixed_tl \tl_set_eq:NN \l__niib_sortkey_tl \l__niib_sortkey_mixed_tl }, presort-after .tl_set:N = \l__niib_presort_after_tl , presort-before .tl_set:N = \l__niib_presort_before_tl , presort-mixed .tl_set:N = \l__niib_presort_mixed_tl , record-type .tl_set:N = \l__niib_record_type_tl , refsection-name .tl_set:N = \l__niib_refsection_name_tl , refsection-separator .tl_set:N = \l__niib_refsection_sep_tl , sort-key-after .tl_set:N = \l__niib_sortkey_before_tl , sort-key-before .tl_set:N = \l__niib_sortkey_after_tl , sort-key-mixed .tl_set:N = \l__niib_sortkey_mixed_tl , use-sort-key .bool_set:N = \l__niib_write_sortkey_bool , } \keys_set:nn { notes2bib } { cite-function = \cite , file-name = notes2bib-\jobname , keyword-entry = note , note-field = note , note-name = Note , presort-after = mn , presort-before = ml , presort-mixed = mm , record-type = misc , refsection-name = Refsection , refsection-separator = - , sort-key-after = zzz , sort-key-before = aaa , use-sort-key = true } \AtBeginDocument { \@ifpackageloaded { biblatex } { \@ifpackagelater { biblatex } { 2011/01/08 } { \keys_set:nn { notes2bib } { record-type = bibnote } \DeclareBibliographyDriver { bibnote } { \usebibmacro { begentry } \printfield { note } \setunit { \bibpagerefpunct } \newblock \usebibmacro { pageref } \usebibmacro { finentry } } } { } } { } \keys_define:nn { notes2bib } { cite-function .code:n = { \cs_set_eq:NN \__niib_cite:w #1 } , file-name .code:n = { \msg_info:nnn { notes2bib } { preamble-only } { file-name } }, convert-endnotes / false .code:n = { \__niib_from_bibnote:n { endnote } } , convert-endnotes / true .code:n = { \__niib_to_bibnote:n { endnote } } , convert-footnotes / false .code:n = { \__niib_from_bibnote:n { footnote } } , convert-footnotes / true .code:n = { \__niib_to_bibnote:n { footnote } } , } } \msg_new:nnn { notes2bib } { preamble-only } { The~option~'#1'~can~only~be~used~in~the~preamble. } \cs_new_nopar:Npn \__niib_insert_refsection: { } \AtBeginDocument { \@ifpackageloaded { biblatex } { \cs_set_nopar:Npn \__niib_insert_refsection: { \int_compare:nNnT { \value { refsection } } > { 0 } { \tl_use:N \l__niib_refsection_name_tl \arabic { refsection } \tl_use:N \l__niib_refsection_sep_tl } } } { } } \keys_define:nn { notes2bib } { cite .meta:x = { cite-function = \exp_not:c {#1} } , debug .code:n = { } , endnotes .meta:n = { convert-footnotes = #1 } , etex .code:n = { } , field .meta:n = { note-field = #1 } , footnotes .meta:n = { convert-footnotes = #1 } , head .meta:n = { placement = before } , keyhead .meta:n = { sort-key-before = #1 } , keytail .meta:n = { sort-key-after = #1 } , keynone .meta:n = { sort-key-mixed = #1 } , keyword .meta:n = { keyword-entry = #1 } , log .meta:n = { } , name .meta:n = { note-name = #1 } , prefix .meta:n = { file-name = #1 \jobname } , presorthead .meta:n = { presort-before = #1 } , presorttail .meta:n = { presort-after = #1 } , presortnone .meta:n = { presort-mixed = #1 } , record .meta:n = { record-type = #1 } , sort .choice: , sort / head .meta:n = { placement = before } , sort / none .meta:n = { placement = after } , sort / tail .meta:n = { placement = mixed } , tail .meta:n = { placement = after } , writekey .meta:n = { use-sort-key = #1 } } \cs_new_nopar:Npn \__niib_note_name: { \__niib_insert_refsection: \tl_use:N \l__niib_note_name_tl \int_compare:nNnT \g__niib_previous_notes_int > \c_nine { \int_compare:nNnT \g__niib_note_int < \c_ten { 0 } } \int_to_arabic:n { \g__niib_note_int } } \cs_new_nopar:Npn \__niib_filesw: { } \cs_new:Npn \__niib_mark_note:n #1 { } \cs_generate_variant:Nn \__niib_mark_note:n { x } \cs_new_protected:Npn \__niib_mark_note_after:n #1 { \int_gincr:N \g__niib_total_notes_int \clist_gput_right:Nx \g__niib_after_clist {#1} \__niib_mark_note_after_aux:n {#1} } \cs_new:Npn \__niib_mark_note_after_aux:n #1 { } \cs_new_protected:Npn \__niib_mark_note_before:n #1 { \int_gincr:N \g__niib_total_notes_int \clist_gput_right:Nx \g__niib_before_clist {#1} \__niib_cite:w {#1} } \cs_new_protected:Npn \__niib_mark_note_mixed:n #1 { \int_gincr:N \g__niib_total_notes_int \__niib_cite:w {#1} } \cs_new:Npn \__niib_write_field:nn #1#2 { \c_space_tl \c_space_tl #1 \c_space_tl = \c_space_tl {#2} , \iow_newline: } \cs_generate_variant:Nn \__niib_write_field:nn { V } \cs_new_protected_nopar:Npn \__niib_write_note:nn { \if@filesw \exp_after:wN \__niib_write_note_aux:nn \else: \exp_after:wN \use_none:nn \fi: } \cs_new_protected:Npn \__niib_write_note_aux:nn #1#2 { \tl_gput_right:Nx \g__niib_notes_tl { @ \l__niib_record_type_tl { #1 , \iow_newline: \__niib_write_field:Vn \l__niib_note_field_tl { \exp_not:n {#2} } \bool_if:NT \l__niib_write_sortkey_bool { \__niib_write_field:Vn \l__niib_sortkey_field_tl { \l__niib_sortkey_tl #1 } } \__niib_write_field:nn { keywords } { \l__niib_keyword_tl } \__niib_write_field:nn { presort } { \l__niib_presort_tl } } \iow_newline: \iow_newline: } } \cs_generate_variant:Nn \__niib_write_note:nn { x } \cs_new_protected_nopar:Npn \__niib_record_notes: { \if@filesw \exp_after:wN \__niib_flush_notes_aux: \fi } \cs_new_protected_nopar:Npn \__niib_flush_notes_aux: { \clist_if_empty:NF \g__niib_before_clist { \iow_now:Nx \@auxout { \NotesBeforeCitations { \exp_not:V \g__niib_before_clist } } \clist_gput_right:NV \g__niib_all_before_clist \g__niib_before_clist \clist_gclear:N \g__niib_before_clist } \clist_if_empty:NF \g__niib_after_clist { \iow_now:Nx \@auxout { \NotesAfterCitations { \exp_not:V \g__niib_after_clist } } \exp_args:NV \nocite \g__niib_after_clist \clist_gput_right:NV \g__niib_all_after_clist \g__niib_after_clist \clist_gclear:N \g__niib_after_clist } } \cs_new_protected_nopar:Npn \__niib_to_bibnote:n #1 { \cs_set_eq:cN {#1} \bibnote \cs_set_eq:cN { #1 mark } \bibnotemark \cs_set_eq:cN { #1 text } \bibnotetext } \cs_new_protected_nopar:Npn \__niib_from_bibnote:n #1 { \cs_set_eq:cc {#1} { __niib_ #1 :w } \cs_set_eq:cc { #1 mark } { __niib_ #1 mark:w } \cs_set_eq:cc { #1 text } { __niib_ #1 text:w } } \AtBeginDocument { \cs_set_eq:NN \__niib_endnote:w \endnote \cs_set_eq:NN \__niib_endnotemark:w \endnotemark \cs_set_eq:NN \__niib_endnotetext:w \endnotetext \cs_set_eq:NN \__niib_footnote:w \footnote \cs_set_eq:NN \__niib_footnotemark:w \footnotemark \cs_set_eq:NN \__niib_footnotetext:w \footnotetext } \AtBeginDocument { \@ifpackageloaded { biblatex } { \cs_new_protected_nopar:Npn \__niib_print_notes: { \cs_set_nopar:Npx \__niib_create_print_notes: { \printbibliography [ keyword = \exp_not:V \l__niib_keyword_tl ] } \__niib_create_print_notes: } } { \cs_new_protected_nopar:Npn \__niib_print_notes: { \exp_args:NV \__niib_bibliography:n \g__niib_filename_tl } } } \cs_new_nopar:Npn \__niib_create_print_notes: { } \cs_new_nopar:Npn \__niib_attach_bibliography: { \@ifpackageloaded { biblatex } { \@ifpackagelater { biblatex } { 2011/01/08 } { \@ifpackagelater { biblatex } { 2011/02/12 } { \exp_args:No \addglobalbib { \g__niib_filename_tl .bib } } { \exp_args:NNV \bibliography * \g__niib_filename_tl } } { \exp_args:NV \bibliography \g__niib_filename_tl } } { \cs_new_eq:NN \__niib_bibliography:n \bibliography \RenewDocumentCommand \bibliography { m } { \int_compare:nNnTF \g__niib_total_notes_int = \c_zero { \__niib_bibliography:n {##1} } { \cs_set_nopar:Npx \__niib_attach_bibliography: { \exp_not:N \__niib_bibliography:n { \exp_not:n {##1} , \exp_not:V \g__niib_filename_tl } } \__niib_attach_bibliography: } } } } \@ifpackageloaded { biblatex } { \@ifpackagelater { biblatex } { 2011/01/08 } { \@ifpackagelater { biblatex } { 2011/02/12 } { \exp_args:No \addglobalbib { \g__niib_filename_tl .bib } } { \exp_args:NNV \bibliography * \g__niib_filename_tl } } { \exp_args:NV \bibliography \g__niib_filename_tl } } { \AtBeginDocument { \__niib_attach_bibliography: } } \AtBeginDocument { \@ifpackageloaded { biblatex } { \tl_set:Nn \l__niib_sortkey_field_tl { sortkey } } { \tl_set:Nn \l__niib_sortkey_field_tl { key } } } \AtBeginDocument { \@ifpackageloaded { biblatex } { \cs_set:Npn \__niib_mark_note_after_aux:n #1 { \AtNextCite { \@fileswfalse } \__niib_cite:w {#1} } } { \cs_set:Npn \__niib_mark_note_after_aux:n #1 { \cs_set_eq:NN \__niib_filesw: \if@filesw \@fileswfalse \__niib_cite:w {#1} \cs_set_eq:NN \if@filesw \__niib_filesw: } } } \AtBeginDocument { \@ifpackageloaded { cite } { \cs_set:Npn \__niib_mark_note_after_aux:n #1 { \cs_set_eq:NN \__niib_filesw: \if@filesw \@fileswfalse \cs_set_nopar:Npn \__niib_aux_hook: { \cs_set_eq:NN \if@filesw \__niib_filesw: \cs_set_nopar:Npn \__niib_aux_hook: { } } \__niib_cite:w {#1} } \cs_new_nopar:Npn \__niib_aux_hook: { } \tl_gput_right:Nn \g__niib_document_hook_tl { \cs_if_exist:NF \@restore@auxhandle { \tl_new:N \@restore@auxhandle } \tl_put_right:Nn \@restore@auxhandle { \__niib_aux_hook: } } } { } } \NewDocumentCommand \bibnote { o +m } { \IfNoValueTF {#1} { \int_gincr:N \g__niib_note_int \__niib_bibnote:xn { \__niib_note_name: } {#2} } { \__niib_bibnote:xn { \__niib_insert_refsection: #1 } {#2} } } \cs_new_protected:Npn \__niib_bibnote:nn #1#2 { \__niib_write_note:nn {#1} {#2} \__niib_mark_note:n {#1} } \cs_generate_variant:Nn \__niib_bibnote:nn { x } \NewDocumentCommand \bibnotemark { o } { \IfNoValueTF {#1} { \int_gincr:N \g__niib_note_int \__niib_mark_note:x { \__niib_note_name: } } { \__niib_mark_note:x { \__niib_insert_refsection: #1 } } } \NewDocumentCommand \bibnotetext { o +m } { \IfNoValueTF {#1} { \__niib_write_note:xn { \__niib_note_name: } {#2} } { \__niib_write_note:xn { \__niib_insert_refsection: #1 } {#2} } } \NewDocumentCommand \recordnotes { } { \__niib_record_notes: } \NewDocumentCommand \bibnotesetup { m } { \keys_set:nn { notes2bib } {#1} } \NewDocumentCommand \printbibnotes { } { \__niib_print_notes: } \NewDocumentCommand \citenote { m } { \__niib_mark_note:n {#1} } \cs_new_eq:NN \flushnotestack \recordnotes \cs_new_eq:NN \niibsetup \bibnotesetup \cs_new_protected_nopar:Npn \NotesAfterCitations #1 { \clist_gput_right:Nn \g__niib_previous_after_clist {#1} } \cs_new_protected_nopar:Npn \NotesBeforeCitations #1 { \clist_gput_right:Nn \g__niib_previous_after_clist {#1} \tl_gput_right:Nn \g__niib_document_hook_tl { \nocite {#1} } } \cs_new_protected_nopar:Npn \TotalNotes #1 { \int_gset:Nn \g__niib_previous_notes_int {#1} } \tl_gput_right:Nn \document { \g__niib_document_hook_tl } \tl_new:N \g__niib_document_hook_tl \AtEndDocument { \__niib_record_notes: } \AtEndDocument { \tl_if_eq:NNTF \g__niib_all_before_clist \g__niib_previous_before_clist { \tl_if_eq:NNF \g__niib_all_after_clist \g__niib_previous_after_clist { \msg_info:nn { notes2bib } { rerun } } } { \msg_info:nn { notes2bib } { rerun } } } \msg_new:nnn { notes2bib } { rerun } { To~get~notes~in~the~correct~order,~please~run: \\% \c_space_tl 1)~LaTeX \\ \c_space_tl 2)~BibTeX \\ \c_space_tl 3)~LaTeX } \AtEndDocument { \if@filesw \exp_after:wN \__niib_write_note_file: \fi: } \cs_new_protected_nopar:Npn \__niib_write_note_file: { \tl_if_empty:NF \g__niib_notes_tl { \iow_open:Nn \g__niib_file_iow { \g__niib_filename_tl .bib } \iow_now:Nx \g__niib_file_iow { \c__niib_file_message_tl } \iow_now:Nx \g__niib_file_iow { \exp_not:V \g__niib_notes_tl } \iow_close:N \g__niib_file_iow } } \iow_new:N \g__niib_file_iow \AtEndDocument { \int_compare:nNnT \g__niib_note_int > \c_zero { \iow_now:Nx \@auxout { \TotalNotes { \int_to_arabic:n { \g__niib_note_int } } } } } \cs_set:Npn \thanks #1 { \__niib_footnotemark:w \protected@xdef \@thanks { \@thanks \protect \__niib_footnotetext:w [ \the \c@footnote ] {#1} } } \keys_set:nn { notes2bib } { placement = mixed } \ProcessKeysOptions { notes2bib } %% %% Copyright (C) 2007-2011 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 %% and the derived files notes2bib.ins, %% notes2bib.pdf and %% notes2bib.sty. %% %% %% End of file `notes2bib.sty'.