summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty')
-rw-r--r--Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty185
1 files changed, 148 insertions, 37 deletions
diff --git a/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty b/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty
index db83bced06c..65bc15d1162 100644
--- a/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty
+++ b/Master/texmf-dist/tex/latex/citation-style-language/citation-style-language-init.sty
@@ -16,8 +16,9 @@
{ \__csl_initialize_lua_module: }
{
\__csl_load_bbl:
- \__csl_read_style_class:
+ \__csl_get_style_class:
}
+ \__csl_set_ref_section_level:
}
@@ -25,19 +26,20 @@
\cs_new:Npn \__csl_write_aux_info:
{
+ \tl_if_empty:NF \l__csl_style_tl
+ { \exp_args:NV \__csl_write_aux_bibstyle:n \l__csl_style_tl }
+ \tl_if_empty:NT \l__csl_style_tl
+ { \tl_set_eq:NN \l__csl_style_tl \g__csl_aux_bibstyle_tl }
\tl_if_empty:NT \l__csl_style_tl
- {
- \tl_set_eq:NN \l__csl_style_tl \g__csl_aux_bibstyle_tl
- \edef \csl@style { \g__csl_aux_bibstyle_tl }
- }
- \tl_if_empty:VTF \l__csl_style_tl
{
\msg_warning:nn { citation-style-language } { missing-style-name }
\tl_set:Nn \l__csl_style_tl { apa }
}
- { \exp_args:NV \__csl_write_aux_bibstyle:n \l__csl_style_tl }
- \clist_if_empty:NTF \l__csl_bib_resources_clist
+ \tl_set_eq:NN \csl@style \l__csl_style_tl
+ \clist_if_empty:NT \l__csl_bib_resources_clist
{ \clist_set_eq:NN \l__csl_bib_resources_clist \g__csl_aux_bib_files_clist }
+ \clist_if_empty:NTF \l__csl_bib_resources_clist
+ { \msg_warning:nn { citation-style-language } { empty-bib-resources } }
{
\exp_args:Nx \__csl_write_aux_bibdata:n
{ \clist_use:Nn \l__csl_bib_resources_clist { , } }
@@ -48,7 +50,11 @@
\cs_new:Npn \__csl_write_aux_bibstyle:n #1
{
\if@filesw
- \iow_now:Nx \@auxout { \token_to_str:N \csl@aux@style {#1} }
+ \iow_now:Nx \@auxout
+ {
+ \token_to_str:N \csl@aux@style
+ { \int_use:N \g__csl_ref_section_index_int } {#1}
+ }
\fi
}
@@ -56,42 +62,56 @@
{
\if@filesw
% Full expansion for files like \jobname.bib
- \iow_now:Nx \@auxout { \token_to_str:N \csl@aux@data {#1} }
+ \iow_now:Nx \@auxout
+ {
+ \token_to_str:N \csl@aux@data
+ { \int_use:N \g__csl_ref_section_index_int } {#1}
+ }
\fi
}
% In earlier time, \bibdata{xxx.json} was used but this causes latexmk unable
% to find xxx.json.bib and it refuses to run the $bibtex procedure.
% John Collins suggests using a different command than \bibdata.
-\cs_new:Npn \csl@aux@data #1
- { \clist_gput_right:Nn \g__csl_aux_bib_files_clist {#1} }
+\cs_new:Npn \csl@aux@data #1#2
+ {
+ \str_if_eq:nnT {#1} { 0 }
+ { \clist_gput_right:Nn \g__csl_aux_bib_files_clist {#2} }
+ }
\cs_new:Npn \__csl_initialize_lua_module:
{
- \clist_if_empty:NT \l__csl_bib_resources_clist
- { \msg_warning:nn { citation-style-language } { empty-bib-resources } }
+ \tl_set:Nx \l_tmpa_tl { \clist_use:Nn \l__csl_bib_resources_clist { , } }
\lua_now:e
{
- csl.init(
+ csl_citation_manager:init(
"\l__csl_style_tl",
- "\l__csl_bib_resources_clist",
+ "\l_tmpa_tl",
"\l__csl_locale_tl"
)
}
-
-
- \str_if_eq:eeT { \lua_now:n { tex.print(csl.initialized) } } { true }
+ \str_if_eq:eeTF
+ {
+ \lua_now:n
+ {
+ tex.print(tostring(
+ csl_citation_manager.ref_section.initialized
+ ))
+ }
+ }
+ { true }
{ \bool_set_true:N \l__csl_engine_initialized_bool }
- \__csl_get_style_class:
+ { \bool_set_false:N \l__csl_engine_initialized_bool }
+ \__csl_get_style_class_luatex:
\@ifpackageloaded { hyperref }
- { \lua_now:n { csl.enable_linking() } }
+ { \lua_now:n { csl_citation_manager:enable_linking() } }
{ }
}
\msg_new:nnn { citation-style-language } { missing-style-name }
- { Missing~ style~ name.\\Will~ use~ default~ APA~ style. }
+ { Missing~ style~ name.~ Will~ use~ default~ APA~ style. }
\msg_new:nnn { citation-style-language } { empty-bib-resources }
{ Empty~ bibliographic~ resources.~ Use~ \token_to_str:N \addbibresource. }
@@ -101,13 +121,16 @@
% 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: {
+\cs_new:Npn \__csl_get_style_class_luatex: {
+ \bool_set_false:N \l__csl_note_bool
\bool_if:NT \l__csl_engine_initialized_bool
{
- \tl_set:Nx \l__csl_class_tl { \lua_now:n { csl.get_style_class() } }
+ \tl_set:Nx \l__csl_class_tl { \lua_now:n { tex.print(csl_citation_manager:get_style_class()) } }
\tl_if_eq:NnT \l__csl_class_tl { note }
{ \bool_set_true:N \l__csl_note_bool }
}
+ \int_compare:nNnT { \g__csl_ref_section_index_int } = { 0 }
+ { \bool_gset_eq:NN \g__csl_global_note_class_bool \l__csl_note_bool }
}
@@ -266,14 +289,16 @@
\cs_new:Npn \__csl_write_aux_options:n #1
{
\if@filesw
- \iow_now:Nn \@auxout { \csl@aux@options {#1} }
+ \iow_now:Nx \@auxout
+ {
+ \token_to_str:N \csl@aux@options
+ { \int_use:N \g__csl_ref_section_index_int } {#1}
+ }
\fi
}
-\cs_new:Npn \csl@aux@options #1 { }
-
+\cs_new:Npn \csl@aux@options #1#2 { }
-\tl_new:N \g__csl_bibliography_setup_tl
% Load .bbl at the beginning of document to save one pass of latex.
% In this procedure, the \cslcitation command is processed and the contents
@@ -283,10 +308,6 @@
% The \@input@ prints "No file ....bbl" in the .log file from which
% the latexmk decides to run $bibtex or not.
\__csl_collect_bibliography:n { \@input@ { \jobname .bbl } }
- % Execute the \cslsetup part to set the style class.
- % \tl_show:N \g__csl_bibliography_setup_tl
- \tl_use:N \g__csl_bibliography_setup_tl
- % \bool_show:N \l__csl_note_bool
}
@@ -302,8 +323,6 @@
% URLs may contain "%" and "#" characters.
\char_set_catcode_other:N \%
\char_set_catcode_other:N \#
- \RenewDocumentCommand \cslsetup { m }
- { \tl_gset:Nn \g__csl_bibliography_setup_tl { \cslsetup { ##1 } } }
\RenewDocumentEnvironment { thebibliography } { m +b }
{
\tl_set:Nn \l__csl_bib_index_tl { 1 }
@@ -321,29 +340,121 @@
\group_end:
}
+% At the moment, the `\csloptions` only reads the style class from `.bbl`
+% generated by `citeproc-lua`.
+% #1: refsection index
+% #2: refsection options
+\NewDocumentCommand \csloptions { m m }
+ { \keys_set:nn { csl / options } { #2 } }
+
+% The class option is in the `<style>=<class>` form
+% (e.g. `\csloptions{class={apa=in-text}}`).
+\keys_define:nn { csl / options }
+ {
+ class .code:n = { \prop_gput_from_keyval:Nn \g__csl_style_class_prop {#1} },
+ }
+
+\prop_new:N \g__csl_style_class_prop
% The `\textcite` bahaves differently with note styles.
% Thus we read the style class from the `.csl` file with non-LuaTeX engines.
\ior_new:N \l__csl_style_ior
-\cs_new:Npn \__csl_read_style_class:
+\cs_new:Npn \__csl_get_style_class:
{
+ \tl_clear:N \l__csl_class_tl
\bool_set_false:N \l__csl_note_bool
+ \prop_get:NVNF \g__csl_style_class_prop \l__csl_style_tl \l__csl_class_tl
+ { \__csl_read_style_class: }
+ \tl_if_empty:NF \l__csl_class_tl
+ {
+ \str_case:VnTF \l__csl_class_tl
+ {
+ { note } { \bool_set_true:N \l__csl_note_bool }
+ { in-text } { \bool_set_false:N \l__csl_note_bool }
+ }
+ {
+ \int_compare:nNnT { \g__csl_ref_section_index_int } = { 0 }
+ {
+ \bool_gset_eq:NN \g__csl_global_note_class_bool \l__csl_note_bool
+ }
+ }
+ {
+ \msg_error:nnV { citation-style-language } { invalid-style-class }
+ \l__csl_class_tl
+ }
+ }
+ }
+
+\cs_new:Npn \__csl_read_style_class:
+ {
\tl_if_blank:VF \l__csl_style_tl
{
\exp_args:NNx \ior_open:Nn \l__csl_style_ior { \l__csl_style_tl .csl }
\ior_map_inline:Nn \l__csl_style_ior
{
% \tl_show:n {##1}
- \tl_if_in:nnT {##1} { class="note" }
+ \tl_if_in:nnTF {##1} { class="note" }
{
\tl_set:Nn \l__csl_class_tl { note }
\bool_set_true:N \l__csl_note_bool
+ \prop_gput:NVn \g__csl_style_class_prop \l__csl_style_tl { note }
\ior_map_break:
}
+ {
+ \tl_if_in:nnT {##1} { class="in-text" }
+ {
+ \tl_set:Nn \l__csl_class_tl { in-text }
+ \bool_set_false:N \l__csl_note_bool
+ \prop_gput:NVn \g__csl_style_class_prop \l__csl_style_tl { in-text }
+ \ior_map_break:
+ }
+ }
}
\ior_close:N \l__csl_style_ior
}
}
-% \msg_new:nnn { citation-style-language } { file / non-exist }
+\msg_new:nnn { citation-style-language } { invalid-style-class }
+ { Invalid~ style~ class~ '#1'. }
+
+% \msg_new:nnn { citation-style-language } { file-non-exist }
% { No~ file~ #1. }
+
+\cs_new:Npn \__csl_set_ref_section_level:
+ {
+ \str_case:Vn \l__csl_bib_ref_section_str
+ {
+ { none } { }
+ { part }
+ { \__csl_patch_ref_section:n { part } }
+ { chapter }
+ { \__csl_patch_ref_section:n { chapter } }
+ { chapter+ }
+ {
+ \__csl_patch_ref_section:n { part }
+ \__csl_patch_ref_section:n { chapter }
+ }
+ { section }
+ { \__csl_patch_ref_section:n { section } }
+ { section+ }
+ {
+ \__csl_patch_ref_section:n { part }
+ \__csl_patch_ref_section:n { chapter }
+ \__csl_patch_ref_section:n { section }
+ }
+ { subsection }
+ { \__csl_patch_ref_section:n { subsection } }
+ { subsection+ }
+ {
+ \__csl_patch_ref_section:n { part }
+ \__csl_patch_ref_section:n { chapter }
+ \__csl_patch_ref_section:n { section }
+ \__csl_patch_ref_section:n { subsection }
+ }
+ }
+ }
+
+\cs_new:Npn \__csl_patch_ref_section:n #1
+ {
+ \hook_gput_code:nnn { cmd / #1 / before } { . } { \newrefsection }
+ }