diff options
author | Norbert Preining <norbert@preining.info> | 2022-08-19 03:00:56 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-08-19 03:00:56 +0000 |
commit | 1772be123f1cfa713b25548f6fec135e7ab339a3 (patch) | |
tree | 1ba6586dc52536e962cb28380567183f6f90bbc1 /biblio/citation-style-language/citation-style-language.sty | |
parent | 982d5e88b736a798b356bf5cabe5e6c9b115f182 (diff) |
CTAN sync 202208190300
Diffstat (limited to 'biblio/citation-style-language/citation-style-language.sty')
-rw-r--r-- | biblio/citation-style-language/citation-style-language.sty | 146 |
1 files changed, 106 insertions, 40 deletions
diff --git a/biblio/citation-style-language/citation-style-language.sty b/biblio/citation-style-language/citation-style-language.sty index 546ac13eec..87165c4be2 100644 --- a/biblio/citation-style-language/citation-style-language.sty +++ b/biblio/citation-style-language/citation-style-language.sty @@ -9,9 +9,10 @@ \RequirePackage{expl3} \RequirePackage{xparse} -\ProvidesExplPackage {citation-style-language} {2022-01-22} {v0.1.0} +\ProvidesExplPackage {citation-style-language} {2022-08-18} {v0.2.0} {Citation Style Language for LaTeX} +\RequirePackage { l3keys2e } \RequirePackage { filehook } \RequirePackage { url } @@ -34,7 +35,7 @@ \__csl_load_check:n \sys_if_engine_luatex:T - { \lua_now:n { csl = require("csl") } } + { \lua_now:n { csl = require("citeproc-latex") } } \NewDocumentCommand \cslsetup { m } @@ -82,8 +83,11 @@ } +% Appends the cite key into \l__csl_cite_keys_seq and cite-items into +% \l__csl_cite_items_seq +% #1, #2: prenote/postnote +% #3: keys \cs_new:Npn \__csl_process_cite_items:nnn #1#2#3 - % #1,#2: prenote/postnote, #3: keys { \tl_if_novalue:nTF {#2} { @@ -120,25 +124,27 @@ { \prop_clear:N \l__csl_cite_item_prop \prop_put:Nnn \l__csl_cite_item_prop { id } {#3} + % \bool_if:T \l__csl_suppress_author_bool + % { \prop_put:Nnn \l__csl_cite_item_prop { suppress-author } { true } } + % \bool_if:T \l__csl_author_only_bool + % { \prop_put:Nnn \l__csl_cite_item_prop { author-only } { true } } \tl_if_empty:nF {#1} { \tl_set:Nn \l__csl_prefix_tl {#1} \tl_put_right:NV \l__csl_prefix_tl \l__csl_prefix_separator_tl - \prop_put:NnV \l__csl_cite_item_prop { prefix } { \l__csl_prefix_tl } + \prop_put:NnV \l__csl_cite_item_prop { prefix } \l__csl_prefix_tl } - \tl_if_in:nnTF {#2} { = } + \tl_if_empty:nF {#2} { - \keys_set:nn { csl / cite-item } {#2} - } - { - \tl_if_empty:nF {#2} + \tl_if_in:nnTF {#2} { = } + { \keys_set:nn { csl / cite-item } {#2} } { \regex_match:nnTF { \d+ } {#2} { \__csl_set_locator:nn { page } {#2} } { \tl_set:Nn \l__csl_suffix_tl {#2} \tl_put_left:NV \l__csl_suffix_tl \l__csl_suffix_separator_tl - \prop_put:NnV \l__csl_cite_item_prop { suffix } { \l__csl_suffix_tl } + \prop_put:NnV \l__csl_cite_item_prop { suffix } \l__csl_suffix_tl } } } @@ -202,20 +208,26 @@ \tl_new:N \l__csl_citation_info_tl \tl_new:N \l__csl_citation_tl \prop_new:N \g__csl_citations_prop +\prop_clear:N \l__csl_citation_prop \cs_new:Npn \__csl_make_citation:NN #1#2 % #1: \l__csl_cite_keys_seq % #2: \l__csl_cite_items_seq { + \prop_clear:N \l__csl_citation_prop \__csl_process_citation_id:NN \l__csl_citation_id_tl #1 + \prop_put:NnV \l__csl_citation_prop { citationID } \l__csl_citation_id_tl \tl_set:Nx \l__csl_cite_items_tl { \seq_use:Nn #2 { , } } - \exp_args:NNV \__csl_process_note_index:Nn \l__csl_note_index_tl \l__csl_citation_id_tl - \tl_set:Nx \l__csl_citation_info_tl + \prop_put:NnV \l__csl_citation_prop { citationItems } \l__csl_cite_items_tl + \__csl_get_note_index:N \l__csl_note_index_tl + \prop_put:Nnx \l__csl_citation_prop { properties } { noteIndex = { \l__csl_note_index_tl } } + \tl_clear:N \l__csl_citation_info_tl + \prop_map_inline:Nn \l__csl_citation_prop { - { \l__csl_citation_id_tl } - { \l__csl_cite_items_tl } - { \l__csl_note_index_tl } + \tl_if_empty:NF \l__csl_citation_info_tl + { \tl_put_right:Nn \l__csl_citation_info_tl { , } } + \tl_put_right:Nn \l__csl_citation_info_tl { ##1 = { ##2 } } } \exp_args:NV \__csl_write_aux_citation:n \l__csl_citation_info_tl \prop_get:NVNTF \g__csl_citations_prop \l__csl_citation_id_tl @@ -224,8 +236,9 @@ { \bool_if:NTF \l__csl_engine_initialized_bool { - \tl_set:Nx \l__csl_citation_tl + \tl_set:Nf \l__csl_citation_tl { \lua_now:e { csl.cite("\l__csl_citation_info_tl") } } + \exp_args:NV \__csl_print_citation:n \l__csl_citation_tl } { \exp_args:Nx \__csl_print_undefined_citation:n @@ -261,26 +274,18 @@ } -\int_new:N \l__csl_note_index_int -\int_gzero_new:N \g__csl_last_note_index_int -\int_gzero_new:N \g__csl_citation_note_count_int - -\cs_new:Npn \__csl_process_note_index:Nn #1#2 - % #1 \l__csl_note_index_tl - % #2: citationID +% Save the note number to \l__csl_note_index_tl +% TODO: multiple citations in a note +\cs_new:Npn \__csl_get_note_index:N #1 + % #1: \l__csl_note_index_tl { - \int_set_eq:Nc \l__csl_note_index_int { c@ \@mpfn } - \prop_if_in:NnTF \g__csl_citations_prop {#2} - { \int_incr:N \l__csl_note_index_int } - { \int_gincr:N \g__csl_citation_note_count_int } - \int_add:Nn \l__csl_note_index_int { \g__csl_citation_note_count_int } - \tl_set:Nx #1 { \int_use:N \l__csl_note_index_int } - \int_gset_eq:NN \g__csl_last_note_index_int \l__csl_note_index_int - \int_compare:nT { \l__csl_note_index_int < \g__csl_last_note_index_int } + \bool_if:NTF \l__csl_note_style_bool { - \int_gzero:N \g__csl_last_note_index_int - \int_gzero:N \g__csl_citation_note_count_int + \int_set_eq:Nc \l_tmpa_int { c@ \@mpfn } + \int_incr:N \l_tmpa_int + \tl_set:Nx #1 { \int_use:N \l_tmpa_int } } + { \tl_set:Nn #1 { 0 } } } @@ -294,6 +299,16 @@ } +% \cs_new:Npn \__csl_print_citation:n #1 +% % #1: citation text +% { +% \bool_if:NTF \l__csl_note_style_bool +% { +% \footnote {#1} +% } +% {#1} +% } + \cs_new:Npn \__csl_print_citation:n #1 % #1: "{<type>}{<citation text>}" { \__csl_print_citation_aux:nn #1 } @@ -330,17 +345,36 @@ \cs_new:Npn \__csl_no_cite:n #1 { - \__csl_if_preamble:TF + \seq_clear:N \l__csl_cite_keys_seq + \seq_clear:N \l__csl_cite_items_seq + \__csl_process_cite_items:nnn { } { } {#1} + \tl_set:Nx \l__csl_cite_items_tl + { \seq_use:Nn \l__csl_cite_items_seq { , } } + \tl_set:Nx \l__csl_citation_info_tl { - \AtBeginDocument - { \__csl_write_aux_citation:n { { nocite } {#1} { } } } + citationID = { @nocite } , + citationItems = { \l__csl_cite_items_tl } , + properties = { noteIndex = { 0 } } } - { \__csl_write_aux_citation:n { { nocite } {#1} { } } } + \exp_args:NV \__csl_no_cite_write_aux:n \l__csl_citation_info_tl \sys_if_engine_luatex:T { \lua_now:n { csl.nocite("#1") } } } +\cs_new:Npn \__csl_no_cite_write_aux:n #1 + { + \__csl_if_preamble:TF + { + \AtBeginDocument + { \exp_args:Nx \__csl_write_aux_citation:n { #1 } } + } + { + \exp_args:Nx \__csl_write_aux_citation:n { #1 } + } + } + + \prg_new_conditional:Nnn \__csl_if_preamble: { T , F , TF } { \if_meaning:w \@begindocumenthook \@undefined @@ -352,6 +386,7 @@ % Used in aux files to register cite items. +% #1: a citation object \cs_set:Npn \citation #1 { \sys_if_engine_luatex:T @@ -362,9 +397,9 @@ \cs_new:Npn \cslcite #1#2 { \bibcite {#1} {#2} - \if@filesw - \iow_now:Nn \@auxout { \bibcite {#1} {#2} } - \fi + % \if@filesw + % \iow_now:Nn \@auxout { \bibcite {#1} {#2} } + % \fi } @@ -444,6 +479,8 @@ entry-spacing = { 1 } , } +\ProcessKeysPackageOptions { csl } + \bool_new:N \l__csl_engine_initialized_bool \prop_set_from_keyval:Nn \l__csl_babel_locale_mapping_prop @@ -590,6 +627,7 @@ } \str_if_eq:eeT { \lua_now:n { tex.print(csl.initialized) } } { true } { \bool_set_true:N \l__csl_engine_initialized_bool } + \__csl_get_style_class: \@ifpackageloaded { hyperref } { \lua_now:n { csl.enable_linking() } } { } @@ -614,6 +652,21 @@ \fi } + +\str_new:N \l__csl_style_class_str +% In-text (including numeric or author-date) or note style +\bool_new:N \l__csl_note_style_bool + +\cs_new:Npn \__csl_get_style_class: { + \bool_if:NT \l__csl_engine_initialized_bool + { + \str_set:Nx \l__csl_style_class_str { \lua_now:n { csl.get_style_class() } } + \str_if_eq:VnT \l__csl_style_class_str { note } + { \bool_set_true:N \l__csl_note_style_bool } + } +} + + \clist_new:N \l__csl_options_clist \cs_new:Npn \__csl_write_aux_csl_options: @@ -972,6 +1025,19 @@ } +% csquotes + +\AtEndOfPackageFile* { csquotes } + { + \BlockquoteDisable + { + \cs_set_eq:NN \__csl_make_citation:NN \use_none:nn + % \sys_if_engine_luatex:T + % { \lua_now:n { csl.preview_mode = true } } + } + } + + % hyperref % The hyperref package also patches \bibcite but it cannot provide hyperlinks |