% -------------------------------------------------------------------------- % the ACRO package % % Typeset Acronyms % % -------------------------------------------------------------------------- % Clemens Niederberger % Web: https://bitbucket.org/cgnieder/acro/ % E-Mail: contact@mychemistry.eu % -------------------------------------------------------------------------- % Copyright 2011-2013 Clemens Niederberger % % 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. % % This work has the LPPL maintenance status `maintained'. % % The Current Maintainer of this work is Clemens Niederberger. % -------------------------------------------------------------------------- % The acro package consists of the files % - acro.sty, acro0.def, acro1.def, acro_en.tex, acro_en.pdf, README % -------------------------------------------------------------------------- % If you have any ideas, questions, suggestions or bugs to report, please % feel free to contact me. % -------------------------------------------------------------------------- \RequirePackage{expl3,xparse,l3keys2e,xtemplate} \ProvidesExplPackage {acro} {2013/04/04} {1.2a} {Typeset Acronyms} % warning and error messages: \msg_new:nnnn { acro } { undefined } { You've~requested~acronym~`#1'~but~it~seems~that~it~was~never~defined! } { You've~requested~acronym~`#1'~\msg_line_context: \c_space_tl but~you~ apperantly~haven't~defined~it,~yet!~Maybe~you've~mispelled~it? } \msg_new:nnnn { acro } { version } { You've~selected~the~version~option~`#1'~which~doesn't~exist. } { You've~selected~the~version~option~`#1'~which~doesn't~exist.~ I'm~using~option~`#2'~instead. } % temporary variables \tl_new:N \l__acro_tmpa_tl \tl_new:N \l__acro_tmpb_tl \tl_new:N \l__acro_tmpc_tl \prop_new:N \l__acro_tmpa_prop \prop_new:N \l__acro_tmpb_prop \seq_new:N \l__acro_tmpa_seq \seq_new:N \l__acro_tmpb_seq \tl_new:N \l__acro_ignore_tl % boolean variables: \bool_new:N \l__acro_mark_as_used_bool \bool_new:N \l__acro_mark_first_as_used_bool \bool_new:N \l__acro_use_single_bool \bool_new:N \l__acro_print_only_used_bool \bool_set_true:N \l__acro_print_only_used_bool \bool_new:N \l__acro_use_plural_bool \bool_new:N \l__acro_hyperref_loaded_bool \bool_new:N \l__acro_use_hyperref_bool \bool_new:N \l__acro_custom_format_bool \bool_new:N \l__acro_strict_bool \bool_new:N \l__acro_create_macros_bool \bool_new:N \l__acro_xspace_bool \bool_new:N \l__acro_first_upper_bool \bool_new:N \l__acro_indefinite_bool \bool_new:N \l__acro_upper_indefinite_bool \bool_new:N \l__acro_sort_bool \bool_set_true:N \l__acro_sort_bool \bool_new:N \l__acro_capitalize_list_bool \bool_new:N \l__acro_citation_all_bool \bool_new:N \l__acro_citation_first_bool \bool_set_true:N \l__acro_citation_first_bool \bool_new:N \l__acro_acc_supp_bool \bool_new:N \l__acro_page_ranges_bool \bool_set_true:N \l__acro_page_ranges_bool \bool_new:N \l__acro_record_pages_bool \bool_set_true:N \l__acro_record_pages_bool \bool_new:N \l__acro_addto_index_bool % tokenlist variables: \tl_new:N \l__acro_short_format_tl \tl_new:N \l__acro_list_short_format_tl \tl_new:N \l__acro_long_format_tl \tl_new:N \l__acro_first_long_format_tl \tl_new:N \l__acro_list_long_format_tl \tl_new:N \l__acro_default_indefinite_tl \tl_set:Nn \l__acro_default_indefinite_tl { a } \tl_new:N \l__acro_extra_format_tl \tl_new:N \l__acro_first_instance_tl \tl_set:Nn \l__acro_first_instance_tl { default } \tl_new:N \l__acro_extra_instance_tl \tl_set:Nn \l__acro_extra_instance_tl { default } \tl_new:N \l__acro_page_instance_tl \tl_set:Nn \l__acro_page_instance_tl { none } \tl_new:N \l__acro_page_name_tl \tl_set:Nn \l__acro_page_name_tl { p.\@\, } \tl_new:N \l__acro_pages_name_tl \tl_set:Nn \l__acro_pages_name_tl { pp.\@\, } \tl_new:N \l__acro_next_page_tl \tl_set:Nn \l__acro_next_page_tl { \,f.\@ } \tl_new:N \l__acro_next_pages_tl \tl_set:Nn \l__acro_next_pages_tl { \,ff.\@ } \tl_new:N \l__acro_list_instance_tl \tl_set:Nn \l__acro_list_instance_tl { list } \tl_new:N \l__acro_list_type_tl \tl_set:Nn \l__acro_list_type_tl { description } \tl_new:N \l__acro_list_title_tl \tl_set:Nn \l__acro_list_title_tl { section* } \tl_new:N \l__acro_list_name_tl \tl_set:Nn \l__acro_list_name_tl { Acronyms } \tl_new:N \l__acro_short_tl \tl_new:N \l__acro_short_plural_tl \tl_new:N \l__acro_default_plural_tl \tl_set:Nn \l__acro_default_plural_tl { s } \tl_new:N \l__acro_alt_tl \tl_new:N \l__acro_long_tl \tl_new:N \l__acro_long_pre_tl \tl_new:N \l__acro_long_post_tl \tl_new:N \l__acro_custom_format_tl \tl_new:N \l__acro_first_between_tl \tl_new:N \l__acro_citation_space_tl \tl_set:Nn \l__acro_citation_space_tl { \nobreakspace } % property list variables: \prop_new:N \l__acro_short_prop \prop_new:N \l__acro_alt_prop \prop_new:N \l__acro_sort_prop \prop_new:N \l__acro_long_prop \prop_new:N \l__acro_class_prop \prop_new:N \l__acro_replace_plural_prop \prop_new:N \l__acro_short_plural_prop \prop_new:N \l__acro_long_plural_prop \prop_new:N \l__acro_short_indefinite_prop \prop_new:N \l__acro_long_indefinite_prop \prop_new:N \l__acro_alt_indefinite_prop \prop_new:N \l__acro_long_pre_prop \prop_new:N \l__acro_long_post_prop \prop_new:N \l__acro_extra_prop \prop_new:N \l__acro_format_prop \prop_new:N \l__acro_long_format_prop \prop_new:N \l__acro_first_long_format_prop \prop_new:N \l__acro_citation_prop \prop_new:N \l__acro_citation_pre_prop \prop_new:N \l__acro_citation_post_prop \prop_new:N \l__acro_pdfstring_prop \prop_new:N \l__acro_pdfstring_plural_prop \prop_new:N \l__acro_acc_supp_prop \prop_new:N \l__acro_index_prop \prop_new:N \l__acro_index_sort_prop \prop_new:N \l__acro_index_cmd_prop % length variables: \dim_new:N \l__acro_table_width_dim \dim_set:Nn \l__acro_table_width_dim { .7\linewidth } \cs_new:Npn \__acro_citation_cmd:w { \cite } \cs_new:Npn \__acro_no_break: { \tex_penalty:D \c_ten_thousand } \cs_new:Npn \__acro_index_cmd:n { \index } \cs_new:Npn \__acro_first_upper_case:n #1 { \tl_expandable_uppercase:n { \tl_head:n { #1 } } \tl_tail:n { #1 } } \cs_generate_variant:Nn \__acro_first_upper_case:n { x } \cs_new_eq:NN \acro_first_upper_case:n \__acro_first_upper_case:n % -------------------------------------------------------------------------- % versioning: \tl_new:N \l__acro_active_version_tl \tl_new:N \l__acro_version_zero_tl \tl_set:Nn \l__acro_version_zero_tl { 0 } \clist_new:N \l__acro_versions_clist \clist_put_right:Nn \l__acro_versions_clist { 0 } \clist_put_right:Nn \l__acro_versions_clist { 1 } \bool_new:N \l__acro_version_selected_bool \cs_new:Npn \__acro_select_version:n #1 { \clist_if_in:NnTF \l__acro_versions_clist { #1 } { \file_input:n { acro#1.def } \tl_set:Nn \l__acro_active_version_tl { #1 } } { \msg_warning:nnxx { acro } { version } { #1 } { 1 } \file_input:n { acro1.def } \tl_set:Nn \l__acro_active_version_tl { 1 } } \bool_set_true:N \l__acro_version_selected_bool } % options: \keys_define:nn { acro } { version .code:n = \__acro_select_version:n { #1 } , accsupp .bool_set:N = \l__acro_acc_supp_bool , macros .bool_set:N = \l__acro_create_macros_bool , xspace .bool_set:N = \l__acro_xspace_bool , strict .bool_set:N = \l__acro_strict_bool , sort .bool_set:N = \l__acro_sort_bool , short-format .code:n = \tl_set:Nn \l__acro_short_format_tl { #1 } \tl_set:Nn \l__acro_list_short_format_tl { #1 } , long-format .code:n = \tl_set:Nn \l__acro_long_format_tl { #1 } \tl_set:Nn \l__acro_first_long_format_tl { #1 } \tl_set:Nn \l__acro_list_long_format_tl { #1 } , first-long-format .code:n = \tl_set:Nn \l__acro_first_long_format_tl { #1 } , list-short-format .tl_set:N = \l__acro_list_short_format_tl , list-long-format .tl_set:N = \l__acro_list_long_format_tl , extra-format .tl_set:N = \l__acro_extra_format_tl , single .bool_set:N = \l__acro_use_single_bool , first-style .tl_set:N = \l__acro_first_instance_tl , extra-style .tl_set:N = \l__acro_extra_instance_tl , page-ref .tl_set:N = \l__acro_page_instance_tl , page-name .tl_set:N = \l__acro_page_name_tl , pages-name .tl_set:N = \l__acro_pages_name_tl , page-ranges .bool_set:N = \l__acro_page_ranges_bool , record-pages .bool_set:N = \l__acro_record_pages_bool , next-page .tl_set:N = \l__acro_next_page_tl , next-pages .tl_set:N = \l__acro_next_pages_tl , list-style .tl_set:N = \l__acro_list_instance_tl , list-type .tl_set:N = \l__acro_list_type_tl , list-header .tl_set:N = \l__acro_list_title_tl , list-name .tl_set:N = \l__acro_list_name_tl , list-table-width .dim_set:N = \l__acro_table_width_dim , hyperref .bool_set:N = \l__acro_use_hyperref_bool , only-used .bool_set:N = \l__acro_print_only_used_bool , mark-as-used .choice: , mark-as-used / first .code:n = \bool_set_true:N \l__acro_mark_first_as_used_bool , mark-as-used / any .code:n = \bool_set_false:N \l__acro_mark_first_as_used_bool , plural-ending .tl_set:N = \l__acro_default_plural_tl , list-caps .bool_set:N = \l__acro_capitalize_list_bool , cite .choice: , cite / all .code:n = \bool_set_true:N \l__acro_citation_all_bool \bool_set_true:N \l__acro_citation_first_bool , cite / none .code:n = \bool_set_false:N \l__acro_citation_all_bool \bool_set_false:N \l__acro_citation_first_bool , cite / first .code:n = \bool_set_false:N \l__acro_citation_all_bool \bool_set_true:N \l__acro_citation_first_bool , cite-all .default:n = all , cite-cmd .code:n = \cs_set:Npn \__acro_citation_cmd:w { #1 } , cite-space .tl_set:N = \l__acro_citation_space_tl , index .bool_set:N = \l__acro_addto_index_bool , index-cmd .code:n = \cs_set:Npn \__acro_index_cmd:n { #1 } , uc-cmd .code:n = \cs_set_eq:NN \__acro_first_upper_case:n #1 } \AtBeginDocument { \bool_if:NTF \l__acro_xspace_bool { \@ifpackageloaded { xspace } { } { \RequirePackage { xspace } } \cs_new_eq:NN \acro_xspace: \xspace } { \cs_new:Npn \acro_xspace: {} } \bool_if:NF \l__acro_record_pages_bool { \cs_set_eq:NN \acro_record_page_number:n \use_none:n } } % setup command: \NewDocumentCommand \acsetup { m } { \keys_set:nn { acro } { #1 } \ignorespaces } % typeset the short form: \cs_new:Npn \__acro_write_short:n #1 { \mode_if_horizontal:F { \leavevmode } \group_begin: \bool_if:NTF \l__acro_custom_format_bool { \l__acro_custom_format_tl } { \l__acro_short_format_tl } { \hbox:n { #1 } } \group_end: \bool_if:NT \l__acro_use_plural_bool { \tl_use:N \l__acro_short_plural_tl } } \cs_generate_variant:Nn \__acro_write_short:n { V } % typeset the longform,...: % TODO: rethink the formatting mechanism % right now a custom format gets applied additionally to the global one % although before it \cs_new:Npn \__acro_write_long:Nn #1#2 { \mode_if_horizontal:F { \leavevmode } \group_begin: \bool_if:NT \l__acro_custom_long_format_bool { \l__acro_custom_long_format_tl } { \exp_args:Nx #1 { \bool_if:NTF \l__acro_first_upper_bool { \exp_not:N \__acro_first_upper_case:n { \exp_not:n { #2 } } } { \exp_not:n { #2 } } } } \group_end: } \cs_generate_variant:Nn \__acro_write_long:Nn { NV,No,Nf } % -------------------------------------------------------------------------- % hyperref support \cs_new_eq:NN \acro_hyper_target:nn \use_ii:nn \cs_new_eq:NN \acro_hyper_link:nn \use_ii:nn \cs_new:Npn \__acro_activate_hyperref_support: { \bool_if:nT { \l__acro_hyperref_loaded_bool && \l__acro_use_hyperref_bool } { \cs_set_eq:NN \acro_hyper_link:nn \hyperlink \cs_set:Npn \acro_hyper_target:nn ##1##2 { \raisebox { 3ex } [ 0pt ] { \hypertarget { ##1 } { } } ##2 } } } \cs_new:Npn \__acro_make_link:nNN #1#2#3 { \tl_set:Nn #2 { \acro_hyper_link:nn { #1 } { \phantom { #3 } } \__acro_is_single:nTF { #1 } { \hbox_overlap_left:n { #3 } } { \bool_if:nTF { \l__acro_use_hyperref_bool && \l__acro_hyperref_loaded_bool } { \acro_color_link:n { \hbox_overlap_left:n { #3 } } } { \hbox_overlap_left:n { #3 } } } } } \cs_new:Npn \acro_color_link:n #1 { \cs_if_exist:NTF \hypersetup { \ifHy@colorlinks \exp_after:wN \use_i:nn \else \ifHy@ocgcolorlinks \exp_after:wN \use_i:nn \else \exp_after:wN \exp_after:wN \exp_after:wN \use_ii:nn \fi \fi { \textcolor { \@linkcolor } { #1 } } { #1 } } { #1 } } \AtBeginDocument{ \cs_if_exist:NF \textcolor { \cs_new_eq:NN \textcolor \use_ii:nn } } % -------------------------------------------------------------------------- % output style of the first time an acronym is used \bool_new:N \l__acro_first_use_brackets_bool \bool_new:N \l__acro_first_only_short_bool \bool_new:N \l__acro_first_reversed_bool \bool_new:N \l__acro_use_note_bool \tl_new:N \l__acro_first_brackets_tl \cs_new:Npn \__acro_note_command:n #1 { #1 } % #1: id % #2: short % #3: long \DeclareObjectType { acro-first } { 3 } % template for inline appearance: \DeclareTemplateInterface { acro-first } { inline } { 3 } { brackets : boolean = true , brackets-type : tokenlist = () , only-short : boolean = false , reversed : boolean = false , between : tokenlist , } \DeclareTemplateCode { acro-first } { inline } { 3 } { brackets = \l__acro_first_use_brackets_bool , brackets-type = \l__acro_first_brackets_tl , only-short = \l__acro_first_only_short_bool , reversed = \l__acro_first_reversed_bool , between = \l__acro_first_between_tl , } { \AssignTemplateKeys \bool_if:nT { !\l__acro_first_only_short_bool && !\l__acro_first_reversed_bool } { \__acro_indefinite:nn { #1 } { long } \__acro_write_long:No \l__acro_first_long_format_tl { #3 } \tl_use:N \c_space_tl \tl_if_blank:VF \l__acro_first_between_tl { \tl_use:N \l__acro_first_between_tl \tl_use:N \c_space_tl } } \bool_if:nT { \l__acro_first_use_brackets_bool && !\l__acro_first_reversed_bool } { \tl_head:N \l__acro_first_brackets_tl } \bool_if:nT { \l__acro_first_reversed_bool || \l__acro_first_only_short_bool } { \__acro_indefinite:nn { #1 } { short } } \__acro_acc_supp:nn { #1 } { \__acro_write_short:n { #2 } } \bool_if:nT { \l__acro_first_use_brackets_bool && !\l__acro_first_reversed_bool } { \tl_tail:N \l__acro_first_brackets_tl } \bool_if:nT { !\l__acro_first_only_short_bool && \l__acro_first_reversed_bool } { \tl_if_blank:VF \l__acro_first_between_tl { \tl_use:N \c_space_tl \tl_use:N \l__acro_first_between_tl } \tl_use:N \c_space_tl \bool_if:nT { \l__acro_first_use_brackets_bool && \l__acro_first_reversed_bool } { \tl_head:N \l__acro_first_brackets_tl } \__acro_write_long:No \l__acro_first_long_format_tl { #3 } \bool_if:nT { \l__acro_first_use_brackets_bool && \l__acro_first_reversed_bool } { \tl_tail:N \l__acro_first_brackets_tl } } \__acro_cite_if:Nn \l__acro_citation_first_bool { #1 } \__acro_index_if:Nn \l__acro_addto_index_bool { #1 } } % template for footnotes, sidenotes, ... \DeclareTemplateInterface { acro-first } { note } { 3 } { use-note : boolean = true , note-command : function 1 = \footnote { #1 } } \DeclareTemplateCode { acro-first } { note } { 3 } { use-note = \l__acro_use_note_bool , note-command = \__acro_note_command:n } { \AssignTemplateKeys \__acro_indefinite:nn { #1 } { short } \__acro_acc_supp:nn { #1 } { \__acro_write_short:n { #2 } } \bool_if:NT \l__acro_use_note_bool { \__acro_note_command:n { \__acro_write_long:No \l__acro_first_long_format_tl { #3 } \__acro_cite_if:Nn \l__acro_citation_first_bool { #1 } \__acro_index_if:Nn \l__acro_addto_index_bool { #1 } } } } % the different styles: \DeclareInstance { acro-first } { default } { inline } { } \DeclareInstance { acro-first } { square } { inline } { brackets-type = [] } \DeclareInstance { acro-first } { plain } { inline } { brackets = false , between = -- } \DeclareInstance { acro-first } { plain-reversed } { inline } { brackets = false , between = -- , reversed = true } \DeclareInstance { acro-first } { footnote } { note } { } \DeclareInstance { acro-first } { sidenote } { note } { note-command = \sidenote { #1 } } \DeclareInstance { acro-first } { empty } { note } { use-note = false } \DeclareInstance { acro-first } { short } { inline } { only-short = true , brackets = false } \DeclareInstance { acro-first } { reversed } { inline } { reversed = true } % -------------------------------------------------------------------------- % formatting the extras information: \bool_new:N \l__acro_extra_punct_bool \bool_new:N \l__acro_extra_use_brackets_bool \tl_new:N \l__acro_extra_brackets_tl \tl_new:N \l__acro_extra_punct_tl \DeclareObjectType { acro-extra } { 1 } \DeclareTemplateInterface { acro-extra } { default } { 1 } { punct : boolean = false , punct-symbol : tokenlist = {,} , brackets : boolean = true , brackets-type : tokenlist = () } \DeclareTemplateCode { acro-extra } { default } { 1 } { punct = \l__acro_extra_punct_bool , punct-symbol = \l__acro_extra_punct_tl , brackets = \l__acro_extra_use_brackets_bool , brackets-type = \l__acro_extra_brackets_tl } { \AssignTemplateKeys \bool_if:NT \l__acro_extra_punct_bool { \tl_use:N \l__acro_extra_punct_tl \tl_use:N \c_space_tl } \bool_if:NT \l__acro_extra_use_brackets_bool { \tl_head:N \l__acro_extra_brackets_tl } \__acro_write_long:Nn \l__acro_extra_format_tl { #1 } \bool_if:NT \l__acro_extra_use_brackets_bool { \tl_tail:N \l__acro_extra_brackets_tl } } % the different styles: \DeclareInstance { acro-extra } { default } { default } { brackets = false , punct = true , punct-symbol = . } \DeclareInstance { acro-extra } { plain } { default } { brackets = false , punct = false } \DeclareInstance { acro-extra } { paren } { default } { } \DeclareInstance { acro-extra } { bracket } { default } { brackets-type=[] } \DeclareInstance { acro-extra } { comma } { default } { punct = true, brackets = false } % -------------------------------------------------------------------------- % outputting the page numbers: (experimental, needs lots of improvements) \bool_new:N \l__acro_page_punct_bool \bool_new:N \l__acro_page_brackets_bool \bool_new:N \l__acro_page_display_bool \tl_new:N \l__acro_page_punct_tl \tl_new:N \l__acro_page_brackets_tl \dim_new:N \l__acro_page_space_dim \cs_new:Npn \acro_create_page_records:n #1 { \seq_new:c { g__acro_#1_tmp_seq } \seq_new:c { g__acro_#1_pages_seq } } \cs_new:Npn \ac@hp #1 { \tl_if_in:nnTF { #1 } { \ac@no@hp } { #1 } { \acro_hyper_page:n { #1 } } } \cs_new_protected:Npn \ac@no@hp {} \cs_new:Npn \__acro_safe_pages_aux:n #1 { \noexpand \ac@hp {#1}| } \cs_new_eq:NN \acro_hyper_page:n \use:n \cs_new:Npn \acro_safe_pages:n #1 { \iow_now:Nx \@auxout { \exp_not:n { \global \@namedef } { acro@#1@pages } { \seq_map_function:cN { g__acro_#1_pages_seq } \__acro_safe_pages_aux:n } } } \AtEndDocument { \prop_map_inline:Nn \l__acro_short_prop { \acro_finalize_page_numbers:n { #1 } \acro_safe_pages:n { #1 } } } \tl_new:N \l__acro_tmp_page_tl \tl_new:N \l__acro_last_page_tl \tl_new:N \g__acro_current_page_style_tl \tl_new:N \g__acro_last_page_style_tl \bool_new:N \g__acro_know_page_style_bool %TODO: this should be translated into expl3 syntax \cs_new:Npn \__acro_if_is_number:nTF #1 { \if!\ifnum9<1#1!\expandafter\expandafter\expandafter\@firstoftwo\fi \else \expandafter\@secondoftwo \fi } \cs_new:Npn \__acro_convert_to_arabic:n #1 { \__acro_if_is_number:nTF { #1 } { #1 } { \exp_args:Nf \int_from_roman:n { \tl_expandable_lowercase:n { #1 } } } } \cs_generate_variant:Nn \__acro_convert_to_arabic:n { V } \cs_new:Npn \__acro_check_for_style:n #1 { \tl_if_in:xxT { \tl_to_str:V { \thepage } } { \tl_to_str:n { #1 } } { \tl_gset:Nn \g__acro_current_page_style_tl { #1 } \bool_gset_true:N \g__acro_know_page_style_bool } } \cs_generate_variant:Nn \tl_if_in:nnT { xx } \cs_generate_variant:Nn \tl_to_str:n { V } \cs_new:Npn \acro_check_page_style: { \tl_gset:Nn \g__acro_current_page_style_tl { unknown } \bool_gset_false:N \g__acro_know_page_style_bool \__acro_check_for_style:n { roman } \__acro_check_for_style:n { Roman } \__acro_check_for_style:n { arabic } } \cs_new:Npn \acro_record_page_number:n #1 { \tl_gset_eq:NN \g__acro_last_page_style_tl \g__acro_current_page_style_tl \acro_check_page_style: \bool_if:NT \g__acro_know_page_style_bool { \seq_if_empty:cTF { g__acro_#1_pages_seq } {% no pages recorded, yet \seq_gput_right:cx { g__acro_#1_pages_seq } { \use:c { \g__acro_current_page_style_tl } { page } } \seq_gput_right:cx { g__acro_#1_tmp_seq } { \use:c { \g__acro_current_page_style_tl } { page } } } { \seq_get_right:cN { g__acro_#1_tmp_seq } \l__acro_tmp_page_tl \seq_get_right:cN { g__acro_#1_pages_seq } \l__acro_last_page_tl \tl_if_eq:NNTF \l__acro_tmp_page_tl \l__acro_last_page_tl {% range may have started \bool_if:nF { \int_compare_p:n { \value{page} = \__acro_convert_to_arabic:V \l__acro_tmp_page_tl } && \tl_if_eq_p:NN \g__acro_last_page_style_tl \g__acro_current_page_style_tl } { \int_compare:nNnTF { \value{page} } = { \__acro_convert_to_arabic:V \l__acro_tmp_page_tl + 1 } {% range continues \seq_gput_right:cx { g__acro_#1_tmp_seq } { \use:c { \g__acro_current_page_style_tl } { page } } } {% no range (any more) \seq_gput_right:cx { g__acro_#1_pages_seq } { \ac@no@hp,~ } \seq_gclear:c { g__acro_#1_tmp_seq } \seq_gput_right:cx { g__acro_#1_tmp_seq } { \use:c { \g__acro_current_page_style_tl } { page } } \seq_gput_right:cx { g__acro_#1_pages_seq } { \use:c { \g__acro_current_page_style_tl } { page } } } } } {% we're in a range \int_compare:nNnF { \value{page} } = { \__acro_convert_to_arabic:V \l__acro_tmp_page_tl } { \int_compare:nNnTF { \value{page} } = { \__acro_convert_to_arabic:V \l__acro_tmp_page_tl + 1 } {% range continues \seq_gput_right:cx { g__acro_#1_tmp_seq } { \use:c { \g__acro_current_page_style_tl } { page } } } {% no range (any more) \int_compare:nNnTF { \__acro_convert_to_arabic:V \l__acro_tmp_page_tl } = { \__acro_convert_to_arabic:V \l__acro_last_page_tl +1 } { \bool_if:NTF \l__acro_page_ranges_bool { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp,~ } \seq_gput_right:cx { g__acro_#1_pages_seq } { \l__acro_tmp_page_tl } } { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp\l__acro_next_page_tl } } } { \bool_if:NTF \l__acro_page_ranges_bool { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp-- } \seq_gput_right:cx { g__acro_#1_pages_seq } { \l__acro_tmp_page_tl } } { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp\l__acro_next_pages_tl } } } \seq_gclear:c { g__acro_#1_tmp_seq } \seq_gput_right:cx { g__acro_#1_tmp_seq } { \use:c { \g__acro_current_page_style_tl } { page } } \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp,~ } \seq_gput_right:cx { g__acro_#1_pages_seq } { \use:c { \g__acro_current_page_style_tl } { page } } } } } } } } \cs_new:Npn \acro_finalize_page_numbers:n #1 { \seq_get_right:cN { g__acro_#1_tmp_seq } \l__acro_tmp_page_tl \seq_get_right:cN { g__acro_#1_pages_seq } \l__acro_last_page_tl \tl_if_eq:NNF \l__acro_tmp_page_tl \l__acro_last_page_tl { \int_compare:nNnTF { \__acro_convert_to_arabic:V \l__acro_tmp_page_tl } = { \__acro_convert_to_arabic:V \l__acro_last_page_tl +1 } { \bool_if:NTF \l__acro_page_ranges_bool { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp,~ } \seq_gput_right:cx { g__acro_#1_pages_seq } { \l__acro_tmp_page_tl } } { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp\l__acro_next_page_tl } } } { \bool_if:NTF \l__acro_page_ranges_bool { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp-- } \seq_gput_right:cx { g__acro_#1_pages_seq } { \l__acro_tmp_page_tl } } { \seq_gput_right:cn { g__acro_#1_pages_seq } { \ac@no@hp\l__acro_next_pages_tl } } } } } \cs_new:Npn \acro_print_page_numbers:n #1 { \cs_if_exist:cTF { acro@#1@pages } { \tl_set_eq:Nc \l__acro_tmpa_tl { acro@#1@pages } \__acro_print_page_numbers:n { #1 } } { ?? } } \cs_new:Npn \__acro_print_page_numbers:n #1 { \seq_set_split:NnV \l__acro_tmpb_seq { | } \l__acro_tmpa_tl \seq_pop_right:NN \l__acro_tmpb_seq \l__acro_ignore_tl \int_compare:nNnTF { \seq_count:N \l__acro_tmpb_seq } = { 1 } { \l__acro_page_name_tl } { \l__acro_pages_name_tl } \acro_no_break: \skip_horizontal:N \l__acro_page_space_dim \acro_no_break: \seq_map_inline:Nn \l__acro_tmpb_seq { ##1 } } \AtBeginDocument { \tl_if_eq:NNT \l__acro_active_version_tl \l__acro_version_zero_tl { \cs_set:Npn \__acro_print_page_numbers:n #1 { \acro_no_break: \skip_horizontal:N \l__acro_page_space_dim \acro_no_break: \tl_use:N \l__acro_page_name_tl \pageref{ac:#1} } } } \cs_new:Npn \acro_no_break: { \tex_penalty:D \c_ten_thousand } \DeclareObjectType { acro-page-number } { 1 } \DeclareTemplateInterface { acro-page-number } { default } { 1 } { display : boolean = true , punct : boolean = false , punct-symbol : tokenlist = {,} , brackets : boolean = false , brackets-type : tokenlist = () , space : length = .3ex } \DeclareTemplateCode { acro-page-number } { default } { 1 } { display = \l__acro_page_display_bool , punct = \l__acro_page_punct_bool , punct-symbol = \l__acro_page_punct_tl , brackets = \l__acro_page_brackets_bool , brackets-type = \l__acro_page_brackets_tl , space = \l__acro_page_space_dim } { \AssignTemplateKeys \bool_if:NT \l__acro_page_display_bool { \bool_if:NT \l__acro_page_punct_bool { \tl_use:N \l__acro_page_punct_tl } \tl_use:N \c_space_tl \bool_if:NT \l__acro_page_brackets_bool { \tl_head:N \l__acro_page_brackets_tl } \acro_print_page_numbers:n { #1 } \bool_if:NT \l__acro_page_brackets_bool { \tl_tail:N \l__acro_page_brackets_tl } } } % the different styles: \DeclareInstance { acro-page-number } { default } { default } { punct = true , punct-symbol = . } \DeclareInstance { acro-page-number } { plain } { default } { punct = false } \DeclareInstance { acro-page-number } { comma } { default } { punct = true } \DeclareInstance { acro-page-number } { paren } { default } { brackets=true , punct-symbol = ~ } \DeclareInstance { acro-page-number } { none } { default } { display = false } % -------------------------------------------------------------------------- % the title of the list: \cs_new:Npn \acro_list_title_format:n #1 { #1 } \DeclareObjectType { acro-title } { 1 } \DeclareTemplateInterface { acro-title } { sectioning } { 1 } { name-format : function 1 = #1 } \DeclareTemplateCode { acro-title } { sectioning } { 1 } { name-format = \acro_list_title_format:n } { \AssignTemplateKeys \acro_list_title_format:n { #1 } } % the different styles: \DeclareInstance { acro-title } { chapter* } { sectioning } { name-format = \chapter* { #1 } } \DeclareInstance { acro-title } { part* } { sectioning } { name-format = \part* { #1 } } \DeclareInstance { acro-title } { section* } { sectioning } { name-format = \section* { #1 } } \DeclareInstance { acro-title } { subsection* } { sectioning } { name-format = \subsection* { #1 } } \DeclareInstance { acro-title } { chapter } { sectioning } { name-format = \chapter { #1 } } \DeclareInstance { acro-title } { part } { sectioning } { name-format = \part { #1 } } \DeclareInstance { acro-title } { section } { sectioning } { name-format = \section { #1 } } \DeclareInstance { acro-title } { subsection } { sectioning } { name-format = \subsection { #1 } } \DeclareInstance { acro-title } { addchap } { sectioning } { name-format = \addchap { #1 } } \DeclareInstance { acro-title } { addsec } { sectioning } { name-format = \addsec { #1 } } % -------------------------------------------------------------------------- % outputting the whole list \DeclareObjectType { acro-list } { 3 } % excluded items: \bool_new:N \l__acro_is_excluded_bool \cs_generate_variant:Nn \tl_if_eq:nnT { nV } % #1: id % #2: excluded classes % #3: continue if not excluded \cs_new:Npn \acro_is_excluded:nnF #1#2#3 { \bool_set_false:N \l__acro_is_excluded_bool \tl_if_empty:nTF { #2 } { #3 } { \clist_map_inline:nn { #2 } { \prop_get:NnNF \l__acro_class_prop { #1 } \l__acro_tmpa_tl {} \tl_if_eq:nVT { ##1 } \l__acro_tmpa_tl { \bool_set_true:N \l__acro_is_excluded_bool } } \bool_if:NF \l__acro_is_excluded_bool { #3 } } } % build the list, dummy functions to be redefined in the template code: \cs_new:Npn \acro_print_list_short:nn #1#2 { } \cs_new:Npn \acro_print_list_long:n #1 { } \cs_new:Npn \acro_print_list_extra:n #1 { } \cs_new:Npn \acro_print_list_page:n #1 { } % Test, if acronyms should be printed or not; needs testing for in/excluded % classes and options `only-used' and `single': \cs_new:Npn \acro_list_allow_items:nn #1#2 { \prop_map_inline:Nn \l__acro_short_prop { \acro_get:n { ##1 } \bool_if:nT { ( \l__acro_use_single_bool && \cs_if_exist_p:c { acro@##1@twice } ) || ( !\l__acro_use_single_bool && \cs_if_exist_p:c { acro@##1@once } && \l__acro_print_only_used_bool ) || ( !\l__acro_use_single_bool && !\l__acro_print_only_used_bool ) } { \acro_is_excluded:nnF { ##1 } { #2 } { \tl_if_blank:nTF { #1 } { \acro_print_list_short:nn { ##1 } { ##2 } \bool_if:NT \l__acro_capitalize_list_bool { \bool_set_true:N \l__acro_first_upper_bool } \acro_print_list_long:n { ##1 } \bool_set_false:N \l__acro_first_upper_bool \acro_print_list_extra:n { ##1 } \acro_print_list_page:n { ##1 } } { \clist_map_inline:nn { #1 } { \prop_get:NnNT \l__acro_class_prop { ##1 } \l__acro_tmpa_tl { \tl_set:Nn \l__acro_tmpb_tl { ####1 } \tl_trim_spaces:N \l__acro_tmpa_tl \tl_trim_spaces:N \l__acro_tmpb_tl \tl_if_eq:NNT \l__acro_tmpa_tl \l__acro_tmpb_tl { \acro_print_list_short:nn { ##1 } { ##2 } \bool_if:NT \l__acro_capitalize_list_bool { \bool_set_true:N \l__acro_first_upper_bool } \acro_print_list_long:n { ##1 } \bool_set_false:N \l__acro_first_upper_bool \acro_print_list_extra:n { ##1 } \acro_print_list_page:n { ##1 } } } } } } } } } % list template: \DeclareTemplateInterface { acro-list } { list } { 3 } { } \DeclareTemplateCode { acro-list } { list } { 3 } { } { \AssignTemplateKeys \__acro_activate_hyperref_support: \cs_set:Npn \acro_print_list_short:nn ##1##2 { \item [ \acro_hyper_target:nn { ##1 } { \__acro_acc_supp:nn { ##1 } { \__acro_write_short:n { \l__acro_list_short_format_tl { ##2 } } } } ] } \cs_set:Npn \acro_print_list_long:n ##1 { \__acro_write_long:Nf \l__acro_list_long_format_tl { \prop_get:Nn \l__acro_long_prop { ##1 } } \__acro_cite_if:Nn \l__acro_citation_all_bool { ##1 } } \cs_set:Npn \acro_print_list_extra:n ##1 { \prop_get:NnNT \l__acro_extra_prop { ##1 } \l__acro_tmpa_tl { \UseInstance { acro-extra } { \l__acro_extra_instance_tl } { \l__acro_tmpa_tl } } } \cs_set:Npn \acro_print_list_page:n ##1 { \bool_if:nT { \cs_if_exist_p:c { acro@##1@once } } { \UseInstance { acro-page-number } { \l__acro_page_instance_tl } { ##1 } } } \begin { #1 } \acro_list_allow_items:nn { #2 } { #3 } \end { #1 } } % table template: \tl_new:N \l__acro_list_table_tl \tl_new:N \l__acro_list_table_spec_tl \DeclareTemplateInterface { acro-list } { table } { 3 } { table : tokenlist = longtable , table-spec : tokenlist = lp{\l__acro_table_width_dim} } \DeclareTemplateCode { acro-list } { table } { 3 } { table = \l__acro_list_table_tl , table-spec = \l__acro_list_table_spec_tl } { \AssignTemplateKeys \__acro_activate_hyperref_support: \cs_set:Npn \acro_print_list_short:nn ##1##2 { \acro_hyper_target:nn { ##1 } { \__acro_acc_supp:nn { ##1 } { \__acro_write_short:n { \l__acro_list_short_format_tl { ##2 } } } } & } \cs_set:Npn \acro_print_list_long:n ##1 { \__acro_write_long:Nf \l__acro_list_long_format_tl { \prop_get:Nn \l__acro_long_prop { ##1 } } \__acro_cite_if:Nn \l__acro_citation_all_bool { ##1 } } \cs_set:Npn \acro_print_list_extra:n ##1 { \prop_get:NnNT \l__acro_extra_prop { ##1 } \l__acro_tmpa_tl { \UseInstance { acro-extra } { \l__acro_extra_instance_tl } { \l__acro_tmpa_tl } } } \cs_set:Npn \acro_print_list_page:n ##1 { \bool_if:nT { \cs_if_exist_p:c { acro@##1@once } } { \UseInstance { acro-page-number } { \l__acro_page_instance_tl } { ##1 } } \tabularnewline } \exp_args:Noo \begin { \l__acro_list_table_tl } { \l__acro_list_table_spec_tl } \acro_list_allow_items:nn { #2 } { #3 } \exp_args:No \end { \l__acro_list_table_tl } } % extra-table template: \DeclareTemplateInterface { acro-list } { extra-table } { 3 } { table : tokenlist = longtable , table-spec : tokenlist = lp{\l__acro_table_width_dim}ll } \DeclareTemplateCode { acro-list } { extra-table } { 3 } { table = \l__acro_list_table_tl , table-spec = \l__acro_list_table_spec_tl } { \AssignTemplateKeys \__acro_activate_hyperref_support: \cs_set:Npn \acro_print_list_short:nn ##1##2 { \acro_hyper_target:nn { ##1 } { \__acro_acc_supp:nn { ##1 } { \__acro_write_short:n { \l__acro_list_short_format_tl { ##2 } } } } & } \cs_set:Npn \acro_print_list_long:n ##1 { \__acro_write_long:Nf \l__acro_list_long_format_tl { \prop_get:Nn \l__acro_long_prop { ##1 } } \__acro_cite_if:Nn \l__acro_citation_all_bool { ##1 } & } \cs_set:Npn \acro_print_list_extra:n ##1 { \prop_get:NnNT \l__acro_extra_prop { ##1 } \l__acro_tmpa_tl { \UseInstance { acro-extra } { \l__acro_extra_instance_tl } { \l__acro_tmpa_tl } } & } \cs_set:Npn \acro_print_list_page:n ##1 { \bool_if:nT { \cs_if_exist_p:c { acro@##1@once } } { \UseInstance { acro-page-number } { \l__acro_page_instance_tl } { ##1 } } \tabularnewline } \exp_args:Noo \begin { \l__acro_list_table_tl } { \l__acro_list_table_spec_tl } \acro_list_allow_items:nn { #2 } { #3 } \exp_args:No \end { \l__acro_list_table_tl } } % extra-table-rev template: \DeclareTemplateInterface { acro-list } { extra-table-rev } { 3 } { table : tokenlist = longtable , table-spec : tokenlist = llp{\l__acro_table_width_dim}l } \DeclareTemplateCode { acro-list } { extra-table-rev } { 3 } { table = \l__acro_list_table_tl , table-spec = \l__acro_list_table_spec_tl } { \AssignTemplateKeys \__acro_activate_hyperref_support: \cs_set:Npn \acro_print_list_short:nn ##1##2 { \acro_hyper_target:nn { ##1 } { \__acro_acc_supp:nn { ##1 } { \__acro_write_short:n { ##2 } } } & } \cs_set:Npn \acro_print_list_extra:n ##1 { \bool_if:NT \l__acro_capitalize_list_bool { \bool_set_true:N \l__acro_first_upper_bool } \__acro_write_long:Nf \l__acro_long_format_tl { \prop_get:Nn \l__acro_long_prop { ##1 } } \__acro_cite_if:Nn \l__acro_citation_all_bool { ##1 } & } \cs_set:Npn \acro_print_list_long:n ##1 { \prop_get:NnNT \l__acro_extra_prop { ##1 } \l__acro_tmpa_tl { \UseInstance { acro-extra } { \l__acro_extra_instance_tl } { \l__acro_tmpa_tl } } & } \cs_set:Npn \acro_print_list_page:n ##1 { \bool_if:nT { \cs_if_exist_p:c { acro@##1@once } } { \UseInstance { acro-page-number } { \l__acro_page_instance_tl } { ##1 } } \tabularnewline } \exp_args:Noo \begin { \l__acro_list_table_tl } { \l__acro_list_table_spec_tl } \acro_list_allow_items:nn { #2 } { #3 } \exp_args:No \end { \l__acro_list_table_tl } } % the different styles: \DeclareInstance { acro-list } { list } { list } { } \DeclareInstance { acro-list } { tabular } { table } { table = tabular } \DeclareInstance { acro-list } { longtable } { table } { table = longtable } \DeclareInstance { acro-list } { extra-longtable } { extra-table } { table = longtable } \DeclareInstance { acro-list } { extra-tabular } { extra-table } { table = tabular } \DeclareInstance { acro-list } { extra-longtable-rev } { extra-table-rev } { table = longtable } \DeclareInstance { acro-list } { extra-tabular-rev } { extra-table-rev } { table = tabular } % -------------------------------------------------------------------------- % automatic typesetting, the internals of \ac: % #1: id \cs_new:Npn \acro_use:n #1 { % get the acronym and the plural settings: \acro_get:n { #1 } \acro_is_used:nTF { #1 } { % this is not the first time \__acro_indefinite:nn { #1 } { short } \__acro_acc_supp:nn { #1 } { \__acro_write_short:V \l__acro_short_tl } \acro_after:n { #1 } } { % this is the first time \bool_gset_true:c { g__acro_#1_first_use_bool } \__acro_is_single:nTF { #1 } { \__acro_indefinite:nn { #1 } { long } \__acro_write_long:NV \l__acro_long_format_tl \l__acro_long_tl } { \UseInstance { acro-first } { \l__acro_first_instance_tl } { #1 } { \l__acro_short_tl } { \l__acro_long_tl } } } } \cs_new:Npn \__acro_is_single:nTF #1#2#3 { \bool_if:nTF { !\l__acro_use_single_bool || \cs_if_exist_p:c { acro@#1@twice } } { #3 } { #2 } } \cs_new:Npn \__acro_is_single:nT #1#2 { \bool_if:nF { !\l__acro_use_single_bool || \cs_if_exist_p:c { acro@#1@twice } } { #2 } } % -------------------------------------------------------------------------- % some helpers we'll need more often: \cs_new:Npn \acro_defined:n #1 { \prop_if_in:NnF \l__acro_short_prop { #1 } { \msg_error:nnx { acro } { undefined } { #1 } } } \cs_new:Npn \acro_get:n #1 { \acro_defined:n { #1 } \__acro_activate_hyperref_support: \prop_get:NnNF \l__acro_short_prop { #1 } \l__acro_tmpa_tl {} \__acro_make_link:nNN { #1 } \l__acro_short_tl \l__acro_tmpa_tl \prop_get:NnNF \l__acro_short_plural_prop { #1 } \l__acro_short_plural_tl {} \prop_get:NnNF \l__acro_long_prop { #1 } \l__acro_long_tl {} \prop_get:NnNTF \l__acro_long_format_prop { #1 } \l__acro_custom_long_format_tl { \bool_set_true:N \l__acro_custom_long_format_bool } { \bool_set_false:N \l__acro_custom_long_format_bool } \prop_get:NnNF \l__acro_first_long_format_prop { #1 } \l__acro_first_long_format_tl {}% to avoid hanging compilation if first-long-format hasn't been set \prop_get:NnNT \l__acro_long_pre_prop { #1 } \l__acro_long_pre_tl { \tl_put_left:NV \l__acro_long_tl \l__acro_long_pre_tl } \prop_get:NnNF \l__acro_alt_prop { #1 } \l__acro_tmpb_tl {} \__acro_make_link:nNN { #1 } \l__acro_alt_tl \l__acro_tmpb_tl \prop_get:NnNTF \l__acro_format_prop { #1 } \l__acro_custom_format_tl { \bool_set_true:N \l__acro_custom_format_bool } { \bool_set_false:N \l__acro_custom_format_bool } \__acro_set_plural:n { #1 } \prop_get:NnNT \l__acro_long_post_prop { #1 } \l__acro_long_post_tl { \tl_put_right:NV \l__acro_long_tl \l__acro_long_post_tl } } \cs_generate_variant:Nn \tl_put_right:Nn { NV } \cs_new:Npn \__acro_set_plural:n #1 { \bool_if:NT \l__acro_use_plural_bool { \bool_if:nTF { \prop_get:Nn \l__acro_replace_plural_prop { #1 } } { \prop_get:NnNF \l__acro_long_plural_prop { #1 } \l__acro_long_tl {} } { \tl_put_right:Nn \l__acro_long_tl { \prop_get:Nn \l__acro_long_plural_prop { #1 } } } } } % -------------------------------------------------------------------------- % enable us to know if the acronym is used only once and provide a different % style for that: \cs_new:Npn \acro_is_used:nTF #1#2#3 { \bool_if:nTF { \bool_if_p:c { g__acro_#1_used_bool } && ( ( \bool_if_p:c { g__acro_#1_first_use_bool } && \l__acro_mark_first_as_used_bool ) || ! \l__acro_mark_first_as_used_bool ) } { \iow_now:Nx \@auxout { \string \acro@used@twice { #1 } } #2 } { \iow_now:Nx \@auxout { \string \acro@used@once { #1 } } \bool_if:NT \l__acro_mark_as_used_bool { \bool_if:nT { !\bool_if_p:c { g__acro_#1_label_bool } && \tl_if_eq_p:NN \l__acro_active_version_tl \l__acro_version_zero_tl } { \bool_gset_true:c { g__acro_#1_label_bool } \label{ac:#1} } \bool_gset_true:c { g__acro_#1_used_bool } } #3 } } \cs_new:Npn \acro_is_used:n #1 { \acro_is_used:nTF { #1 } { } { } } \cs_new:Npn \acro@used@once #1 { \expandafter\xdef\csname acro@#1@once \endcsname { #1 } } \cs_new:Npn \acro@used@twice #1 { \expandafter\xdef\csname acro@#1@twice \endcsname { #1 } } \AtEndDocument { \cs_set:Npn \acro@used@twice #1 { \def\reserved@a{#1}% \expandafter\ifx\csname acro@#1@twice \endcsname\reserved@a\else \@tempswatrue\fi } } % -------------------------------------------------------------------------- \cs_new:Npn \acro_after:n #1 { \__acro_cite_if:Nn \l__acro_citation_all_bool { #1 } \__acro_index_if:Nn \l__acro_addto_index_bool { #1 } } % the standard internals: \cs_new:Npn \acro_short:n #1 { \acro_get:n { #1 } \acro_is_used:n { #1 } \__acro_indefinite:nn { #1 } { short } \__acro_is_single:nT { #1 } { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn } \__acro_acc_supp:nn { #1 } { \__acro_write_short:V \l__acro_short_tl } \acro_after:n { #1 } } % get alternative entry: \cs_new:Npn \acro_alt:n #1 { \acro_get:n { #1 } \acro_is_used:n { #1 } \__acro_indefinite:nn { #1 } { alt } \__acro_is_single:nT { #1 } { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn } \__acro_acc_supp:nn { #1 } { \__acro_write_short:V \l__acro_alt_tl } \acro_after:n { #1 } } % get long entry: \cs_new:Npn \acro_long:n #1 { \acro_get:n { #1 } \acro_is_used:n { #1 } \__acro_indefinite:nn { #1 } { long } \__acro_is_single:nT { #1 } { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn } \__acro_write_long:NV \l__acro_long_format_tl \l__acro_long_tl \acro_after:n { #1 } } % output like the first time: \cs_new:Npn \acro_first:n #1 { \bool_gset_true:c { g__acro_#1_first_use_bool } \acro_get:n { #1 } \acro_is_used:n { #1 } \__acro_is_single:nT { #1 } { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn } \UseInstance { acro-first } { \l__acro_first_instance_tl } { #1 } { \l__acro_short_tl } { \l__acro_long_tl } } % output like the first time with own long version: \cs_new:Npn \acro_first_like:nn #1#2 { \bool_gset_true:c { g__acro_#1_first_use_bool } \acro_get:n { #1 } \acro_is_used:n { #1 } \__acro_is_single:nT { #1 } { \cs_set_eq:NN \acro_hyper_link:nn \use_ii:nn } \UseInstance { acro-first } { \l__acro_first_instance_tl } { #1 } { \l__acro_short_tl } { #2 } } % ---------------------------------------------------------------------------- % citations: % #1 pre % #2 post % #3 key \cs_new:Npn \__acro_cite:nnn #1#2#3 { \quark_if_no_value:nTF { #1 } { \__acro_citation_cmd:w { #3 } } { \quark_if_no_value:nTF { #2 } { \__acro_citation_cmd:w [ #1 ] { #3 } } { \__acro_citation_cmd:w [ #1 ] [ #2 ] { #3 } } } } \cs_generate_variant:Nn \__acro_cite:nnn { VVV } \cs_new:Npn \__acro_cite_if:Nn #1#2 { \bool_if:NT #1 { \prop_get:NnNT \l__acro_citation_prop { #2 } \l__acro_tmpa_tl { \prop_get:NnN \l__acro_citation_pre_prop { #2 } \l__acro_tmpb_tl \prop_get:NnN \l__acro_citation_post_prop { #2 } \l__acro_tmpc_tl \__acro_no_break: \tl_use:N \l__acro_citation_space_tl \__acro_cite:VVV \l__acro_tmpb_tl \l__acro_tmpc_tl \l__acro_tmpa_tl } } } % ---------------------------------------------------------------------------- % indexing: \cs_new:Npn \__acro_index_if:Nn #1#2 { \bool_if:nT { #1 && \l__acro_mark_as_used_bool } { \prop_get:NnN \l__acro_index_cmd_prop { #2 } \l__acro_tmpa_tl \prop_get:NnN \l__acro_index_sort_prop { #2 } \l__acro_tmpb_tl \prop_get:NnN \l__acro_index_prop { #2 } \l__acro_tmpc_tl \__acro_index:VnVV \l__acro_tmpa_tl { #2 } \l__acro_tmpb_tl \l__acro_tmpc_tl } } % #1: cmd % #2: key % #3: sort % #4: replace \cs_new:Npn \__acro_index:nnnn #1#2#3#4 { \prop_get:NnNF \l__acro_short_prop { #2 } \l__acro_tmpa_tl {} \prop_get:NnNF \l__acro_format_prop { #2 } \l__acro_tmpb_tl {} \quark_if_no_value:VTF \l__acro_tmpb_tl { \tl_set:Nn \l__acro_tmpc_tl { \l__acro_short_format_tl \l__acro_tmpa_tl } } { \tl_set:Nn \l__acro_tmpc_tl { \l__acro_tmpb_tl \l__acro_tmpa_tl } } \quark_if_no_value:nF { #1 } { \cs_set:Npn \__acro_index_cmd:n { #1 } } \quark_if_no_value:nTF { #4 } { \quark_if_no_value:nTF { #3 } { \__acro_index_cmd:n { #2 @ { \l__acro_tmpc_tl } } } { \__acro_index_cmd:n { #3 @ { \l__acro_tmpc_tl } } } } { \__acro_index_cmd:n { #4 } } } \cs_generate_variant:Nn \__acro_index:nnnn { VnVV } \cs_generate_variant:Nn \quark_if_no_value:nTF { V } % ---------------------------------------------------------------------------- % accessability support \tl_new:N \l__acro_acc_supp_tl \cs_new_eq:NN \__acro_acc_supp:nn \use_ii:nn \cs_new:Npn \__acro_acc_supp_aux:nn #1#2 { \BeginAccSupp { ActualText = #1 } #2 \EndAccSupp { } } \cs_generate_variant:Nn \__acro_acc_supp_aux:nn { V } \AtBeginDocument { \bool_if:NT \l__acro_acc_supp_bool { \RequirePackage { accsupp } \cs_set:Npn \__acro_acc_supp:nn #1#2 { \prop_get:NnNF \l__acro_acc_supp_prop { #1 } \l__acro_acc_supp_tl { \prop_get:NnNF \l__acro_short_prop { #1 } \l__acro_acc_supp_tl {} } \bool_if:NT \l__acro_use_plural_bool { \tl_put_right:NV \l__acro_acc_supp_tl \l__acro_short_plural_tl } \__acro_acc_supp_aux:Vn \l__acro_acc_supp_tl { #2 } } } } % -------------------------------------------------------------------------- % indefinite articles: \cs_new_protected:Npn \__acro_indefinite:nn #1#2 { \bool_if:NT \l__acro_indefinite_bool { \prop_get:cn { l__acro_#2_indefinite_prop } { #1 } ~ } \bool_if:NT \l__acro_upper_indefinite_bool { \__acro_first_upper_case:x { \prop_get:cn { l__acro_#2_indefinite_prop } { #1 } } ~ } } % -------------------------------------------------------------------------- % experimental sorting feature: \AtBeginDocument { \bool_if:NT \l__acro_sort_bool { \RequirePackage { l3sort } \cs_new:Npn \acro_sort_prop:N #1 { \seq_clear:N \l__acro_tmpa_seq \prop_clear:N \l__acro_tmpa_prop \prop_clear:N \l__acro_tmpb_prop \prop_map_inline:Nn \l__acro_sort_prop { \seq_put_right:Nn \l__acro_tmpa_seq { ##2 } \prop_put:Nnn \l__acro_tmpa_prop { ##2 } { ##1 } } \seq_sort:Nn \l__acro_tmpa_seq { \tl_to_lowercase:n { \int_compare:nTF { \pdfstrcmp { ##1 } { ##2 } = -1 } { \sort_ordered: } { \sort_reversed: } } } \seq_map_inline:Nn \l__acro_tmpa_seq { % get ID: \prop_get:NnNF \l__acro_tmpa_prop { ##1 } \l__acro_tmpa_tl {} % get prop entry of ID in #1: \prop_get:NVNT #1 \l__acro_tmpa_tl \l__acro_tmpb_tl { \prop_put:NVV \l__acro_tmpb_prop \l__acro_tmpa_tl \l__acro_tmpb_tl } } \prop_set_eq:NN #1 \l__acro_tmpb_prop } } } % -------------------------------------------------------------------------- % regarding list printing: \cs_new:Npn \acro@print@list { \cs_if_exist:NF \acro@printed@list { \cs_new:Npn \acro@printed@list {} } } \cs_new:Npn \acro_use_if:nn #1#2 { \IfBooleanTF { #1 } { \bool_set_false:N \l__acro_mark_as_used_bool } { \acro_record_page_number:n { #2 } \bool_set_true:N \l__acro_mark_as_used_bool } } % -------------------------------------------------------------------------- % the user commands: % automatic: \NewDocumentCommand \ac { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_use:n { #2 } \group_end: } \NewDocumentCommand \iac { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_use:n { #2 } \group_end: } \NewDocumentCommand \Iac { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_use:n { #2 } \group_end: } \NewDocumentCommand \Ac { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_first_upper_bool \acro_use:n { #2 } \group_end: } \NewDocumentCommand \acp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_use:n { #2 } \group_end: } \NewDocumentCommand \Acp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \bool_set_true:N \l__acro_first_upper_bool \acro_use:n { #2 } \group_end: } % short: \NewDocumentCommand \acs { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_short:n { #2 } \group_end: } \NewDocumentCommand \iacs { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_short:n { #2 } \group_end: } \NewDocumentCommand \Iacs { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_short:n { #2 } \group_end: } \NewDocumentCommand \acsp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_short:n { #2 } \group_end: } % alt: \NewDocumentCommand \aca { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_alt:n { #2 } \group_end: } \NewDocumentCommand \iaca { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_alt:n { #2 } \group_end: } \NewDocumentCommand \Iaca { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_alt:n { #2 } \group_end: } \NewDocumentCommand \acap { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_alt:n { #2 } \group_end: } % long: \NewDocumentCommand \acl { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_long:n { #2 } \group_end: } \NewDocumentCommand \iacl { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_long:n { #2 } \group_end: } \NewDocumentCommand \Iacl { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_long:n { #2 } \group_end: } \NewDocumentCommand \Acl { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_first_upper_bool \acro_long:n { #2 } \group_end: } \NewDocumentCommand \aclp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_long:n { #2 } \group_end: } \NewDocumentCommand \Aclp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \bool_set_true:N \l__acro_first_upper_bool \acro_long:n { #2 } \group_end: } % first: \NewDocumentCommand \acf { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_first:n { #2 } \group_end: } \NewDocumentCommand \iacf { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_first:n { #2 } \group_end: } \NewDocumentCommand \Iacf { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_first:n { #2 } \group_end: } \NewDocumentCommand \Acf { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_first_upper_bool \acro_first:n { #2 } \group_end: } \NewDocumentCommand \acfp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_first:n { #2 } \group_end: } \NewDocumentCommand \Acfp { sm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \bool_set_true:N \l__acro_first_upper_bool \acro_first:n { #2 } \group_end: } % first-like: \NewDocumentCommand \acflike { smm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \acro_first_like:nn { #2 } { #3 } \group_end: } \NewDocumentCommand \iacflike { smm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_indefinite_bool \acro_first_like:nn { #2 } { #3 } \group_end: } \NewDocumentCommand \Iacflike { smm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_upper_indefinite_bool \acro_first_like:nn { #2 } { #3 } \group_end: } \NewDocumentCommand \acfplike { smm } { \group_begin: \acro_defined:n { #2 } \acro_use_if:nn { #1 } { #2 } \bool_set_true:N \l__acro_use_plural_bool \acro_first_like:nn { #2 } { #3 } \group_end: } % reset outputs, they'll behave like the first time again (!not like the _only_ % time!): \cs_new:Npn \acro_reset:n #1 { \bool_gset_false:c { g__acro_#1_used_bool } \bool_gset_false:c { g__acro_#1_first_use_bool } } \cs_new:Npn \acro_mark_as_used:n #1 { \bool_gset_true:c { g__acro_#1_used_bool } \bool_gset_true:c { g__acro_#1_first_use_bool } \acro@used@once { #1 } } \cs_new:Npn \acro_reset_all: { \prop_map_inline:Nn \l__acro_short_prop { \acro_reset:n { ##1 } } } \cs_new:Npn \acro_mark_all_as_used: { \prop_map_inline:Nn \l__acro_short_prop { \acro_mark_as_used:n { ##1 } } } \NewDocumentCommand \acresetall {} { \acro_reset_all: } \NewDocumentCommand \acuseall {} { \acro_mark_all_as_used: } \NewDocumentCommand \acreset { > { \SplitList { , } } m } { \ProcessList { #1 } { \acro_reset:n } \ignorespaces } \NewDocumentCommand \acuse { > { \SplitList { , } } m } { \ProcessList { #1 } { \acro_mark_as_used:n } \ignorespaces } % --------------------------------------------------------------------------- % process options: \ProcessKeysOptions { acro } % --------------------------------------------------------------------------- % PDF bookmark support \cs_new:Npn \acpdfstring { \acro_pdf_string:n } \cs_new:Npn \acpdfstringplural { \acro_pdf_string_plural:n } \cs_new:Npn \acro_tl_if_eq:nnTF #1#2 { \ifx#1#2\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi } \cs_new:Npn \acro_pdf_string:n #1 { \acro_tl_if_eq:nnTF {*} {#1} { \prop_get:Nn \l__acro_pdfstring_prop } { \prop_get:Nn \l__acro_pdfstring_prop { #1 } } } \cs_new:Npn \acro_pdf_string_plural:n #1 { \acro_tl_if_eq:nnTF {*} {#1} { \prop_get:Nn \l__acro_pdfstring_plural_prop } { \prop_get:Nn \l__acro_pdfstring_plural_prop { #1 } } } \AtBeginDocument { \@ifpackageloaded { hyperref } { \bool_set_true:N \l__acro_hyperref_loaded_bool \pdfstringdefDisableCommands { \cs_set_eq:NN \ac \acpdfstring \cs_set_eq:NN \Ac \acpdfstring \cs_set_eq:NN \acs \acpdfstring \cs_set_eq:NN \acl \acpdfstring \cs_set_eq:NN \Acl \acpdfstring \cs_set_eq:NN \acf \acpdfstring \cs_set_eq:NN \Acf \acpdfstring \cs_set_eq:NN \aca \acpdfstring \cs_set_eq:NN \acp \acpdfstringplural \cs_set_eq:NN \Acp \acpdfstringplural \cs_set_eq:NN \acsp \acpdfstringplural \cs_set_eq:NN \aclp \acpdfstringplural \cs_set_eq:NN \Aclp \acpdfstringplural \cs_set_eq:NN \acfp \acpdfstringplural \cs_set_eq:NN \Acfp \acpdfstringplural \cs_set_eq:NN \acap \acpdfstringplural } \cs_set_eq:NN \acro_hyper_page:n \hyperpage } {} } % -------------------------------------------------------------------------- % language support \RequirePackage { translations } % Listenname \DeclareTranslationFallback { acronym-list-name } { Acronyms } \DeclareTranslation { English } { acronym-list-name } { Acronyms } \DeclareTranslation { American } { acronym-list-name } { Acronyms } \DeclareTranslation { British } { acronym-list-name } { Acronyms } \DeclareTranslation { French } { acronym-list-name } { Acronymes } \DeclareTranslation { German } { acronym-list-name } { Abk\"urzungen } \DeclareTranslation { Italian } { acronym-list-name } { Acronimi } \DeclareTranslation { Portuguese } { acronym-list-name } { Acr\'onimos } \DeclareTranslation { Spanish } { acronym-list-name } { Siglas } \DeclareTranslation { Catalan } { acronym-list-name } { Sigles } \DeclareTranslation { Turkish } { acronym-list-name } { K\i saltmalar } \tl_set:Nn \l__acro_list_name_tl { \GetTranslation { acronym-list-name } } % Seitenname \DeclareTranslationFallback { acronym-page-name } { p. } \DeclareTranslation { English } { acronym-page-name } { p. } \DeclareTranslation { German } { acronym-page-name } { S. } \DeclareTranslation { Portuguese } { acronym-page-name } { p. } \tl_set:Nn \l__acro_page_name_tl { \GetTranslation { acronym-page-name }\@\, } % Seitenname - Plural \DeclareTranslationFallback { acronym-pages-name } { pp. } \DeclareTranslation { English } { acronym-pages-name } { pp. } \DeclareTranslation { German } { acronym-pages-name } { S. } \DeclareTranslation { Portuguese } { acronym-pages-name } { pp. } \tl_set:Nn \l__acro_pages_name_tl { \GetTranslation { acronym-pages-name }\@\, } % einzelne folgende Seite \DeclareTranslationFallback { acronym-next-page } { f. } \DeclareTranslation { English } { acronym-next-page } { f. } \DeclareTranslation { German } { acronym-next-page } { f. } \DeclareTranslation { Portuguese } { acronym-next-page } { s. } \tl_set:Nn \l__acro_next_page_tl { \,\GetTranslation {acronym-next-page }\@ } % mehrere folgende Seiten \DeclareTranslationFallback { acronym-next-pages } { ff. } \DeclareTranslation { English } { acronym-next-pages } { ff. } \DeclareTranslation { German } { acronym-next-pages } { ff. } \DeclareTranslation { Portuguese } { acronym-next-pages } { ss. } \tl_set:Nn \l__acro_next_pages_tl { \,\GetTranslation {acronym-next-pages }\@ } % -------------------------------------------------------------------------- % load default version \bool_if:NF \l__acro_version_selected_bool { \__acro_select_version:n { 1 } } \tex_endinput:D % -------------------------------------------------------------------------- % HISTORY: 2012/06/22 v0.1 - first public release 2012/06/23 v0.1a - bug fix, added `strict' and `macros' option and creation of shortcut macros - added capitalized version of long forms - added `sort' option 2012/06/24 v0.1b - added \Acf and \Acfp, added option `plural-ending' 2012/06/24 v0.1c - added excluded argument to \printacronyms 2012/06/24 v0.2 - renamed \NewAcronym => \DeclareAcronym \AcronymFormat => \DeclareAcronymFormat 2012/06/25 v0.2a - new first-style's: `short' and `reversed' 2012/06/25 v0.3 - new list formats: extra-tabular, extra-longtable, extra-tabular-rev, extra-longtable-rev - extra precaution when using \printacronyms to avoid errors. 2012/06/27 v0.3a - new option `list-caps', \Acp added 2012/06/29 v0.3b - extended the `text' template to the `acro-first' object - added `acro-first' instances `plain' and `plain-reversed' 2012/07/16 v0.3c - small adjustments to the documentation 2012/07/23 v0.3d - first CTAN version 2012/07/24 v0.3e - adapted to updated l3kernel 2012/09/28 v0.4 - added means to add citations to acronyms 2012/10/07 v0.4a - new options: "uc-cmd", "list-long-format" - preliminary language support, needs package `translations' 2012/11/30 v0.5 - added starred variants of the commands that won't mark an acronym as used - added \acreset{} - added preliminary support for pdf strings: in pdf strings always the singular lowercase short version is inserted (the equivalent of \acs) 2012/12/14 v0.6 - bug with not-colored links resolved - bug introduced with the last update (full expansion of the short entry) resolved - option `xspace' added 2013/01/02 v0.6a - \acuseall 2013/01/16 v1.0 - new syntax of \DeclareAcronym - new option `version' - new `accsupp' acronym property - new `sort' acronym property - new syntax of \printacronyms - new default: `sort=true' - new options `page-ranges', `next-page', `next-pages', `pages-name', `record-pages' - no automatic label placement for page number referencing any more 2013/01/26 v1.1 - bug fix in the plural detection - new keys `long-pre' and `long-post' - new keys `index', `index-sort' and `index-cmd' - new options `index' and `index-cmd' 2013/01/29 v1.1a - added `long-format' key - renamed `format' key into `short-format', kept `format' for compatibility reasons 2013/02/09 v1.2 - error message instead of hanging when an undefined acronym is used - added `first-long-format' key and `first-long-format' option - added \acflike and \acfplike - improvements and bug fixes to the page recording mechanism - new option `mark-as-used' - new keys: `short-indefinite', `alt-indefinite' and `long-indefinite' - new commands: \iac, \Iac, \iacs, \Iacs, \iaca, \Iaca, \iacl, \Iacl, \iacf, \Iacf, \iacflike and \Iacflike 2013/04/04 v1.2a - added Portuguese translations % -------------------------------------------------------------------------- % TODO: - Option `totoc'!? - revise list styles to allow _full_ customization by creating own instances! this probably needs a handfull of macros that give access to the entries without worrying about internals - record and list _all_ pagenumbers where an acronym occurs - add \ACF, \ACFP, \ACL and \ACLP that will print all words of the long form capitalized