In trying to create a custom acro list style with a longtable and repeating heading, I started working my way through some LaTeX3 code more than I have in the past. I am used to patching with etoolbox's \patchcmd, but was stumped when trying to change a Template created via some code in acro.sty.
Goal
I want to change/add variables to the \DeclareAcroListStyle procedure to allow lines of the tables to be added before and after the acronym content, but inside the longtable environment. This would allow, for example, a header row with \endhead to be inserted to support a multiple-page table.
Minimum Working Example
This MWE gives a table and an example of how I would want the code to operate.
\documentclass{article}
\usepackage{acro,longtable}
\DeclareAcronym{test}{short = ST, long = Some Test}
% Define a new format type
\DeclareAcroListStyle{newstyle}{table}{
table = longtable,
table-spec = ll,
before = This text is before the \texttt{\textbackslash begin\{...\}} element.,
after = \noindent This text is after the \texttt{\textbackslash end\{...\}} element.,
%%% Want to add these variables to put header into table:
% beforeinner = \hrule Acronym & Definition \\\endhead,
% afterinner = \hrule
}
\acsetup{list-style=newstyle}
\begin{document}
\noindent This is \ac{test}.
\printacronyms
\end{document}
Changes in the source code
I have solved my overall problem by copying and modifying the acro.sty in its entirety. Now, I am trying to get this done via a patch, so I don't have to copy the entire style file. The portion that I had to edit was lines 1795-1837 (6 lines added in code below, current version of acro package being v2.6e 2016/09/04).
% `table' template:
\DeclareTemplateInterface {acro-list} {table} {2}
{
table : tokenlist = tabular ,
table-spec : tokenlist = lp{.7\linewidth} ,
foreign-sep : tokenlist = {~} ,
reverse : boolean = false ,
before : tokenlist = ,
after : tokenlist = ,
beforeinner : tokenlist = , %%% ADDED
afterinner : tokenlist = %%% ADDED
}
\DeclareTemplateCode {acro-list} {table} {2}
{
table = \l__acro_list_table_tl ,
table-spec = \l__acro_list_table_spec_tl ,
foreign-sep = \l__acro_foreign_sep_tl ,
reverse = \l__acro_list_reverse_long_extra_bool ,
before = \l__acro_list_before_tl ,
after = \l__acro_list_after_tl ,
beforeinner = \l__acro_list_beforeinner_tl , %%% ADDED
afterinner = \l__acro_list_afterinner_tl %%% ADDED
}
{
\AssignTemplateKeys
\acro_activate_hyperref_support:
\bool_if:NTF \l__acro_list_reverse_long_extra_bool
{
\cs_set_protected:Npn \acro_print_list_entry:nnnn ##1##2##3##4
{ ##1 & ##3 ##2 ##4 \tabularnewline }
}
{
\cs_set_protected:Npn \acro_print_list_entry:nnnn ##1##2##3##4
{ ##1 & ##2 ##3 ##4 \tabularnewline }
}
\acro_build_list_entries:Nnn \l__acro_list_entries_tl {#1} {#2}
\use:x
{
\exp_not:V \l__acro_list_before_tl
\exp_not:N \begin { \exp_not:V \l__acro_list_table_tl }
{ \exp_not:V \l__acro_list_table_spec_tl }
\exp_not:V \l__acro_list_beforeinner_tl %%% ADDED
\exp_not:V \l__acro_list_entries_tl
\exp_not:V \l__acro_list_afterinner_tl %%% ADDED
\exp_not:N \end { \exp_not:V \l__acro_list_table_tl }
\exp_not:V \l__acro_list_after_tl
}
}
It seems like I could modify the template interface after creation with xtemplate's \EditInstance, but I haven't actually confirmed that yet.
I can't figure out if/how I would be able to modify the template code in any similar fashion.
I would entertain any easier methods of solving the original problem (adding running header to longtable style with acro) in comments, but the real question is patching the template code in LaTeX3.
\ExplSyntaxOnand\tl_new:Nyet...! – cslstr Jan 12 '17 at 03:06